[ad_1]
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 sizzling foot and we get a lot on the market. To let you recognize about a few of the new work I’ve been taking up, I wished to convey 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…
- Constructing some wonderful Atomics for an API in SecureX Orchestration!
- Constructing workflows geared in direction of our BCS Operational Insights API!
- Having the ability to map given code (on this case python) to SXO workflows
- Giving some greatest practices round workflow and atomic creation
- 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 probably be in individual in fabulous Las Vegas! And sure readers, I will probably be there prepared to show you all about automation and orchestration. I will probably be instructing a 4 hour lab that you’ll find at LTRATO-1000. Within the lab I will probably be instructing alongside my superior good friend and co-automation skilled, Mohammed Hamzeh. Area 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’ve 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’ll find it on SoundCloud (search for our brand… its a microphone with Cisco Tech Insiders subsequent to it) or on Spotify. I extremely would recommend some listens and see if something we discuss excites you. As at all times, you may recommend issues by way of electronic 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 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 properly finished API and we’ve each! Authentication is completed by way of Consumer Secret+Consumer ID right into a JWT token…. we will discover the knowledge we want right here…
Observe: Previous to doing a few of the API greatness you have to to undergo the On-boarding Course of and Utility Registration so you may get your Consumer ID and Consumer 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 utility registration course of please attain out to your BCS Account Mission Supervisor and/or related Consulting Engineers in your challenge.
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 on your reference.
The steps we want for Authentication (assuming you’ve your consumer id and consumer secret) are…
- Make API name to the token endpoint
- Extract and preserve 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'
information = {
"grantType": "client_credentials",
"clientId": client_id,
"secret": client_secret,
"scope": "api.bcs.handle"
}
strive:
resp = httpx.Consumer().submit(url=url, json=information)
resp.raise_for_status()
besides (httpx.HTTPStatusError, httpx.RequestError) as err:
logger.error(
f'Did not JSON Net 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.Consumer().submit(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 constructing these items…
How To Construct a JWT Token Atomic
- Go to SXO and choose Targets on the left menu
- Click on
NEW TARGETand choose HTTP Endpoint. Name it BCS Operational Insights Auth API - Set
NO ACCOUNT KEYSto true. SetPROTOCOLto HTTPS,HOST/IPto api-cx.cisco.com andPATHto /torii-auth/v1/. You’ll be able to see all of those values within the Python script as properly. Click onSUBMIT.
- Click on the Workflows on the left menu after which click on
NEW WORKFLOW - On the far proper beneath
VARIABLES, click onADD VARIABLEand add aSTRINGknown as I_client_id, make it required and make itsSCOPEto be enter. Add aSECURE STRINGknown as I_client_secret, make it required and make itsSCOPEto be enter.
- Then add one other variable
SECURE STRING. Name it O_jwt_token and make itsSCOPEto be output.
- Within the
TARGETpart, chooseEXECUTE ON THIS TARGETand choose the goal sort ofHTTP ENDPOINTafter which choose the goal you created above. - 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. - 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.
- On the exercise set the
RELATIVE URLto token , theMETHODto submit, and theREQUEST BODYought to mirror what’s within the instance. It ought to like this…{"grantType": "client_credentials", "clientId": "", "secret": "", "scope": "api.bcs.handle" }
- As you see I left the clientId and secret clean. It’s because we wish to go variables into these fields, so you may copy the above into the
REQUEST BODYarea and hit the format button to make it look good! - To go 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_idfor the consumer id area andWorkflow->input->I_client_secretfor the key. Set the content material sort to JSON.
- 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 beneath your HTTP Request exercise.
- Click on on the JSONPath exercise. Within the
SOURCE JSON TO QUERY, click on the puzzle piece icon and chooseActions->Your HTTP Request ->Physiqueand save. Click on+ADDbeneath that area after which within theJSONPATH QUERYarea enter $..accessToken after which simply accessToken for thePROPERTY NAME. Set it to sortSECURE STRING.
- Lastly, search for the
SET VARIABLEexercise and drag and drop it beneath the JSONPath question. Click on+ADDand within theVARIABLE TO UPDATE, click on the puzzle piece icon and chooseWorkflow->output->O_jwt_token. Within theNEW VALUEarea, click on the puzzle piece icon and choose Activities->JSONPATH Question Exercise->accessToken. - Your workflow is full! You need to be capable to validate it and click on run. Enter your consumer id and secret and it’ll generate a token for you!
Now I’d be a poor teacher if I didn’t embody a ultimate end result so that you can view alongside what we simply stepped by… 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’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 package deal or copying and pasting pattern code you should have all of my workflows so that you can use and construct cool BCS automations. (or MAGIC!) Yow will discover 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 see some pattern utilization workflows on the Shared CX SXO Repo that can assist you get began. These embody 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 will 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 fashion nature workflows and atomics so when 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 isn’t any password!
Normal 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 have a query, please ask, if you wish to see extra, please ask… when you have matter concepts that you really want me to weblog on, Please ask! I’m completely happy to cater to the readers and make this one of the best weblog you will see
AUTOMATION BLOG DISCLAIMER: As at all times, this can be a weblog and my (Shaun Roberts) ideas on SXO, orchestration, growth, devops, and automation, my ideas on greatest practices, and my experiences with the merchandise and prospects. The above views are on no account 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 normal product assist. For those who want normal product assist please accomplish that by way of the present name in numbers on Cisco.com or electronic mail tac@cisco.com
Thanks and Joyful Automating!!!
— Shaun Roberts, shaurobe@cisco.com
We’d love to listen to what you suppose. Ask a query or depart a remark beneath.
And keep related with Cisco DevNet on social!
LinkedIn | Twitter @CiscoDevNet | Fb | Developer Video Channel
Share:
[ad_2]
