Skip to content

Instantly share code, notes, and snippets.

@CITGuru
Created August 7, 2020 19:51
Show Gist options
  • Save CITGuru/d99072c6eea8f3d9ce5c051c0350deec to your computer and use it in GitHub Desktop.
Save CITGuru/d99072c6eea8f3d9ce5c051c0350deec to your computer and use it in GitHub Desktop.
# auth.py
import akeyless_proxy_api # import our installled module
from api import request_api_key
# Setup our configuration
api_conf = akeyless_proxy_api.Configuration()
api_conf.host = "rest.akeyless-security.com"
# create an instance of the Proxy API class
api_client = akeyless_proxy_api.ApiClient(api_conf)
api_instance = akeyless_proxy_api.DefaultApi(api_client)
# Authenticating - We'll be using our API Key
access_id = 'access-id' # Access Id
access_type = 'api_key' # Access Type (api_key/okta_saml) (optional)
access_key = 'access_key' # Access key (relevant only for access-type=api_key) (optional)
def get_token():
# Authenticate to the service and returns an access token
auth_response = api_instance.auth(access_id, access_type=access_type, access_key=access_key)
token = auth_response.token
return token
def get_api():
token = get_token()
api_key = api_instance.get_secret_value("food-ordering-api", token)
if api_key.status == "success":
return api_key.response[0]
else:
secret_name = 'food-ordering-api' # Secret name
secret_value = request_api_key().get("token") # secret value
secret_metadata = 'Food ordering API Key' # Description about the secret (optional)
create_response = api_instance.create_secret(secret_name, secret_value, token, metadata=secret_metadata)
return secret_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment