# OpenCAPIF SDK usage OpenCAPIF SDK implements this set of features to easily integrate an application with CAPIF NF either manually, using scripting, or integrating SDK library directly within app code. Before using it, it is required to have fulfilled the [requirements](./sdk-prerequirements.md) section, the [installation](./sdk-installation.md) section and the selected parts of the [configuration](./sdk-configuration.md) depending on the CAPIF role the NetApp is going to play. ![GENERAL CAPIF USAGE FLOW](./images/Flujo%20completo-OPENCAPIF%20ACTUAL.jpg) This repository includes 2 different modes to test OpenCAPIF SDK: - **Development usage**: import SDK in the code and start ... Within [nf-sample folder](../netapp-samples/), it is provided a sample application leveraging - **Manual usage**: use a set of python [scripts](../scripts/) to test step by step all implemented procedures. All of them are provided at scripts folder - For Manual usage it is required to complete the utilities file with the absolute paths of target environment in order to complete the configuration of the SDK: **NOTE**:register file is not needed for the use of the SDK **IMPORTANT**:It is needed to fill out config files depending on the features required to be used from the SDK.Please if it is not fulfilled this file, go to the [Configuration Section](./sdk-configuration.md) # Table of contents As explained before, OpenCAPIF SDK is designed to play two different roles: - [Provider NetApp](#provider-netapp) - [Important Information for Provider](#important-information-for-provider-consumer) - [Onboard Provider](#onboard_provider--script-provider_capif_connectorpy) - [Publish Services](#publish_services--script-provider_publish_apipy) - [Unpublish Services](#unpublish_service--script-provider_unpublish_apipy) - [Update Services](#update_service--script-provider_update_apipy) - [Get Published Services](#get_service--script-provider_get_published_apipy) - [Get All Published Services](#get_all_services--script-provider_get_all_published_apipy) - [Update and Offboard Provider](#update_provider-and-offboard_provider--provider_capif_connector_updatepy-and-provider_capif_connector_offboardingpy) - [Invoker NetApp](#invoker-netapp) - [Important Information for Invoker](#important-information-for-invoker-consumer) - [Onboard Invoker](#onboard_invoker--script-invoker_capif_connectorpy) - [Discover API](#discover--script-invoker_service_discoverpy) - [Get Tokens](#get_tokens--script-invoker_service_get_tokenpy) - [Update and Offboard Invoker](#update_invoker-and-offboard_and_deregister_invoker--invoker_capif_connector_updatepy-and-invoker_capif_connector_offboardingpy) - [Other Features](#other-features) - [Register and Login](#script-register_and_loginpy) - [Deregister and Login](#script-deregister_and_loginpy) # Provider NetApp The common path to follow using CAPIF in order to publish an API is by following this steps: ## Important information for Provider consumer In the `provider_folder`, it will be located several folders with each `capif_username` that has onboarded as a provider, for each folder it is created by SDK this files: - `capif_provider_details.json` : Contains all the APFs and AEFs ids that have already onboarded with this capif_username - `CAPIF_<_API_id>.json` : If it's already published or updated an API, It will be available a copy of the last payload. - `service_received.json` : If it's already used the get an api or get all apis functionality, It will be available the response to the request. - `published-apis.json` : Contains the currently published APIs with their ApiId ### Provider onboarding CAPIF SDK references: * **CAPIF SDK function**: onboard_provider()\ * **CAPIF SDK script**: provider_capif_connector.py SDK simplifies the onboarding process for Provider developers. It also provides the capability to register several APFs and AEFs if necessary. ![Provider_onboard](./images/provider_onboarding.png) [CAPIF_Publish_Service_API](https://github.com/jdegre/5GC_APIs/blob/Rel-18/TS29222_CAPIF_Publish_Service_API.yaml) Using Publish Service it is required to fulfill certain fields of the [capif-sdk-config.json](./sdk-configuration.md) file. ### Services publishing CAPIF SDK references: * **CAPIF SDK function**: publish_services()\ * **CAPIF SDK script**: provider_publish_api.py SDK simplifies the process of publishing an API in CAPIF. Besides, it also provides the ability to chose which APF and AEFs will be used to publish the API. It is mandatory to be [onboarded as a provider](#onboard_provider--script-provider_capif_connectorpy): Mandatory fields: - PublisherAPFid - PublisherAEFsids ### Services deletion CAPIF SDK references: * **CAPIF SDK function**: unpublish_service()\ * **CAPIF SDK script**: provider_unpublish_api.py SDK simplifies the process of deleting an API available in CAPIF. It is mandatory to have onboarded as a [provider](#onboard_provider--script-provider_capif_connectorpy) before and to have [published any service](#publish_services--script-provider_publish_apipy) before Mandatory fields: - ServiceApiId - PublisherAPFid - PublisherAEFsids ### Services update CAPIF SDK references: * **CAPIF SDK function**: update_service()\ * **CAPIF SDK script**: provider_update_api.py SDK simplifies the process of updating an API already registered at CAPIF. It also supports selecting which APF and AEFs will be used to update the API. It is mandatory to have onboarded as a [provider](#onboard_provider--script-provider_capif_connectorpy) before and to have [published any service](#publish_services--script-provider_publish_apipy) before Mandatory fields: - ServiceApiId - PublisherAPFid - PublisherAEFsids ### Get services CAPIF SDK references: * **CAPIF SDK function**: get_service()\ * **CAPIF SDK script**: provider_get_published_api.py SDK simplifies the process of receiving the information of one service published previously in published-apis.json It is mandatory to have onboarded as a [provider](#onboard_provider--script-provider_capif_connectorpy) before and to have [published any service](#publish_services--script-provider_publish_apipy) before Mandatory fields: - ServiceApiId - PublisherAPFid ### Get all services CAPIF SDK references: * **CAPIF SDK function**: get_all_services()\ * **CAPIF SDK script**: provider_get_all_published_api.py SDK simplifies the process of receiving the information of all available services published previously in published-apis.json It is mandatory to have onboarded as a [provider](#onboard_provider--script-provider_capif_connectorpy) before and to have [published any service](#publish_services--script-provider_publish_apipy) before Mandatory fields: - PublisherAPFid ![Provider_publish](./images/provider_publish.png) ### Update and Offboard provider CAPIF SDK references: * **CAPIF SDK function**: update_provider() & offboard_provider() * **CAPIF SDK script**: provider_capif_connector_update.py & provider_capif_connector_offboarding.py For using this features we must be previously onboarded as a provider. ![Provider_update-offboard](./images/provider_update-offboard.png) # Invoker NetApp The common path to follow using CAPIF in order to get an API token of the service it's wanted to use is by following this steps: ## Important information for Invoker consumer In the `invoker_folder`, it will be located several folders with each `capif_username` that has onboarded as a provider. For each folder, it could be found: - `capif_api_security_context_details.json`: This file contains the information of the invoker. It will contain: 1. The `api_invoker_id`. 2. If it has already used the Service Discovery Functionality, it will be found all the available APIs with their information. 3. If it has already used the Service Get Token functionality, it will be found the access token for using the APIs that has already been discovered. ### onboard_invoker() // Script invoker_capif_connector.py Simplifies the process of onboarding for Invoker users ![Invoker_onboard](./images/Invoker_onboarding.png) ### Discover process CAPIF SDK references: * **CAPIF SDK function**: discover()\ * **CAPIF SDK script**: invoker_service_discover.py In this functionality, [discover_filter](./sdk-configuration.md) is used to retrieve the access of target API specified in discover filter. It is mandatory to be onboarded as a [invoker](#onboard_invoker--script-invoker_capif_connectorpy). DISCLAIMER: if it's the first time the user runs discover() it will appear a warning alert like this WARNING - Received 404 error, redirecting to register security service ![Invoker_discover](./images/Invoker_discover.png) ### Obtain Invoker tokens CAPIF SDK references: * **CAPIF SDK function**: get_tokens()\ * **CAPIF SDK script**: invoker_service_get_token.py This functionality simplifies the process of creating a security context based on JWT tokens in CAPIF, allowing to access the target APIs. This functionality **requires** to to be onboarded as a [invoker](#onboard_invoker--script-invoker_capif_connectorpy) before and run the [discover](#discover--script-invoker_service_discoverpy) function at least once before. ![Invoker_get_token](./images/invoker_get_token.png) ### Update & offboard invoker CAPIF SDK references: * **CAPIF SDK function**: update_invoker() & offboard_and_deregister_Invoker() * **CAPIF SDK script**: invoker_capif_connector_update.py & invoker_capif_connector_offboarding.py To use these features, the NetApp must be previously [onboarded as an invoker](#onboard_invoker--script-invoker_capif_connectorpy). ![Invoker_update-offboard](./images/invoker_update-offboard.png) # Other features Apart from the SDK core, there are available different functionalities for development purposes: ### Script register_and_login.py Facilitates the logging process for admin users and creates a CAPIF user, ### Script deregister_and_login.py Facilitates the logging process for admin users and eliminates a CAPIF user. ![Register picture](./images/Flujo%20completo-SDK%20ACTUAL%20CON%20REGISTER.jpg)