2023 Aug 21 6:56 AM
(Check out the SAP Developer Challenge - APIs blog post for everything you need to know about the challenge to which this task relates!)
In this task, you're going to create an instance of the SAP Cloud Management Service, with a specific plan. To find out why, read on.
This task follows on from and is in a group with the previous task (Task 7 - Create a new directory in an SAP BTP account). Having created a directory in your SAP Business Technology Platform (SAP BTP) account, you're going to eventually retrieve that directory's details programmatically, through an API endpoint.
In making such a call to the appropriate endpoint, you need to supply authentication details in the HTTP header.
What do the authentication details look like, and how do you obtain them? Well, in this and subsequent tasks, you'll find out, by reading, and by doing!
On the reading part, you should start out by jumping back to the Core Services for SAP BTP API package landing page on the SAP Business Accelerator Hub that you viewed in the previous task. You'll see a range of APIs, like this:
The Accounts Service API is described thus: "Manage the directories and subaccounts in your global account's structure". This is the API containing the endpoint that you'll eventually use to look at the details of the directory you created in the previous task.
Selecting this API, and navigating to its API Reference section, specifically to the Directory Operations group, you'll see quite a list of endpoints, some of which you can see in this screenshot:
One of them is the one you'll eventually be calling:
Note that the final part of the endpoint's path, {directoryGUID}, is what we need to specify when making a call to this endpoint. Remind you of anything? Yes, it's the GUID value of your newly created directory that you determined in the previous task.
While you're staring at the details of this endpoint, make a mental note of this part:
Required scope: $XSAPPNAME.global-account.account-directory.read
This will become relevant shortly.
While you're still in reading mode, jump back to the Accounts Service API Overview and follow the link to the SAP Help Portal documentation Account Administration Using APIs of the SAP Cloud Management Service. It's here that you'll find information on setting up for calls to this API and its endpoints. Take some time to read through the linked section and the subsections within.
Here's a very brief summary of what it says, so you have something concise to which you can refer in this and subsequent tasks in this group.
In order to make calls to API endpoints in this API (and indeed the other APIs in the package), you'll need to follow these steps:
The documentation mentions different environments in which you might create an instance of the service; for the purposes of this Developer Challenge as a whole, please use a Cloud Foundry environment. This is for a couple of reasons:
OK, let's look at precisely what your task is. That list of steps above looks quite a lot of work ... but don't worry. Your task today relates only to step 1 in the list.
There are two parts to your task here. In both parts, you should use the cf command line tool for Cloud Foundry (also known as the "cf CLI").
There are different ways you could go about creating a service instance on Cloud Foundry, but here the cf CLI is prescribed because it can be used for not only creating the instance, but also for retrieving detailed information afterwards. And of course, also because #TheFutureIsTerminal 🙂
For part one, you must complete step 1 in the list above, i.e. create an instance of the SAP Cloud Management Service (short name: cis). Do this in your SAP BTP account that you used in the previous task. Make sure you choose the appropriate plan when doing this, and create the instance in your Cloud Foundry environment.
Information on where to find the service plan details, and tips on how to create the instance itself, are detailed in the "Hints and tips" section.
For part two, you must use the Cloud Foundry API to retrieve information about your newly created service instance. Specifically, you should use the List all Service Instances endpoint (GET /v2/service_instances). And as you'll have already been using the cf CLI for part one of this task, you are strongly encouraged to use it for this part as well. Did you know that you can use the cf CLI to make calls to the CF API as well? Find out more in the "Hints and tips section below".
From the information you retrieve via the GET /v2/service_instances endpoint, you should identify the appropriate object in the resources property in the JSON returned, and pick out the value of the entity type.
Here's an example (with some properties removed for brevity):
{ "total_results": 1, "resources": [ { "metadata": { "guid": "58314563-ab6d-48db-b40c-ae4abf0e0355", "url": "/v2/service_instances/58314563-ab6d-48db-b40c-ae4abf0e0355", "created_at": "2023-08-15T10:31:13Z", "updated_at": "2023-08-15T10:31:15Z" }, "entity": { "name": "cis-central", "credentials": {}, "service_plan_guid": "7cc70093-3c5f-47f2-acf6-8de4185ba63c", "space_guid": "52311e40-efaa-4176-bef1-505f3a9889bd", "gateway_data": null, "dashboard_url": null, "type": "<instance-type>", "last_operation": { "type": "create", "state": "succeeded", "updated_at": "2023-08-15T10:31:15Z", "created_at": "2023-08-15T10:31:15Z" }, "tags": [], "maintenance_info": {}, "service_guid": "4eacd0ef-9a9d-4cb3-8fb1-60fb685d8f82" } } ] }
As you can see in this example, there's only one service instance in the Cloud Foundry environment org / space used to set up this example. This is reflected in the fact that there's only a single object contained in the resources array. That object represents and contains the details of that service instance.
The type of the service instance is given in the entity.type property within the object. In the example above, the value is deliberately hidden, and has been replaced by the string <instance-type>.
For those of you who are curious and have also tried to use cf service to list details of the service, note that the entity type shown in the output to cf service is not quite the same, and not what is required here. You have been warned!
It's the actual value of this entity.type property that you must determine and send to be hashed and shared in a reply to this discussion thread as described in Task 0. So whatever that value is, in the JSON that's returned, that's what you need to send to be hashed (don't include the double quotes, because they're just part of the JSON syntax of course).
Here are some pointers to help you with this task.
If you read through the Account Administration Using APIs of the SAP Cloud Management Service documentation, you will have come across the SAP Cloud Management Service - Service Plans section. In this section, the details of each service plan offered are available, including a list of scopes provided by each.
When creating the service instance, make sure you specify the appropriate plan, the plan that contains the scope that you need to make a GET request to the /accounts/v1/directories/{directoryGUID} API endpoint.
You are required to use the cf CLI for both parts of this task. Some of you may already have the cf CLI installed. Others may not.
For those of you who have it installed, or are willing and able to install it in their own system, we recommend you use the latest major version, i.e. version 8. The reason for this is twofold:
See Upgrading to cf CLI v8 for details of what's new and different with version 8.
For those who don't already have the cf CLI installed, and don't want to install it right now, we recommend you make use of a Dev Space in the SAP Business Application Studio. Just like the Cloud Foundry environment itself, a subscription to the SAP Business Application Studio is available to anyone and everyone, not least within a trial SAP BTP account context. You can follow the tutorial Set Up SAP Business Application Studio for Development if you need some guidance on getting access.
Once you have a subscription to the SAP Business Application Studio, create yourself a Dev Space. It doesn't have to be anything special - even a Basic Dev Space contains the cf CLI, as you can see:
Once you have a Dev Space up and running, and you have of course opened up a terminal session therein (use menu path "Terminal -> New Terminal"), you have the cf CLI at your disposal.
At this point you should log in, and specify the API endpoint that relates to your specific Cloud Foundry environment instance.
There are different ways to find out what the API endpoint is (including programmatically, see Determining your CF API endpoint), but a simple way for the purposes of this task is to head over to the SAP BTP Cockpit and check in the subaccount overview:
Once you've logged in, you'll need to familiarize yourself with the cf CLI commands related to this task.
For the first part of the task, look into the "Services integration" commands (get to this list using the command cf help):
Services integration: marketplace,m create-user-provided-service,cups services,s update-user-provided-service,uups create-service,cs create-service-key,csk update-service delete-service-key,dsk delete-service,ds service-keys,sk service service-key bind-service,bs bind-route-service,brs unbind-service,us unbind-route-service,urs
In particular:
When using cf marketplace, note that the service offerings will be listed using their technical name. The technical name for the SAP Cloud Management Service is cis, as noted in the Account Administration Using APIs of the SAP Cloud Management Service section on the SAP Help Portal.
For the second part of the task, you'll want to look at:
Interestingly, if you want to find this command in the list of possible commands in the cf CLI, you must use:
cf help -a
(i.e. include the -a option) otherwise it's not shown.
Good luck and have fun!
How else might one create an instance of a service? Is this your first encounter with the cf CLI? How did you find it? What is your favorite place to run command line tools?
2023 Aug 23 2:11 AM
2023 Aug 23 6:21 AM
2023 Aug 23 6:44 AM
By the way, I could not filter the cloud management service instance using -d 'q=name:<myinstancename>' In windows it returned all the services in the entire global account and in linux it threw an error with code 10001.
Appreciate if anyone can help me to understand what exactly I am missing?
-Anupam
2023 Aug 23 6:58 AM
2023 Aug 23 9:55 AM
2023 Aug 23 10:40 AM
2023 Aug 23 1:04 PM
2023 Aug 23 1:14 PM
2023 Aug 23 2:19 PM
2023 Aug 24 2:53 AM
2023 Aug 24 2:57 AM
As this is my first time using CF CLI, I find the process to be quite a challenge to get used to it, especially as I was used to adding service instances in the service marketplace through the CF GUI, but a Google search did eventually lead to the solution. I was also kicking myself for nearly an hour to finish this task, turns out I was not supposed to read the directory GUID from the API just yet. I usually prefer to use Windows' default command line interface, but for this case, I would rather use the command line in BAS since it means I can run it without installing the program natively.
2023 Aug 24 10:40 AM
Thanks for sharing your thoughts, @choujiacheng ! In a way, I find that a bit of a struggle to get things working does help in the long term, because the peripheral work one does to figure out what to do is also part of the learning process. I'm glad you got there!
I'm a massive fan of the power of the command line, which in turn means (for me) a UNIX style shell, with all that goodness that the UNIX philosophy entails (small well behaved programs that do one thing well, and a beautiful STDIN/STDOUT/STDERR and pipe model for glueing these programs together). One of my favourite aspects of BAS is that the Dev Spaces give you a proper command line with such a shell (Bash, to be precise, The One True Shell(tm) ;-))
2023 Aug 24 9:14 AM
2023 Aug 25 3:20 AM
2023 Aug 25 8:06 AM
2023 Aug 25 9:34 AM
2023 Aug 25 4:47 PM
2023 Aug 26 3:22 PM
2023 Aug 27 1:31 AM
2023 Aug 27 11:47 AM - edited 2023 Sep 02 8:40 AM
2023 Aug 27 7:30 PM
2023 Aug 28 7:43 AM
I generally use cf-cli to deploy node/python applications. But I havn't tried to manage service instances before. This task gave me some idea on CF8-CLI for Infra deployments.
Using Node-Red is always fun. And all the CF8 deployments / Service Managments can be easily scaled and automated as well using Node-red. Here we can automate a server to perform a CLI based task easily through HTTP Injections as well. I have just tried out something -
In this Node-Red Flow, I have added a HTTP Request IN Node - "/cis_service_entity_type". Now this becomes a API which I can consume..
2023 Aug 28 3:22 PM
2023 Aug 28 5:27 PM
2023 Aug 28 5:31 PM
Struggled quite a bit to get the CF login via API, documentation is pretty hard to find
This works:
POST https://uaa.cf.us10-001.hana.ondemand.com/oauth/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic cf:
grant_type=password
&username={{$dotenv CIS_USER}}
&password={{$dotenv CIS_PASSWORD}}
2023 Aug 28 8:58 PM
2023 Aug 28 9:02 PM
@qmacro , great exercise. cf curl is certainly something I didn't know would work.
Here is a question for you though: In Task 1, why does the client credentials authentication in task one have a different scope (only uaa.resources) than the password type? I tried specifying the scope explicitly, but didn't get anywhere.
2023 Aug 29 4:34 AM
2023 Aug 29 4:10 PM
2023 Aug 29 8:00 PM
2023 Aug 30 4:10 PM
2023 Aug 31 5:21 PM
2023 Aug 31 9:12 PM
2023 Sep 01 2:28 PM
2023 Sep 03 7:14 AM
2023 Sep 04 4:36 AM
2023 Sep 04 5:08 AM
2023 Sep 04 9:20 AM
Hey everyone! The challenge to which this task belongs is now officially closed. Head over to the original blog post SAP Developer Challenge – APIs to check out the closing info and final statistics, and to see your name in lights! 🎉 And we thank you all for participating, you made this challenge great!
2023 Sep 04 10:17 AM - edited 2023 Sep 04 10:40 AM
2023 Sep 04 4:06 PM