Tuesday, July 5, 2022
HomeCloud ComputingLet's Make Some BCS Magic!

Let’s Make Some BCS Magic!


Howdy on the market in automation land! It has been some time since my final weblog, and new and thrilling issues proceed to occur. (Therefore the dearth of blogs.) I’m hopeful this kicks off the summer time on a scorching foot and we get loads on the market. To let you recognize about among the new work I’ve been taking up, I wished to convey you one thing from the land of Enterprise Crucial Companies (BCS). It is a new area I’ve entered so I wished to share with you some foundational items of automation goodness! So we’re going to take a stab at a couple of issues on this weblog…

  1. Constructing some superb Atomics for an API in SecureX Orchestration!
  2. Constructing workflows geared in the direction of our BCS Operational Insights API!
  3. Having the ability to map given code (on this case python) to SXO workflows
  4. Giving some greatest practices round workflow and atomic creation
  5. Sharing with the readers a ton of pre-built content material you should use to speed up your BCS automation work

Earlier than I get to our nice content material of the day, I’ve a couple of issues to share. The primary one is that Cisco Dwell is again and might be in particular person in fabulous Las Vegas! And sure readers, I might be there prepared to show you all about automation and orchestration. I might be educating a 4 hour lab that yow will discover at LTRATO-1000. Within the lab I might be educating alongside my superior good friend and co-automation professional, Mohammed Hamzeh. House is restricted and some spots are nonetheless there so enroll at present! Secondly, one other cool factor I’ve began to work on is a podcast that we now have began (once more, therefore much less blogs). This podcast is round bringing the most effective Cisco minds to you the listening viewers and our prospects. The podcast is named Cisco Tech Insiders and yow will discover it on SoundCloud (search for our emblem… its a microphone with Cisco Tech Insiders subsequent to it) or on Spotify. I extremely would recommend some listens and see if something we speak about excites you. As at all times, you may recommend issues by way of e-mail to me or feedback on the weblog.

Like I mentioned… let’s make some magic! So time to focus on what we’re going to do at present and that’s to construct some atomics off of some python code from DevNet and assist us begin to construct out an API set or “Atomic Adapter” for BCS Operational Insights API.

To start out with any API, we have to discover Authentication and Documentation on the API Spec. Fortunately, this can be a effectively performed API and we now have each! Authentication is completed by way of Shopper Secret+Shopper ID right into a JWT token…. we are able to discover the knowledge we’d like right here…

  1. Authentication
  2. OpenAPI Spec

Notice: Previous to doing among the API greatness you’ll need to undergo the On-boarding Course of and Utility Registration so you will get your Shopper ID and Shopper Secret to authenticate with the API. Registration will make use of the CX Cloud API Gateway! Extra thrilling know-how so that you can use. In case you have any points getting on boarded or within the utility registration course of please attain out to your BCS Account Venture Supervisor and/or related Consulting Engineers in your mission.

So let’s check out the Authentication half first and a few pattern Python code. We’re going to semi-map this code to SXO actions in a workflow. The python code doesn’t belong to me and I’m not the creator, so I’m linking it right here in your reference.

The steps we’d like for Authentication (assuming you have got your shopper id and shopper secret) are…

  1. Make API name to the token endpoint
  2. Extract and hold token from API return

In python to name the API we would do one thing like this (in python):

