Initializing the Fuzzball Workflow Service API
This demo requires the Fuzzball CLI to be set up in your environment. For more information please see the documentation on installing the Fuzzball CLI.
Once the Fuzzball CLI is set up in your environment, you will need to log into your
context such that configuration file
~/.config/fuzzball/config.yaml
contains a valid API token for your active Fuzzball context.
The Fuzzball Workflow Service API must be initialized in this way before any of the following procedures can be completed.
$ fuzzball context login
Logging into current cluster context...
Using a secure browser, open the link to complete login:
https://auth.ciq.dev/auth/realms/e700253c-8ce8-4e36-a420-1e4cab4cb7ef/device?user_code=IVWJ-ZJAZ
Waiting for login completion... Account "User Account (dgodlove@ciq.co)" in use
The code snippet below initializes an instance of the Fuzzball workflow service API. It does this by:
- reading the configuration file
~/.config/fuzzball/config.yaml
into the variableconfig
- initializing a Fuzzball configuration in the variable
api_config
- setting the variables
host
,api_key
,api_key_prefix
inapi_config
using the active context in the configuration file~/.config/fuzzball/config.yaml
- initializing a Fuzzball API client with the variable
api_config
- initializing the Fuzzball workflow service API using the Fuzzball API client initialized in the
previous step as variable
api_instance
Lastly, the code implements a workaround for a bearer authentication bug in Python when using Swagger Codegen.
import fuzzball
import sys
import yaml
import os.path
with open(os.path.expanduser("~/.config/fuzzball/config.yaml")) as stream:
try:
config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
sys.exit(-1)
api_config = fuzzball.Configuration()
activeContext = config['activeContext']
for context in config['contexts']:
if context['name'] == activeContext:
api_config.host = "https://{}/v2".format(context['address'])
api_config.api_key['api_key'] = context['auth']['credentials']['token']
api_config.api_key_prefix = {'Bearer': context['auth']['credentials']['token']}
api_instance = fuzzball.WorkflowServiceApi(fuzzball.ApiClient(api_config))
# Bearer auth is broken for Python in Swagger Codegen
# Workaround from https://github.com/swagger-api/swagger-codegen/issues/10060#issuecomment-819545223
api_instance.api_client.set_default_header("Authorization", "Bearer {}".format(api_config.api_key['api_key']))
The next sections will detail usage of the initialized Fuzzball workflow service API to perform various Fuzzball workflow operations.