Sunday, June 4, 2023
HomeHealthcareLet'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 season on a scorching foot and we get loads on the market. To let you understand about a number of the new work I’ve been taking up, I wished to carry you one thing from the land of Enterprise Essential Providers (BCS). This can be a new enviornment 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 number of issues on this weblog…

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

Earlier than I get to our nice content material of the day, I’ve a number of issues to share. The primary one is that Cisco Stay is again and will likely be in individual in fabulous Las Vegas! And sure readers, I will likely be there prepared to show you all about automation and orchestration. I will likely be educating a 4 hour lab that you will discover at LTRATO-1000. Within the lab I will likely be educating alongside my superior pal and co-automation professional, Mohammed Hamzeh. House is proscribed and some spots are nonetheless there so join in the present day! Secondly, one other cool factor I’ve began to work on is a podcast that we’ve got began (once more, therefore much less blogs). This podcast is round bringing one of the best Cisco minds to you the listening viewers and our prospects. The podcast known as Cisco Tech Insiders and you 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 through e-mail to me or feedback on the weblog.

Like I stated… let’s make some magic! So time to focus on what we’re going to do in the present day 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 begin with any API, we have to discover Authentication and Documentation on the API Spec. Fortunately, this can be a effectively completed API and we’ve got each! Authentication is finished through Shopper Secret+Shopper ID right into a JWT token…. we will discover the data we want right here…

  1. Authentication
  2. OpenAPI Spec

Notice: Previous to doing a number of the API greatness you will want to undergo the On-boarding Course of and Software Registration so you may 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. When you’ve got any points getting on boarded or within the software registration course of please attain out to your BCS Account Undertaking 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 to your reference.

The steps we want for Authentication (assuming you’ve 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’d do one thing like this (in python):

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

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

    strive:
        resp = httpx.Shopper().put up(url=url, json=information)
        resp.raise_for_status()
    besides (httpx.HTTPStatusError, httpx.RequestError) as err:
        logger.error(
            f'Didn't JSON Internet Token(JWT): {err}'
        )
        increase err
    else:
        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().put up(url=url, json=information) 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 by way of 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 may 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 beneath 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 sort 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 precise facet of your window.
  10. On the exercise set the RELATIVE URL to token , the METHOD to put up, 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 need to cross variables into these fields, so you may copy the above into the REQUEST BODY discipline 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 discipline. That is the insert variable reference icon. When you click on that, navigate to Workflow->input->I_client_id for the shopper id discipline and Workflow->input->I_client_secret for the key. Set the content material sort to JSON.
  13. Subsequent we need to parse the token out and reserve it to a safe string. Seek for the JSONPath Question exercise and drag and drop it beneath 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 beneath that discipline after which within the JSONPATH QUERY discipline enter $..accessToken after which simply accessToken for the PROPERTY NAME. Set it to sort SECURE STRING.
  15. Lastly, search for the SET VARIABLE exercise and drag and drop it beneath 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 discipline, click on the puzzle piece icon and choose Activities->JSONPATH Question Exercise->accessToken.
  16. Your workflow is full! It’s best 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 remaining outcome so that you can view alongside what we simply stepped by way of… so I’ve loads of that upcoming for you. As they are saying in cooking reveals, “at all times have a pre-baked turkey to associate with the one you might be 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). Similar to you importing a package deal 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 could find them on the Shared CX SXO Repo and in time they are going to be printed to the official SXO atomics git. To make this *even* higher you will discover 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 assume you wouldn’t get a video proper???) and an instance workflow that will refresh your JWT token within the background as an alternative of you having to re-call it every time you need to use the API. These are nonetheless an opensource model nature workflows and atomics so if in case you have 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 is no such thing as a password!

Customary 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 on… if in case you have a query, please ask, if you wish to see extra, please ask… if in case you have subject concepts that you really want me to weblog on, Please ask! I’m pleased to cater to the readers and make this one of the best weblog you will discover 🙂

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 finest practices, and my experiences with the merchandise and prospects. The above views are under no circumstances consultant of Cisco or any of it’s companions, and so on. None of those views, and so on are supported and this isn’t a spot to seek out normal product help. If you happen to want normal product help please accomplish that through the present name in numbers on Cisco.com or e-mail tac@cisco.com

Thanks and Completely happy Automating!!!

— Shaun Roberts,  shaurobe@cisco.com 

 

We’d love to listen to what you assume. Ask a query or depart a remark beneath.
And keep linked with Cisco DevNet on social!

LinkedIn | Twitter @CiscoDevNet | Fb | Developer Video Channel

 

Share:



RELATED ARTICLES

Most Popular

Recent Comments

error: Content is protected !!