Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dciauth-4.0.1.post202603121510.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dciauth-4.0.1.post202603121510-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file dciauth-4.0.1.post202603121510.tar.gz.

File metadata

  • Download URL: dciauth-4.0.1.post202603121510.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dciauth-4.0.1.post202603121510.tar.gz
Algorithm Hash digest
SHA256 b36cb0daaf3c6e36252fd29539b19477495cdd5e4d94e288d2512805d47d6c9d
MD5 ca63a4d11400a0ae52f696fa3cff077e
BLAKE2b-256 7e5d8a517464fa844971c99686204fab58ff7fc50bdf6a59388ad4dc1d280120

See more details on using hashes here.

File details

Details for the file dciauth-4.0.1.post202603121510-py3-none-any.whl.

File metadata

File hashes

Hashes for dciauth-4.0.1.post202603121510-py3-none-any.whl
Algorithm Hash digest
SHA256 e23135cc4a1802a383baf3428eb9f3b3fdc75f398920af2f6a35d3662dd1bc59
MD5 148dc679fae7b2602c169dc70a2c3ee2
BLAKE2b-256 ceba76efc9ec366bb8e1f823b2cdec57c4bb7ae27ba5eaa46327efc75667fcb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page