Skip to main content

Python script for working with Okta APIs, esp OPA

Project description

Okta API Script

A Python package for calling Okta APIs using the requests module.

This package has the following scripts defined by the pyproject.toml file:

  • okta-server-enrollment-token: Generates a server enrollment token for a specified project within an Okta team. This token can be used to enroll servers into Okta for identity and access management.

Project Structure

okta/
├── src
│   └── main/python
│   |    └── okta_api_script/
│   |       ├── __init__.py
│   |       ├── main.py          # Main API logic
│   |       └── cli.py           # Command line interface
│   └── test/python
│       ├── test/python
│       ├── __init__.py
│       └── test_main.py         # Unit tests
├── pyproject.toml           # Project configuration
├── justfile                 # Build automation
└── README.md               # This file

Setup

  1. This project is meant to be developed using direnv for environment variable management. Ensure you have direnv installed and configured in your shell, or that you are using the provided devcontainer setup. You can also skip this step if you set those values previously or are using some other method to manage environment variables.

  2. Initialize the project:

    cp DOTENV .envrc
    # Modifiy .envrc with your environment variables
    direnv allow
    
    just init
    
  3. Install development dependencies:

    just dev-install
    
  4. Set your environment variables:

    export KEY_ID="your-key-id"
    export KEY_SECRET="your-key-secret"
    
  5. Run the script:

    just run          # Run as Python module
    just run-cli      # Run via CLI entry point
    

Script Overview

The main script (okta_api_script.main) orchestrates the Okta API workflow:

  1. Authenticates with Okta using service credentials to obtain a bearer token
  2. Retrieves resource groups for your team
  3. Fetches projects for each resource group
  4. Generates a server enrollment token for your target project

Usage

As a Python Module

just run

Programmatically

from okta_api_script.main import execute_api_cycle

execute_api_cycle(
    org_name="your-org",
    team_name="your-team",
    target_project="your-project",
    key_id="your-key-id",
    key_secret="your-key-secret",
    output_json=False
)

Script Parameters

The execute_api_cycle() function accepts the following parameters:

Parameter Type Required Description
org_name str | None No Okta organization name. If not provided, reads from OKTA_ORG environment variable
team_name str | None No Team name. If not provided, reads from OKTA_TEAM environment variable
target_project str | None No Target project name. If not provided, reads from OKTA_TARGET_PROJECT environment variable
key_id str | None No Okta API key ID. If not provided, reads from KEY_ID environment variable
key_secret str | None No Okta API key secret. If not provided, reads from KEY_SECRET environment variable
output_json bool No If True, outputs full response as formatted JSON. If False (default), outputs only the enrollment token

Environment Variables

The following environment variables are used by the script:

  • OKTA_ORG: Your Okta organization name (e.g., noaa)
  • OKTA_TEAM: Your team name (e.g., nos-coastal-modeling-cloud-sandbox)
  • OKTA_TARGET_PROJECT: Your target project name
  • KEY_ID: Your Okta API key ID
  • KEY_SECRET: Your Okta API key secret

All environment variables must be set for the script to run successfully. You can set them in:

  • Your shell environment
  • .envrc file (with direnv)
  • Command line arguments to the execute_api_cycle() function

Listing Available Just Targets

just --list

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

okta_opa-0.1.2.tar.gz (83.5 kB view details)

Uploaded Source

Built Distribution

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

okta_opa-0.1.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file okta_opa-0.1.2.tar.gz.

File metadata

  • Download URL: okta_opa-0.1.2.tar.gz
  • Upload date:
  • Size: 83.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for okta_opa-0.1.2.tar.gz
Algorithm Hash digest
SHA256 87489b6a0ff7f596c6b5fc0282e12afcc674b6bad81ead3d3211a13ee3656ab4
MD5 c794d378fceb8ac8551f6d02c59b585d
BLAKE2b-256 db995373a795d78dfda747cdec8295dc7ed2fb6462dddfc6dae213004898e2e4

See more details on using hashes here.

File details

Details for the file okta_opa-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: okta_opa-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for okta_opa-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c0ad1ee2156998436f8b4620cb9433d9cb2dbb8db821b64f14bd03f8441be84a
MD5 debeef26674d071b85692f8c4760e8e4
BLAKE2b-256 9d5690f9b5bde944d1c7fff7342c79bc7b92ff61ba7cd9211b13fc2bdfe60cfa

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