Created
September 1, 2023 13:22
-
-
Save recklessop/94cdd3edd4779aee1d2de0e5493d3939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
base_server = "192.168.50.60" | |
keycloak_base_url = f"https://{base_server}/auth" # Replace with your Keycloak server URL | |
zvm_api_url = f"https://{base_server}/v1" | |
realm = "zerto" # Replace with your Keycloak realm name | |
client_id = "api-script" | |
client_secret = "fcYMFuA5TkIUwp6b3hDUxim0f32z8erk" # Replace with your client's secret key | |
token_url = f"{keycloak_base_url}/realms/{realm}/protocol/openid-connect/token" | |
data = { | |
"grant_type": "client_credentials", | |
"client_id": client_id, | |
"client_secret": client_secret, | |
} | |
# Disable SSL certificate verification (use with caution) | |
response = requests.post(token_url, data=data, verify=False) | |
if response.status_code == 200: | |
access_token = response.json()["access_token"] | |
print("Authentication successful. Access token:", access_token) | |
else: | |
print("Authentication failed. Status code:", response.status_code) | |
print("Error message:", response.text) | |
uri = zvm_api_url + "/vpgs" | |
print(uri) | |
headers = { | |
"Authorization": f"Bearer {access_token}", | |
"accept": "application/json" | |
} | |
# Make a POST request to the token URL with the data headers=headers, | |
response = requests.get(uri, headers=headers, verify=False) | |
# Check if the request was successful (HTTP status code 200) | |
if response.status_code == 200: | |
# Parse the response JSON to get the access token | |
print(response.text) | |
else: | |
print("Status code:", response.status_code) | |
print("Error message:", response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment