Skip to main content

keystone-light :: A limited Identity API v3 python client

keystone-light implements a Python interface to a very limited subset of the OpenStack Identity API v3.

Initial goal: access to OpenStack Swift, using the Identity API v3, but with a lot fewer dependencies.

As of this writing, the python-keystoneclient requires keystoneauth1 and oslo.*, which in turn require some more. We only require the ubiquitous requests (and PyYAML), which you generally already have installed anyway.

Example usage

#!/usr/bin/env python3
from urllib.parse import urljoin

import requests
from keystone_light import Cloud, CloudConfig, PermissionDenied


def get_projects(cloud):
    "Yields projects, sorted by domain and project name"
    domains = cloud.get_domains()
    for dom in sorted(domains, key=(lambda x: x.name)):
        if dom.name == 'Default':
            # print('WARN: skipping domain Default (fixme?)')
            continue

        projects = dom.get_projects()
        for project in sorted(projects, key=(lambda x: x.name)):
            project.domain = dom
            yield project


def get_swift_stat_ensuring_permissions(project):
    "Get Swift v1 stat on a project (previously: tenant)"
    try:
        stat = project.get_swift().get_stat()
    except PermissionDenied:
        # We don't have permission to access the project? Upgrade the
        # permissions and try again.
        admin_role = cloud.get_role(name='admin')  # or 'reader'
        dom_admin_group = project.domain.get_admin_group()

        url = urljoin(
            cloud.base_url,
            ('/v3/projects/{project_id}/groups/{group_id}/'
             'roles/{role_id}').format(
                project_id=project.id, group_id=dom_admin_group.id,
                role_id=admin_role.id))
        out = requests.put(
            url, headers={'X-Auth-Token': str(cloud.get_system_token())})
        assert out.status_code == 201, (out.status_code, out.text)

        # Try again. Should succeed if the cloud admin user is in the
        # dom_admin_group.
        stat = project.get_swift().get_stat()

    return stat


# Take config from ~/.config/openstack/clouds.yaml and select
# 'my-cloud-admin', like the openstack(1) --os-cloud option.
config = CloudConfig('my-cloud-admin')
cloud = Cloud(config)
for project in get_projects(cloud):
    swift_stat = get_swift_stat_ensuring_permissions(project)
    print('{:15s} {:23s} {:21d} B ({} objects, {} containers)'.format(
        project.domain.name[0:15], project.name,
        int(swift_stat['X-Account-Bytes-Used']),
        swift_stat['X-Account-Object-Count'],
        swift_stat['X-Account-Container-Count']))

Example output

$ python3 example.py
domainx         project                  3489 B (2 objects, 1 containers)
domainx         otherproject       1455042022 B (267 objects, 1 containers)
...

Metadata

Release files for keystone-light 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keystone-light 0.1
File Size Uploaded Provenance Actions
keystone-light-0.1.tar.gz 8.2 kB Without provenance Details for keystone-light-0.1.tar.gz

Release files / keystone-light-0.1.tar.gz

Download URL keystone-light-0.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2d9cc5845e391063e7f7d2b89c6f95167dacf1a1772bcec023ca845caaf71ca9
BLAKE2b-256 checksum
How to use checksums
d68fd317670699bbdf598459f193c498cc966a955fc1d819182966d333417dac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/2.7.15+

Security for keystone-light 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page