tcurl — T Cloud Public API Client¶
A CLI tool and Python module for making REST API calls to T Cloud Public endpoints.
Supports bearer token, AK/SK (SDK-HMAC-SHA256), and metadata server authentication.
It is more of a tool to use for creating integration scripts rather than outright application.
Requirements¶
Python 3.10+
requestslibraryOptional:
icecream(debug logging, falls back gracefully)Optional:
pyyaml(YAML output format)
Installation¶
# Core dependencies
pip install requests
# Optional:
pip install icecream pyyaml
# For interactive login (urwid-based TUI form):
pip install urwid
Or install via pip from source:
pip install .
This installs two console scripts:
Command |
Description |
|---|---|
|
Main CLI tool for API calls, credentials, etc. |
|
Interactive TUI login (username/password/OTP form) |
Usage¶
# As a standalone script
python tcurl.py [global-opts] <command> [command-opts]
# Or using the installed console scripts:
tcurl [global-opts] <command> [command-opts]
tcurl-login [options]
Global options¶
Option |
Description |
|---|---|
|
Show additional information |
|
Show version and exit |
Commands¶
Authentication¶
Command |
Description |
|---|---|
|
Issue a bearer token (password or unscoped token exchange) |
|
Revoke a previously issued token |
Credential retrieval¶
Command |
Description |
|---|---|
|
Retrieve temporary AK/SK from the metadata server |
|
Issue temporary AK/SK credentials from a bearer token |
REST API calls¶
Command |
Description |
|---|---|
|
Make a GET request |
|
Make a POST request (requires body) |
|
Make a PUT request (requires body) |
|
Make a PATCH request (requires body) |
|
Make a DELETE request |
|
Make a HEAD request |
|
Make an OPTIONS request |
Output formats¶
Every command except logout supports the --format / -f option:
Format |
Description |
|---|---|
|
Space-joined values (default) |
|
Pretty-printed JSON |
|
YAML output (requires |
|
Shell |
Authentication¶
Credentials are resolved in this order:
Command-line arguments
Metadata server (
http://169.254.169.254/openstack/latest/securitykey)Environment variables
Bearer token¶
# Environment
export OS_AUTH_TOKEN=...
python tcurl.py get https://...
# Command line
python tcurl.py get --token=eyJ... https://...
AK/SK (SDK-HMAC-SHA256)¶
# Environment
export OS_ACCESS_KEY=...
export OS_SECRET_KEY=...
export OS_SECURITY_TOKEN=... # optional, for temp credentials
# Command line
python tcurl.py get --ak=... --sk=... https://...
When doing AK/SK calls, you can scope the request with any of these mutually exclusive options:
Option |
Description |
|---|---|
|
Scope to a specific project ID |
|
Scope to a project by name |
|
Scope to a specific domain ID |
Metadata server¶
# Fetch credentials first
eval $(python tcurl.py metadata --format shell)
# Then use them
python tcurl.py get https://...
Alternatively, pass --metadata directly to any REST verb:
python tcurl.py get --metadata https://...
You can also use a custom metadata URL with --url:
# In two steps
python tcurl.py metadata --url=http://custom.metadata/securitykey --format shell
# Or inline with any REST verb
python tcurl.py get --url=http://custom.metadata/securitykey https://...
REST API call options¶
All REST verb commands (get, post, put, patch, delete, head, options)
accept these authentication options (mutually exclusive):
Option |
Description |
|---|---|
|
Bearer token (or env |
|
Access Key (or env |
|
Secret Key (or env |
|
Security token for temp credentials (or env |
|
Fetch credentials from the standard metadata endpoint |
|
Fetch credentials from a custom metadata URL |
And these general options:
Option |
Description |
|---|---|
|
Additional header in |
|
Output format: |
Login (issue a bearer token)¶
# Using username + password
python tcurl.py login --username=user@example.com --password=... --domain=OTC0000xxxx
# Interactive (prompts for missing credentials via stdin)
python tcurl.py login --interactive
# Interactive with urwid-based TUI form (requires urwid)
tcurl-login
# Interactive with Virtual MFA OTP
python tcurl.py login --interactive --totp=123456
# Exchange an unscoped token for a scoped one
python tcurl.py login --token=eyJ... --project=eu-de_project
# Scope to a region
python tcurl.py login --username=... --password=... --domain=... --region=eu-de
# Custom auth URL
python tcurl.py login --username=... --password=... --domain=... --auth-url=https://iam.eu-de.otc.t-systems.com
Options:
Option |
Description |
|---|---|
|
Username for password-based authentication |
|
Password (or env |
|
User domain name, e.g. |
|
Unscoped token to exchange for a scoped one |
|
Scope to a project name (derives region from prefix) |
|
Scope to a region (or env |
|
Custom auth URL (or env |
|
Prompt for credentials interactively |
|
Virtual MFA one-time passcode |
The login command outputs the token and expiry in the selected format
(--format json is recommended for inspection).
Logout (revoke a token)¶
# Revoke a specific token
python tcurl.py logout eyJ...
# Revoke the token from the environment and export shell commands
python tcurl.py logout --shell
The --shell flag (or --format shell) outputs export statements suitable
for eval, clearing the OS_AUTH_TOKEN variable after revocation.
Temporary AK/SK¶
# Issue temporary credentials valid for 15 minutes (default)
python tcurl.py aksk --token=eyJ...
# Custom duration (up to 24 hours = 86400 seconds)
python tcurl.py aksk --maxage=3600 --token=eyJ...
# Using environment variable for the token
export OS_AUTH_TOKEN=eyJ...
python tcurl.py aksk
# With a custom region or auth URL
python tcurl.py aksk --region=eu-de --maxage=7200
Options:
Option |
Description |
|---|---|
|
Bearer token (or env |
|
Max lifetime in seconds (default: 900 / 15 min) |
|
Region for auth URL (or env |
|
Custom auth URL (or env |
|
Output format: |
The issued AK/SK will have the same permissions as the original bearer token.
Project layout¶
Path |
Description |
|---|---|
|
CLI tool and importable module |
|
Interactive TUI login form (urwid-based) |
|
Package installer / distribution |
|
Test scripts and examples |
|
Sphinx documentation source |
|
Archived scripts (not part of the project) |
|
Developer notes |
Use as a Python module¶
tcurl.py and tcurl_login.py can be imported and used programmatically:
from tcurl import (
creds, add_headers, add_project_id, add_domain_id,
metadata_config, resolve_auth_url,
login, logout, temp_aksk,
OTCAkSkAuth, OBSAuth,
)
# Resolve the IAM endpoint for a region
auth_url = resolve_auth_url(region='eu-de')
# => 'https://iam.eu-de.otc.t-systems.com'
# Fetch credentials from metadata server
credential = metadata_config()
# => {'access': '...', 'secret': '...', 'securitytoken': '...', 'expires_at': '...'}
# Build request kwargs
kwargs = creds(token='eyJ...')
# => {'headers': {'X-Auth-Token': 'eyJ...'}}
# Or use AK/SK
kwargs = creds(ak='...', sk='...', securitytoken='...')
# => {'auth': OTCAkSkAuth(...)}
# Scope an AK/SK request to a project
add_project_id(kwargs, 'eu-de_12345')
add_domain_id(kwargs, 'OTC0000xxxx')
# Add custom headers
add_headers(kwargs, ['X-Request-Id:my-id'])
# Make the request
import requests
resp = requests.get('https://...', **kwargs)
# Issue a bearer token programmatically
token, details = login(
username='user@example.com',
password='...',
domain='OTC0000xxxx',
project='eu-de_project',
)
# token => 'eyJ...'
# details => full JSON response from IAM
# Issue temporary AK/SK from a token
creds = temp_aksk(token='eyJ...', max_secs=3600)
# => {'access': '...', 'secret': '...', 'securitytoken': '...', 'expires_at': '...'}
# Revoke a token
logout(token='eyJ...')
The tcurl_login module provides an interactive urwid-based form:
from tcurl_login import CredentialForm
form = CredentialForm()
result = form.run()
# => {'username': '...', 'password': '...', 'domain': '...', 'totp': '...'}
Notes¶
The
--projectshort flag (-p) in thelogincommand refers to a project name, not a project ID.When using
--projectinlogin, the region is automatically derived from the project name (the part before the first_).All REST verb commands accept
get,post,put,patch,delete,head, andoptionsboth in lowercase (e.g.get) and uppercase (e.g.GET).The tool supports reading arguments from a file using the
@prefix (e.g.python tcurl.py get @args.txt).Credential resolution order for REST verbs: command-line arguments → metadata server → environment variables.
The
--regionand--projectoptions onloginare mutually exclusive. When--projectis used, the region is derived from the project name prefix.The
--interactivemode reads from stdin when running in a TTY, or silently from stdin when piped (useful for automation scripts).The
tcurl-loginconsole script (urwid-based TUI) requiresurwid. It provides a dialog-style form with password masking and Tab navigation.