url = f'https://{server}/torii-auth/v1/token'

    knowledge = {
        "grantType": "client_credentials",
        "clientId": client_id,
        "secret": client_secret,
        "scope": "api.bcs.handle"

        resp = httpx.Shopper().publish(url=url, json=knowledge)
    besides (httpx.HTTPStatusError, httpx.RequestError) as err:
            f'Didn't JSON Internet Token(JWT): {err}'
        increase err
        return resp.json().get('accessToken')

To map this to SXO we have to…

Step Python SXO
1 url = f’https://{server}/torii-auth/v1/token’ Create a Goal configuration
2 resp = httpx.Shopper().publish(url=url, json=knowledge) Add a HTTP Request Exercise to a workflow
3 return resp.json().get(‘accessToken’) Use a JSON Path Question Exercise in workflow

So let’s stroll via constructing these items…

How To Construct a JWT Token Atomic

  1. Go to SXO and choose Targets on the left menu
  2. Click on NEW TARGET and choose HTTP Endpoint. Name it BCS Operational Insights Auth API
  3. Set NO ACCOUNT KEYS to true. Set PROTOCOL to HTTPS, HOST/IP to api-cx.cisco.com and PATH to /torii-auth/v1/. You’ll be able to see all of those values within the Python script as effectively. Click on SUBMIT.
  4. Click on the Workflows on the left menu after which click on NEW WORKFLOW
  5. On the far proper below VARIABLES, click on ADD VARIABLE and add a STRING referred to as I_client_id, make it required and make its SCOPE to be enter. Add a SECURE STRING referred to as I_client_secret, make it required and make its SCOPE to be enter.
  6. Then add one other variable SECURE STRING. Name it O_jwt_token and make its SCOPE to be output.
  7. Within the TARGET part, choose EXECUTE ON THIS TARGET and choose the goal kind of HTTP ENDPOINT after which choose the goal you created above.
  8. That is half the place we deal with step 2 and three above from the python to SXO conversion desk. On the toolbar seek for HTTP Request, then drag and drop one onto your workflow canvas.
  9. Click on on the exercise you simply dragged and dropped and it is possible for you to to configure it on the proper aspect of your window.
  10. On the exercise set the RELATIVE URL to token , the METHOD to publish, and the REQUEST BODY ought to mirror what’s within the instance. It ought to like this…
    {"grantType": "client_credentials", "clientId": "", "secret": "", "scope": "api.bcs.handle" }
  11. As you see I left the clientId and secret clean. It’s because we wish to cross variables into these fields, so you may copy the above into the REQUEST BODY area and hit the format button to make it look good!
  12. To cross within the variables we have to click on the puzzle piece icon in that area. That is the insert variable reference icon. When you click on that, navigate to Workflow->input->I_client_id for the shopper id area and Workflow->input->I_client_secret for the key. Set the content material kind to JSON.
  13. Subsequent we wish to parse the token out and put it aside to a safe string. Seek for the JSONPath Question exercise and drag and drop it under your HTTP Request exercise.
  14. Click on on the JSONPath exercise. Within the SOURCE JSON TO QUERY, click on the puzzle piece icon and choose Actions->Your HTTP Request ->Physique and save. Click on +ADD under that area after which within the JSONPATH QUERY area enter $..accessToken after which simply accessToken for the PROPERTY NAME. Set it to kind SECURE STRING.
  15. Lastly, search for the SET VARIABLE exercise and drag and drop it under the JSONPath question. Click on +ADD and within the VARIABLE TO UPDATE, click on the puzzle piece icon and choose Workflow->output->O_jwt_token. Within the NEW VALUE area, click on the puzzle piece icon and choose Activities->JSONPATH Question Exercise->accessToken.
  16. Your workflow is full! You need to be capable to validate it and click on run. Enter your shopper id and secret and it’ll generate a token for you!

Now I’d be a poor teacher if I didn’t embrace a closing outcome so that you can view alongside what we simply stepped via… so I’ve loads of that upcoming for you. As they are saying in cooking exhibits, “at all times have a pre-baked turkey to associate with the one you’re baking.” To assist everybody out I’ve constructed a complete atomic adapter so that you can use for BCS Operational Insights! (not only a JWT generator). Identical to you importing a bundle or copying and pasting pattern code you’ll have all of my workflows so that you can use and construct cool BCS automations. (or MAGIC!) You will discover them on the Shared CX SXO Repo and in time they are going to be revealed to the official SXO atomics git. To make this *even* higher you will see some pattern utilization workflows on the Shared CX SXO Repo that can assist you get began. These embrace the demo I’ll present within the weblog video (you didn’t suppose you wouldn’t get a video proper???) and an instance workflow that may refresh your JWT token within the background as an alternative of you having to re-call it every time you wish to use the API. These are nonetheless an opensource type nature workflows and atomics so when you’ve got points, please let me know!


So I do know I simply spoiled the enjoyable… however as at all times…

On to the Video!!!

Pondering Automation Demo of BCS Operational Insights API

Password: There isn’t a password!

Commonplace Finish-O-Weblog Disclaimer:

Thanks as at all times to all my great readers and people who proceed to stay with and use SXO! I’ve at all times wished to seek out good questions, eventualities, tales, and so forth… when you’ve got a query, please ask, if you wish to see extra, please ask… when you’ve got subject concepts that you really want me to weblog on, Please ask! I’m completely satisfied to cater to the readers and make this the most effective weblog you will see 🙂

AUTOMATION BLOG DISCLAIMER: As at all times, this can be a weblog and my (Shaun Roberts) ideas on SXO, orchestration, improvement, devops, and automation, my ideas on greatest practices, and my experiences with the merchandise and prospects. The above views are by no means consultant of Cisco or any of it’s companions, and so forth. None of those views, and so forth are supported and this isn’t a spot to seek out commonplace product help. When you want commonplace product help please accomplish that by way of the present name in numbers on Cisco.com or e-mail tac@cisco.com

Thanks and Glad Automating!!!

— Shaun Roberts,  shaurobe@cisco.com 


We’d love to listen to what you suppose. Ask a query or depart a remark under.
And keep related with Cisco DevNet on social!

LinkedIn | Twitter @CiscoDevNet | Fb | Developer Video Channel





Most Popular

Recent Comments