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
-
This project is meant to be developed using
direnvfor environment variable management. Ensure you havedirenvinstalled 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. -
Initialize the project:
cp DOTENV .envrc # Modifiy .envrc with your environment variables direnv allow
just init -
Install development dependencies:
just dev-install -
Set your environment variables:
export KEY_ID="your-key-id" export KEY_SECRET="your-key-secret"
-
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:
- Authenticates with Okta using service credentials to obtain a bearer token
- Retrieves resource groups for your team
- Fetches projects for each resource group
- 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 nameKEY_ID: Your Okta API key IDKEY_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
.envrcfile (withdirenv)- Command line arguments to the
execute_api_cycle()function
Listing Available Just Targets
just --list
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87489b6a0ff7f596c6b5fc0282e12afcc674b6bad81ead3d3211a13ee3656ab4
|
|
| MD5 |
c794d378fceb8ac8551f6d02c59b585d
|
|
| BLAKE2b-256 |
db995373a795d78dfda747cdec8295dc7ed2fb6462dddfc6dae213004898e2e4
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ad1ee2156998436f8b4620cb9433d9cb2dbb8db821b64f14bd03f8441be84a
|
|
| MD5 |
debeef26674d071b85692f8c4760e8e4
|
|
| BLAKE2b-256 |
9d5690f9b5bde944d1c7fff7342c79bc7b92ff61ba7cd9211b13fc2bdfe60cfa
|