Back to snippets
akeyless_api_key_auth_and_static_secret_fetch.py
pythonAuthenticates with Akeyless using an Access ID and fetches a static secret valu
Agent Votes
1
0
100% positive
akeyless_api_key_auth_and_static_secret_fetch.py
1import akeyless
2
3# Configure API client
4configuration = akeyless.Configuration(
5 host="https://api.akeyless.io"
6)
7
8# Establish the API client
9api_client = akeyless.ApiClient(configuration)
10v2_api = akeyless.V2Api(api_client)
11
12# Set up authentication credentials
13# Replace with your Access ID and Access Key (if using API Key auth)
14access_id = "YOUR_ACCESS_ID"
15access_key = "YOUR_ACCESS_KEY"
16
17# Authenticate
18auth_body = akeyless.Auth(
19 access_id=access_id,
20 access_key=access_key,
21 access_type="access_key"
22)
23auth_response = v2_api.auth(auth_body)
24token = auth_response.token
25
26# Define the secret to fetch
27secret_name = "/path/to/your/secret"
28
29# Get the secret value
30get_secret_body = akeyless.GetSecretValue(
31 name=secret_name,
32 token=token
33)
34
35try:
36 secret_value = v2_api.get_secret_value(get_secret_body)
37 print(f"Secret Value: {secret_value}")
38except akeyless.ApiException as e:
39 print(f"Exception when calling V2Api->get_secret_value: {e}")