-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaults.py
More file actions
124 lines (90 loc) · 5.12 KB
/
Copy pathdefaults.py
File metadata and controls
124 lines (90 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import logging
import os
from os.path import join as path_join, expanduser, abspath, dirname
import click_log
logger = logging.getLogger(__name__)
click_log.basic_config(logger)
TEMPLATE_EXTS = {
"python": "py",
"html": "html",
"ruby": "rb",
"node": "js",
"php": "php",
"java": "java",
}
CLOUDINARY_HOME = os.environ.get('CLOUDINARY_HOME')
if CLOUDINARY_HOME is None:
CLOUDINARY_HOME = abspath(path_join(expanduser("~"), ".cloudinary-cli"))
CLOUDINARY_CLI_CONFIG_FILE = abspath(path_join(CLOUDINARY_HOME, 'config.json'))
# Reserved key inside config.json that names the default saved configuration. Double-underscore
# names are rejected as user config names, so this can't collide with a saved config.
DEFAULT_CONFIG_KEY = "__default__"
# Query param carried inside a saved cloudinary:// URL recording the email the account was created
# for (via `cld agent signup`). Stripped before display and before reaching the SDK.
ACCOUNT_EMAIL_PARAM = "account_email"
# Guidance shown when no configuration is available (the group callback for account-consuming
# commands, and the empty `config -ls`). Printed verbatim to stderr, without the logger's
# "warning:" prefix, so the copy-pasteable command lines stay clean.
NO_CONFIG_MESSAGE = (
"No Cloudinary configuration found.\n"
" - Log in with OAuth: cld login\n"
" - Add an API-key config: cld config -n <name> cloudinary://<api_key>:<api_secret>@<cloud_name> --set-default\n"
" - Set an existing config as the default: cld config -d <name>\n"
" - AI agents - provision an environment to be claimed by a human: cld agent signup <email> <framework> <model> <goal>"
)
# Shown when saved configs exist but none is active (no default set, no environment config, and no
# -c/-C on the command line). The account is there; the CLI just doesn't know which one to use.
NO_DEFAULT_CONFIG_MESSAGE = (
"No default Cloudinary configuration is set. Select one per command with `-C <name>`, "
"or set a default with `cld config -d <name>`.\n"
"List your saved configurations with `cld config -ls`."
)
# Shown when an explicitly selected config (-c URL or -C saved name) has a cloud name but no
# credentials (api_key/api_secret or an OAuth token). The user picked a config on purpose, so the
# generic "no config found" guidance would be misleading; the config is just incomplete.
INCOMPLETE_CONFIG_MESSAGE = (
"The selected configuration is incomplete: it has a cloud name but no credentials "
"(api_key/api_secret or an OAuth token). Operations that need authentication will fail."
)
# OAuth configuration for `cld login`. The region string derives both the API and
# OAuth hosts; an unknown region simply fails to resolve.
DEFAULT_REGION = 'api'
def normalize_region(region):
# Bare geo codes ('eu') become 'api-<geo>'; 'api' and 'api-*' pass through.
region = (region or DEFAULT_REGION).strip()
return region if region.startswith('api') else f'api-{region}'
def _oauth_host_for(region):
# Short suffixes (geo codes) use the central authz server; longer ones route to oauth-<suffix>.
_, _, suffix = region.partition('-')
return 'oauth.cloudinary.com' if len(suffix) <= 2 else f'oauth-{suffix}.cloudinary.com'
def api_host_for_region(region):
return f'https://{normalize_region(region)}.cloudinary.com'
def oauth_base_url_for_region(region):
return f'https://{_oauth_host_for(normalize_region(region))}'
def oauth_authorize_url_for_region(region):
return f'{oauth_base_url_for_region(region)}/oauth2/auth'
def oauth_token_url_for_region(region):
return f'{oauth_base_url_for_region(region)}/oauth2/token'
def oauth_revoke_url_for_region(region):
return f'{oauth_base_url_for_region(region)}/oauth2/revoke'
CLOUDINARY_REGION = normalize_region(os.environ.get('CLOUDINARY_REGION'))
# Public PKCE client (no secret). Overridable for testing against a non-prod authorization server
# registered with a different client; production uses the single registered client below.
OAUTH_DEFAULT_CLIENT_ID = 'a920ea9c-531b-4613-9783-1d4f4cc10655'
OAUTH_CLIENT_ID = os.environ.get('CLOUDINARY_OAUTH_CLIENT_ID', OAUTH_DEFAULT_CLIENT_ID)
OAUTH_DEFAULT_SCOPES = 'openid offline_access asset_management upload'
OAUTH_SCOPES = os.environ.get('CLOUDINARY_OAUTH_SCOPES', OAUTH_DEFAULT_SCOPES)
# The authorization server requires an exact redirect match, so the port is fixed and must match the registered client.
OAUTH_DEFAULT_REDIRECT_HOST = '127.0.0.1'
OAUTH_REDIRECT_HOST = os.environ.get('CLOUDINARY_OAUTH_REDIRECT_HOST', OAUTH_DEFAULT_REDIRECT_HOST)
OAUTH_DEFAULT_REDIRECT_PORT = 49421
OAUTH_REDIRECT_PORT = int(os.environ.get('CLOUDINARY_OAUTH_REDIRECT_PORT', OAUTH_DEFAULT_REDIRECT_PORT))
OAUTH_CALLBACK_PATH = '/callback'
OAUTH_CALLBACK_TIMEOUT_SECONDS = 300
OAUTH_EXPIRY_SKEW_SECONDS = 30
OAUTH_HTTP_TIMEOUT_SECONDS = 30
TEMPLATE_FOLDER_NAME = 'templates'
CLOUDINARY_CLI_ROOT = dirname(__file__)
TEMPLATE_FOLDER = path_join(CLOUDINARY_CLI_ROOT, TEMPLATE_FOLDER_NAME)
CUSTOM_TEMPLATE_FOLDER = path_join(abspath(CLOUDINARY_HOME), TEMPLATE_FOLDER_NAME)
OLD_CLOUDINARY_CLI_CONFIG_FILE = path_join(expanduser("~"), '.cloudinary-cli-config')