DCI authentication module used by dci-control-server and python-dciclient
Project description
python-dciauth
DCI authentication module used by dci-control-server and python-dciclient
This section shows example programs written in python that illustrate how to work with Signature Version 2 in DCI. The algorithm used by dciauth is identical to Signature Version 4 in AWS.
Authentication example:
Create a HmacAuthBase
object to give to python requests module
from dciauth.signature import HmacAuthBase
auth = HmacAuthBase(
access_key="access_key",
secret_key="secret_key",
region="us-east-1",
service="api",
service_key="aws4_request",
algorithm="AWS4-HMAC-SHA256",
)
GET
import requests
requests.get("http://api.distributed-ci.io/api/v1/jobs", auth=auth)
POST
import requests
requests.post("http://api.distributed-ci.io/api/v1/users", auth=auth, json={"name": "user 1"})
Validation example
import flask
from dciauth.signature import FlaskHmacSignature
@app.route("/api/protected", methods=["GET"])
def get_protected():
auth_scheme = flask.request.headers.get("Authorization").split(" ")[0]
if auth_scheme == "AWS4-HMAC-SHA256":
signature = FlaskHmacSignature(
{
"service_name": "api",
"service_key": "aws4_request",
"region_name": "us-east-1",
"algorithm": "AWS4-HMAC-SHA256",
}
).add_request(flask.request)
assert signature.access_key == "access_key"
if not signature.is_valid(secret_key="secret_key"):
return "ko", 401
return "ok", 200
return "ko", 400
Using POSTMAN
If you are using POSTMAN to discover DCI API you can use the following parameters with the AWS Signature authorization header:
GET https://api.distributed-ci.io/api/v1/identity
AccessKey=<DCI_CLIENT_ID>
SecretKey=<DCI_API_SECRET>
AWS Region="BHS3"
Service Name="api"
License
Apache 2.0
Author Information
Distributed-CI Team distributed-ci@redhat.com
Project details
Release history Release notifications | RSS feed
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 dciauth-4.0.1.post202411050953.tar.gz
.
File metadata
- Download URL: dciauth-4.0.1.post202411050953.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc650b21cc5857db08f481108ef1f4865967c6682f957f4fa2f55d5b847c5663 |
|
MD5 | 37c7a88502a1343069918b5630a11ede |
|
BLAKE2b-256 | 5e21c4a1f551bbd9f9e7db6dfdd243a22ec287fc724c9fecadf260d7e3ec5bb7 |
File details
Details for the file dciauth-4.0.1.post202411050953-py3-none-any.whl
.
File metadata
- Download URL: dciauth-4.0.1.post202411050953-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c95b09d6ec20d11e7e8b62a75eccfecf69f46834f6d809ec2a342bce323fbc7f |
|
MD5 | 6cb1ed96a6e9c4c22d3ad1c6919cfbe4 |
|
BLAKE2b-256 | 0900d3aebd3623bac5f66917bf615972f989a5929f4279d817c25acd9b8e6602 |