Intersight Authentication helper for requests
Project description
intersight-auth
This module provides an authentication helper for requests to make it easy to make Intersight API calls using requests.
Features
- Supports both v2 and v3 keys
- Keys can be supplied as strings or path to a PEM file
Install
pip install intersight-auth
Example using a file for the secret key
import sys
from intersight_auth import IntersightAuth
from requests import Session
session = Session()
session.auth = IntersightAuth("XYZ/XYZ/XYZ", "key.pem")
response = session.get("https://intersight.com/api/v1/ntp/Policies")
if not response.ok:
print(f"Error: {response.status_code} {response.reason}")
sys.exit(1)
for policy in response.json()["Results"]:
print(f"{policy['Name']}")
Example using a multiline (a.k.a. heredoc) string for the secret key
The secret key must still be in PEM format even if it's a string instead of a file.
my_secret_key='''
-----BEGIN RSA PRIVATE KEY-----
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjklmnopqrstuvwxy
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/abcdefghizjkl=
-----END RSA PRIVATE KEY-----
'''
session = Session()
session.auth = IntersightAuth(
api_key_id="XYZ/XYZ/XYZ",
secret_key_string=my_secret_key
)
response = session.get("https://intersight.com/api/v1/ntp/Policies")
if not response.ok:
print(f"Error: {response.status_code} {response.reason}")
sys.exit(1)
for policy in response.json()["Results"]:
print(f"{policy['Name']}")
Example of PEM repair
The need to present the secret key in PEM format can be a challenge with some secret management approaches. The PEM could be collapsed onto a single line, or the whitespace could otherwise be disturbed. A function is provided to attempt to resolve these kinds of issues.
from intersight_auth import IntersightAuth, repair_pem
# This PEM has required the whitespace removed
broken_pem = "-----BEGIN EC PRIVATE KEY-----ABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900abcdefghizjklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900abcdefghizjklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900abcdefghizjklmnopq-----END EC PRIVATE KEY-----"
session = Session()
session.auth = IntersightAuth(
api_key_id="XYZ/XYZ/XYZ",
secret_key_string=repair_pem(broken_pem)
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file intersight_auth-0.2.5.tar.gz
.
File metadata
- Download URL: intersight_auth-0.2.5.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d3cfa2fe80d08873d14c968029a4bdbf7901ebbd093ab4d9689d033de4552aa |
|
MD5 | 0a029232dd2fb36e089cc883e5892f6f |
|
BLAKE2b-256 | 1a1504e957e34eddedd60959c09c57312f8eab7927f666963a214d0a152bdb6b |
File details
Details for the file intersight_auth-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: intersight_auth-0.2.5-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccd020afbf554bd933d0c6cdf555cbe779d884c070d18a7f79ff09727e890a97 |
|
MD5 | 878a8c9dd5442cde6183eee38d9add0d |
|
BLAKE2b-256 | 4815cbde51e6036bfad99aab5876933f2c7f215e112b19e6d10d6cab64cc0ba6 |