dremio-cli 1.8.1__tar.gz → 1.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dremio_cli-1.8.1/dremio_cli.egg-info → dremio_cli-1.10.0}/PKG-INFO +1 -1
- dremio_cli-1.10.0/docs/profiles.md +147 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/client/auth.py +90 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/client/base.py +81 -86
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/client/cloud.py +14 -1
- dremio_cli-1.10.0/dremio_cli/client/factory.py +170 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/client/software.py +14 -1
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/profile.py +9 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/config.py +10 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0/dremio_cli.egg-info}/PKG-INFO +1 -1
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/pyproject.toml +1 -1
- dremio_cli-1.8.1/docs/profiles.md +0 -139
- dremio_cli-1.8.1/dremio_cli/client/factory.py +0 -122
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/LICENSE +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/MANIFEST.in +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/README.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/completions/dremio-completion.bash +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/completions/dremio-completion.zsh +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/README.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/advanced-features.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/catalog.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/completion.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/dac.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/dac_governance.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/dac_reflections.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/dac_sources.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/dac_tables.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/dac_validations.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/favorites.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/grants.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/history.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/init.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/installation.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/jobs.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/lineage.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/monitor.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/quickstart.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/reflections.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/repl.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/roles.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/scripts.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/sources.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/spaces-folders.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/sql.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/tables.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/tags-wiki.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/tui.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/users.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/docs/views.md +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/__main__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/cli.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/client/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/catalog.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/completion.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/favorite.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/folder.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/grant.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/history.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/init.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/job.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/lineage.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/monitor.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/reflection.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/repl.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/role.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/script.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/source.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/space.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/sql.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/sync.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/table.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/tag.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/udf.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/ui.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/user.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/view.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/commands/wiki.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/dac/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/dac/config.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/dac/diff.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/dac/graph.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/dac/state.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/dac/sync.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/env.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/formatters/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/formatters/json.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/formatters/table.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/formatters/yaml.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/history.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/app.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/screens.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/widgets.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/utils/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/utils/console.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/utils/exceptions.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/utils/helpers.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli/utils/validators.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli.egg-info/SOURCES.txt +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli.egg-info/dependency_links.txt +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli.egg-info/entry_points.txt +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli.egg-info/requires.txt +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/dremio_cli.egg-info/top_level.txt +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/setup.cfg +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/setup.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/__init__.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/conftest.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_config.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_grant_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_history_favorite.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_integration.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_job_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_multi_sql_execution.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_reflection_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_role_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_script_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_source_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_space_folder_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_sql_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_table_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_tag_wiki_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_user_commands.py +0 -0
- {dremio_cli-1.8.1 → dremio_cli-1.10.0}/tests/test_view_commands.py +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Profile Management Guide
|
|
2
|
+
|
|
3
|
+
This guide covers how to create and manage Dremio CLI profiles using CLI commands, YAML configuration, or environment variables.
|
|
4
|
+
|
|
5
|
+
## 1. Quick Start: CLI Commands
|
|
6
|
+
|
|
7
|
+
The fastest way to set up profiles is using the `dremio profile create` command. Below are examples for every supported configuration.
|
|
8
|
+
|
|
9
|
+
### 1. Dremio Cloud (PAT)
|
|
10
|
+
*Requires Project ID from your URL (e.g., `app.dremio.cloud/projectId/<PROJECT_ID>/...`).*
|
|
11
|
+
*For Dremio Cloud, the CLI automatically attempts to exchange this PAT for a short-lived OAuth token for enhanced security.*
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
dremio profile create cloud-prod \
|
|
15
|
+
--type cloud \
|
|
16
|
+
--base-url https://api.dremio.cloud/v0 \
|
|
17
|
+
--project-id 788baab4-3c3b-42da-9f1d-5cc6dc03147d \
|
|
18
|
+
--auth-type pat \
|
|
19
|
+
--token "dtYQ629..."
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Dremio Cloud (Service User / Client Credentials)
|
|
23
|
+
|
|
24
|
+
For service accounts using Client ID and Secret (OAuth Client Credentials flow).
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
dremio profile create cloud-service \
|
|
28
|
+
--type cloud \
|
|
29
|
+
--base-url https://api.dremio.cloud \
|
|
30
|
+
--project-id <PROJECT_ID> \
|
|
31
|
+
--auth-type oauth \
|
|
32
|
+
--client-id <CLIENT_ID> \
|
|
33
|
+
--client-secret <CLIENT_SECRET>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 3. Dremio Software (PAT)
|
|
37
|
+
*Recommended for production scripts and service accounts.*
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
dremio profile create software-prod \
|
|
41
|
+
--type software \
|
|
42
|
+
--base-url https://dremio.company.com \
|
|
43
|
+
--auth-type pat \
|
|
44
|
+
--token "96fVB..."
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 4. Dremio Software (Username/Password)
|
|
48
|
+
|
|
49
|
+
Legacy authentication for Dremio Software.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
dremio profile create soft-auth \
|
|
53
|
+
--type software \
|
|
54
|
+
--base-url http://localhost:9047 \
|
|
55
|
+
--auth-type username_password \
|
|
56
|
+
--username <USERNAME> \
|
|
57
|
+
--password <PASSWORD>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> **Note on Service Users**: To use a Service User (Cloud or Software), simply generate a Personal Access Token (PAT) for that service account and use the **PAT** profile type shown above. The CLI does not currently support automated Client Credentials exchange.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 2. Comprehensive YAML Configuration
|
|
65
|
+
|
|
66
|
+
You can manage all your profiles in a single file: `~/.dremio/profiles.yaml`.
|
|
67
|
+
|
|
68
|
+
Below is a complete example configuration showing all supported profile types.
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
# ~/.dremio/profiles.yaml
|
|
72
|
+
profiles:
|
|
73
|
+
# 1. Dremio Cloud (Default)
|
|
74
|
+
cloud-prod:
|
|
75
|
+
type: cloud
|
|
76
|
+
base_url: https://api.dremio.cloud/v0
|
|
77
|
+
project_id: 788baab4-3c3b-42da-9f1d-5cc6dc03147d
|
|
78
|
+
auth:
|
|
79
|
+
type: pat
|
|
80
|
+
token: dtYQ629xQRukYE+cOExuAUr6VbWI/B+bu2c6hd6WM7c63XOXQS++3S4T6dJPfA==
|
|
81
|
+
|
|
82
|
+
# 2. Cloud Service Account (Recommended for Automation)
|
|
83
|
+
cloud-service-bot:
|
|
84
|
+
type: cloud
|
|
85
|
+
base_url: https://api.dremio.cloud
|
|
86
|
+
project_id: b5e7h8...
|
|
87
|
+
auth:
|
|
88
|
+
type: oauth
|
|
89
|
+
client_id: <CLIENT_ID>
|
|
90
|
+
client_secret: <CLIENT_SECRET>
|
|
91
|
+
|
|
92
|
+
# 3. Dremio Software (Legacy/Corporate)
|
|
93
|
+
software-prod:
|
|
94
|
+
type: software
|
|
95
|
+
base_url: https://dremio.corp.com
|
|
96
|
+
auth:
|
|
97
|
+
type: pat
|
|
98
|
+
token: 96fVBEuWREyqyVAJ9EWlRfxWR7UZx32YWpe/uZ86P5K3MjduYb8a3wp12jYIUA==
|
|
99
|
+
|
|
100
|
+
# 4. Dremio Software (Local Dev)
|
|
101
|
+
software-local:
|
|
102
|
+
type: software
|
|
103
|
+
base_url: http://localhost:9047
|
|
104
|
+
auth:
|
|
105
|
+
type: username_password
|
|
106
|
+
username: admin
|
|
107
|
+
password: password123
|
|
108
|
+
|
|
109
|
+
# Set the active profile
|
|
110
|
+
default_profile: cloud-prod
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Profile Fields Guide
|
|
114
|
+
|
|
115
|
+
| Field | Description |
|
|
116
|
+
|-------|-------------|
|
|
117
|
+
| `type` | `cloud` or `software`. |
|
|
118
|
+
| `base_url` | API Endpoint. <br>• Cloud (US): `https://api.dremio.cloud/v0`<br>• Cloud (EU): `https://api.dremio.eu/v0`<br>• Software: `https://<host>:<port>` |
|
|
119
|
+
| `project_id`| **Cloud Only**. Found in the Cloud Console URL. |
|
|
120
|
+
| `auth.type` | • `pat`: Personal Access Token<br>• `oauth`: Client Credentials Flow (Service User)<br>• `username_password`: Software Only. |
|
|
121
|
+
| `auth.token`| The token string (for `pat`). |
|
|
122
|
+
| `auth.client_id`| OAuth Client ID (for `oauth`). |
|
|
123
|
+
| `auth.client_secret`| OAuth Client Secret (for `oauth`). |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 3. Environment Variable Configuration
|
|
128
|
+
|
|
129
|
+
Ideal for CI/CD pipelines. Environment variables override the YAML file.
|
|
130
|
+
|
|
131
|
+
| variable | example |
|
|
132
|
+
|----------|---------|
|
|
133
|
+
| `DREMIO_PROFILE_{NAME}_TYPE` | `cloud` |
|
|
134
|
+
| `DREMIO_{NAME}_BASE_URL` | `https://api.dremio.cloud/v0` |
|
|
135
|
+
| `DREMIO_{NAME}_PROJECTID` | `788b...` |
|
|
136
|
+
| `DREMIO_{NAME}_AUTH_TYPE` | `pat` |
|
|
137
|
+
| `DREMIO_{NAME}_TOKEN` | `dtYQ...` |
|
|
138
|
+
|
|
139
|
+
### Example `.env`
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
DREMIO_CLOUD_TYPE=cloud
|
|
143
|
+
DREMIO_CLOUD_BASE_URL=https://api.dremio.cloud/v0
|
|
144
|
+
DREMIO_CLOUD_PROJECTID=788baab4-3c3b-42da-9f1d-5cc6dc03147d
|
|
145
|
+
DREMIO_CLOUD_AUTH_TYPE=pat
|
|
146
|
+
DREMIO_CLOUD_TOKEN=dtYQ629...
|
|
147
|
+
```
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from typing import Dict, Any, Optional
|
|
4
4
|
import requests
|
|
5
|
+
from requests.auth import HTTPBasicAuth
|
|
5
6
|
|
|
6
7
|
from dremio_cli.utils.exceptions import AuthenticationError
|
|
7
8
|
|
|
@@ -56,6 +57,95 @@ def authenticate_with_username_password(
|
|
|
56
57
|
raise AuthenticationError(f"Authentication request failed: {e}")
|
|
57
58
|
|
|
58
59
|
|
|
60
|
+
def exchange_pat_for_oauth(
|
|
61
|
+
base_url: str,
|
|
62
|
+
pat: str,
|
|
63
|
+
) -> Dict[str, Any]:
|
|
64
|
+
"""Exchange PAT for OAuth token.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
base_url: Base URL for Dremio
|
|
68
|
+
pat: Personal Access Token
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Dictionary with access_token (and optionally refresh_token)
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
AuthenticationError: If exchange fails
|
|
75
|
+
"""
|
|
76
|
+
oauth_url = f"{base_url}/oauth/token"
|
|
77
|
+
|
|
78
|
+
# Standard RFC 8693 Token Exchange params for Dremio
|
|
79
|
+
data = {
|
|
80
|
+
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
81
|
+
"subject_token": pat,
|
|
82
|
+
"subject_token_type": "urn:ietf:params:oauth:token-type:access_token"
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try:
|
|
86
|
+
response = requests.post(
|
|
87
|
+
oauth_url,
|
|
88
|
+
json=data,
|
|
89
|
+
headers={"Content-Type": "application/json"},
|
|
90
|
+
timeout=30,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
if not response.ok:
|
|
94
|
+
raise AuthenticationError(f"PAT exchange failed: {response.text}")
|
|
95
|
+
|
|
96
|
+
return response.json()
|
|
97
|
+
|
|
98
|
+
except requests.RequestException as e:
|
|
99
|
+
raise AuthenticationError(f"PAT exchange request failed: {e}")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def authenticate_client_credentials(
|
|
103
|
+
base_url: str,
|
|
104
|
+
client_id: str,
|
|
105
|
+
client_secret: str,
|
|
106
|
+
) -> Dict[str, Any]:
|
|
107
|
+
"""Authenticate using OAuth Client Credentials.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
base_url: Base URL for Dremio
|
|
111
|
+
client_id: Client ID
|
|
112
|
+
client_secret: Client Secret
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Dictionary with access_token
|
|
116
|
+
|
|
117
|
+
Raises:
|
|
118
|
+
AuthenticationError: If authentication fails
|
|
119
|
+
"""
|
|
120
|
+
oauth_url = f"{base_url}/oauth/token"
|
|
121
|
+
|
|
122
|
+
data = {
|
|
123
|
+
"grant_type": "client_credentials"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
# Client credentials usually sent via Basic Auth header or body
|
|
128
|
+
# Dremio often accepts them in body or basic auth. Using Basic Auth is safer standard.
|
|
129
|
+
response = requests.post(
|
|
130
|
+
oauth_url,
|
|
131
|
+
data=data, # form-encoded for standard OAuth, but Dremio might expect JSON
|
|
132
|
+
# Dremio docs usually imply JSON body for other endpoints, but let's check.
|
|
133
|
+
# Actually standard Dremio /oauth/token often takes JSON.
|
|
134
|
+
# Let's try JSON body first as it matches other methods here.
|
|
135
|
+
json=data | {"client_id": client_id, "client_secret": client_secret},
|
|
136
|
+
headers={"Content-Type": "application/json"},
|
|
137
|
+
timeout=30,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
if not response.ok:
|
|
141
|
+
raise AuthenticationError(f"Client credentials auth failed: {response.text}")
|
|
142
|
+
|
|
143
|
+
return response.json()
|
|
144
|
+
|
|
145
|
+
except requests.RequestException as e:
|
|
146
|
+
raise AuthenticationError(f"Client credentials request failed: {e}")
|
|
147
|
+
|
|
148
|
+
|
|
59
149
|
def refresh_oauth_token(
|
|
60
150
|
base_url: str,
|
|
61
151
|
refresh_token: str,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"""Base HTTP client for Dremio API."""
|
|
2
2
|
|
|
3
|
-
from typing import Any, Dict, Optional
|
|
3
|
+
from typing import Any, Dict, Optional, Callable
|
|
4
4
|
from urllib.parse import urljoin
|
|
5
|
+
import time
|
|
5
6
|
|
|
6
7
|
import requests
|
|
7
8
|
from requests.adapters import HTTPAdapter
|
|
8
9
|
from urllib3.util.retry import Retry
|
|
9
10
|
|
|
10
11
|
from dremio_cli.utils.exceptions import ApiError, AuthenticationError
|
|
12
|
+
from dremio_cli.client.auth import refresh_oauth_token
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
class BaseClient:
|
|
@@ -19,17 +21,26 @@ class BaseClient:
|
|
|
19
21
|
token: Optional[str] = None,
|
|
20
22
|
timeout: int = 30,
|
|
21
23
|
max_retries: int = 3,
|
|
24
|
+
refresh_token: Optional[str] = None,
|
|
25
|
+
client_id: Optional[str] = None,
|
|
26
|
+
client_secret: Optional[str] = None,
|
|
22
27
|
):
|
|
23
28
|
"""Initialize base client.
|
|
24
29
|
|
|
25
30
|
Args:
|
|
26
31
|
base_url: Base URL for API
|
|
27
|
-
token: Authentication token
|
|
32
|
+
token: Authentication token (Access Token)
|
|
28
33
|
timeout: Request timeout in seconds
|
|
29
34
|
max_retries: Maximum number of retries
|
|
35
|
+
refresh_token: OAuth Refresh Token
|
|
36
|
+
client_id: OAuth Client ID (for refresh)
|
|
37
|
+
client_secret: OAuth Client Secret (for refresh)
|
|
30
38
|
"""
|
|
31
39
|
self.base_url = base_url.rstrip("/")
|
|
32
40
|
self.token = token
|
|
41
|
+
self.refresh_token = refresh_token
|
|
42
|
+
self.client_id = client_id
|
|
43
|
+
self.client_secret = client_secret
|
|
33
44
|
self.timeout = timeout
|
|
34
45
|
|
|
35
46
|
# Create session with retry logic
|
|
@@ -71,6 +82,68 @@ class BaseClient:
|
|
|
71
82
|
"""
|
|
72
83
|
return urljoin(self.base_url + "/", endpoint.lstrip("/"))
|
|
73
84
|
|
|
85
|
+
def _refresh_token(self) -> bool:
|
|
86
|
+
"""Attempt to refresh auth token.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
True if refresh successful, False otherwise
|
|
90
|
+
"""
|
|
91
|
+
if not self.refresh_token:
|
|
92
|
+
return False
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
# Determine base URL for auth (could be different if v0/v3 messiness, but auth.py handles logic usually)
|
|
96
|
+
# auth.refresh_oauth_token expects base_url used for API usually
|
|
97
|
+
new_tokens = refresh_oauth_token(
|
|
98
|
+
self.base_url,
|
|
99
|
+
self.refresh_token,
|
|
100
|
+
self.client_id,
|
|
101
|
+
self.client_secret
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.token = new_tokens.get("access_token")
|
|
105
|
+
# Update refresh token if provided (rolling refresh)
|
|
106
|
+
if "refresh_token" in new_tokens:
|
|
107
|
+
self.refresh_token = new_tokens["refresh_token"]
|
|
108
|
+
|
|
109
|
+
return True
|
|
110
|
+
except Exception:
|
|
111
|
+
# If refresh fails, we can't recover
|
|
112
|
+
return False
|
|
113
|
+
|
|
114
|
+
def _request(self, method: str, endpoint: str, **kwargs) -> Any:
|
|
115
|
+
"""Internal request wrapper with 401 retry logic.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
method: HTTP method
|
|
119
|
+
endpoint: API endpoint
|
|
120
|
+
**kwargs: Arguments for requests.session.request
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Response data
|
|
124
|
+
"""
|
|
125
|
+
url = self._build_url(endpoint)
|
|
126
|
+
kwargs.setdefault("timeout", self.timeout)
|
|
127
|
+
|
|
128
|
+
# First attempt
|
|
129
|
+
kwargs["headers"] = self._get_headers()
|
|
130
|
+
try:
|
|
131
|
+
response = self.session.request(method, url, **kwargs)
|
|
132
|
+
except requests.RequestException as e:
|
|
133
|
+
raise ApiError(f"Request failed: {e}")
|
|
134
|
+
|
|
135
|
+
# Check for 401 and attempt refresh
|
|
136
|
+
if response.status_code == 401 and self.refresh_token:
|
|
137
|
+
if self._refresh_token():
|
|
138
|
+
# Retry with new token
|
|
139
|
+
kwargs["headers"] = self._get_headers()
|
|
140
|
+
try:
|
|
141
|
+
response = self.session.request(method, url, **kwargs)
|
|
142
|
+
except requests.RequestException as e:
|
|
143
|
+
raise ApiError(f"Retry request failed: {e}")
|
|
144
|
+
|
|
145
|
+
return self._handle_response(response)
|
|
146
|
+
|
|
74
147
|
def _handle_response(self, response: requests.Response) -> Any:
|
|
75
148
|
"""Handle API response.
|
|
76
149
|
|
|
@@ -85,7 +158,7 @@ class BaseClient:
|
|
|
85
158
|
ApiError: If API request fails
|
|
86
159
|
"""
|
|
87
160
|
if response.status_code == 401:
|
|
88
|
-
raise AuthenticationError("Authentication failed.
|
|
161
|
+
raise AuthenticationError("Authentication failed. Token expired or invalid.")
|
|
89
162
|
|
|
90
163
|
if response.status_code == 403:
|
|
91
164
|
raise ApiError("Access forbidden. Check your permissions.", status_code=403)
|
|
@@ -116,94 +189,16 @@ class BaseClient:
|
|
|
116
189
|
return response.text
|
|
117
190
|
|
|
118
191
|
def get(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Any:
|
|
119
|
-
""
|
|
120
|
-
|
|
121
|
-
Args:
|
|
122
|
-
endpoint: API endpoint
|
|
123
|
-
params: Query parameters
|
|
124
|
-
|
|
125
|
-
Returns:
|
|
126
|
-
Response data
|
|
127
|
-
"""
|
|
128
|
-
url = self._build_url(endpoint)
|
|
129
|
-
response = self.session.get(
|
|
130
|
-
url,
|
|
131
|
-
headers=self._get_headers(),
|
|
132
|
-
params=params,
|
|
133
|
-
timeout=self.timeout,
|
|
134
|
-
)
|
|
135
|
-
return self._handle_response(response)
|
|
192
|
+
return self._request("GET", endpoint, params=params)
|
|
136
193
|
|
|
137
194
|
def post(self, endpoint: str, data: Optional[Dict[str, Any]] = None) -> Any:
|
|
138
|
-
""
|
|
139
|
-
|
|
140
|
-
Args:
|
|
141
|
-
endpoint: API endpoint
|
|
142
|
-
data: Request body data
|
|
143
|
-
|
|
144
|
-
Returns:
|
|
145
|
-
Response data
|
|
146
|
-
"""
|
|
147
|
-
url = self._build_url(endpoint)
|
|
148
|
-
response = self.session.post(
|
|
149
|
-
url,
|
|
150
|
-
headers=self._get_headers(),
|
|
151
|
-
json=data,
|
|
152
|
-
timeout=self.timeout,
|
|
153
|
-
)
|
|
154
|
-
return self._handle_response(response)
|
|
195
|
+
return self._request("POST", endpoint, json=data)
|
|
155
196
|
|
|
156
197
|
def put(self, endpoint: str, data: Optional[Dict[str, Any]] = None) -> Any:
|
|
157
|
-
""
|
|
158
|
-
|
|
159
|
-
Args:
|
|
160
|
-
endpoint: API endpoint
|
|
161
|
-
data: Request body data
|
|
162
|
-
|
|
163
|
-
Returns:
|
|
164
|
-
Response data
|
|
165
|
-
"""
|
|
166
|
-
url = self._build_url(endpoint)
|
|
167
|
-
response = self.session.put(
|
|
168
|
-
url,
|
|
169
|
-
headers=self._get_headers(),
|
|
170
|
-
json=data,
|
|
171
|
-
timeout=self.timeout,
|
|
172
|
-
)
|
|
173
|
-
return self._handle_response(response)
|
|
198
|
+
return self._request("PUT", endpoint, json=data)
|
|
174
199
|
|
|
175
200
|
def delete(self, endpoint: str) -> Any:
|
|
176
|
-
""
|
|
177
|
-
|
|
178
|
-
Args:
|
|
179
|
-
endpoint: API endpoint
|
|
180
|
-
|
|
181
|
-
Returns:
|
|
182
|
-
Response data
|
|
183
|
-
"""
|
|
184
|
-
url = self._build_url(endpoint)
|
|
185
|
-
response = self.session.delete(
|
|
186
|
-
url,
|
|
187
|
-
headers=self._get_headers(),
|
|
188
|
-
timeout=self.timeout,
|
|
189
|
-
)
|
|
190
|
-
return self._handle_response(response)
|
|
201
|
+
return self._request("DELETE", endpoint)
|
|
191
202
|
|
|
192
203
|
def patch(self, endpoint: str, data: Optional[Dict[str, Any]] = None) -> Any:
|
|
193
|
-
""
|
|
194
|
-
|
|
195
|
-
Args:
|
|
196
|
-
endpoint: API endpoint
|
|
197
|
-
data: Request body data
|
|
198
|
-
|
|
199
|
-
Returns:
|
|
200
|
-
Response data
|
|
201
|
-
"""
|
|
202
|
-
url = self._build_url(endpoint)
|
|
203
|
-
response = self.session.patch(
|
|
204
|
-
url,
|
|
205
|
-
headers=self._get_headers(),
|
|
206
|
-
json=data,
|
|
207
|
-
timeout=self.timeout,
|
|
208
|
-
)
|
|
209
|
-
return self._handle_response(response)
|
|
204
|
+
return self._request("PATCH", endpoint, json=data)
|
|
@@ -14,6 +14,9 @@ class CloudClient(BaseClient):
|
|
|
14
14
|
project_id: str,
|
|
15
15
|
token: str,
|
|
16
16
|
timeout: int = 30,
|
|
17
|
+
refresh_token: Optional[str] = None,
|
|
18
|
+
client_id: Optional[str] = None,
|
|
19
|
+
client_secret: Optional[str] = None,
|
|
17
20
|
):
|
|
18
21
|
"""Initialize Cloud client.
|
|
19
22
|
|
|
@@ -22,8 +25,18 @@ class CloudClient(BaseClient):
|
|
|
22
25
|
project_id: Project ID
|
|
23
26
|
token: Authentication token
|
|
24
27
|
timeout: Request timeout in seconds
|
|
28
|
+
refresh_token: OAuth Refresh Token
|
|
29
|
+
client_id: OAuth Client ID
|
|
30
|
+
client_secret: OAuth Client Secret
|
|
25
31
|
"""
|
|
26
|
-
super().__init__(
|
|
32
|
+
super().__init__(
|
|
33
|
+
base_url=base_url,
|
|
34
|
+
token=token,
|
|
35
|
+
timeout=timeout,
|
|
36
|
+
refresh_token=refresh_token,
|
|
37
|
+
client_id=client_id,
|
|
38
|
+
client_secret=client_secret,
|
|
39
|
+
)
|
|
27
40
|
self.project_id = project_id
|
|
28
41
|
|
|
29
42
|
def _project_endpoint(self, endpoint: str) -> str:
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Client factory for creating appropriate Dremio clients."""
|
|
2
|
+
|
|
3
|
+
from typing import Dict, Any, Union
|
|
4
|
+
|
|
5
|
+
from dremio_cli.client.cloud import CloudClient
|
|
6
|
+
from dremio_cli.client.software import SoftwareClient
|
|
7
|
+
from dremio_cli.client.auth import (
|
|
8
|
+
authenticate_with_username_password,
|
|
9
|
+
exchange_pat_for_oauth,
|
|
10
|
+
authenticate_client_credentials
|
|
11
|
+
)
|
|
12
|
+
from dremio_cli.utils.exceptions import ConfigurationError, AuthenticationError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def create_client(profile: Dict[str, Any]) -> Union[CloudClient, SoftwareClient]:
|
|
16
|
+
"""Create appropriate Dremio client from profile.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
profile: Profile configuration dictionary
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
CloudClient or SoftwareClient instance
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
ConfigurationError: If profile is invalid
|
|
26
|
+
AuthenticationError: If authentication fails
|
|
27
|
+
"""
|
|
28
|
+
profile_type = profile.get("type")
|
|
29
|
+
|
|
30
|
+
if not profile_type:
|
|
31
|
+
raise ConfigurationError("Profile missing 'type' field")
|
|
32
|
+
|
|
33
|
+
if profile_type not in ["cloud", "software"]:
|
|
34
|
+
raise ConfigurationError(f"Invalid profile type: {profile_type}")
|
|
35
|
+
|
|
36
|
+
base_url = profile.get("base_url")
|
|
37
|
+
if not base_url:
|
|
38
|
+
raise ConfigurationError("Profile missing 'base_url' field")
|
|
39
|
+
|
|
40
|
+
auth = profile.get("auth", {})
|
|
41
|
+
auth_type = auth.get("type")
|
|
42
|
+
|
|
43
|
+
if not auth_type:
|
|
44
|
+
raise ConfigurationError("Profile missing 'auth.type' field")
|
|
45
|
+
|
|
46
|
+
# Get auth details (token, refresh_token, etc.)
|
|
47
|
+
auth_details = _get_auth_details(profile, auth, base_url)
|
|
48
|
+
|
|
49
|
+
# Create appropriate client
|
|
50
|
+
if profile_type == "cloud":
|
|
51
|
+
project_id = profile.get("project_id")
|
|
52
|
+
if not project_id:
|
|
53
|
+
raise ConfigurationError("Cloud profile missing 'project_id' field")
|
|
54
|
+
|
|
55
|
+
return CloudClient(
|
|
56
|
+
base_url=base_url,
|
|
57
|
+
project_id=project_id,
|
|
58
|
+
token=auth_details["token"],
|
|
59
|
+
refresh_token=auth_details.get("refresh_token"),
|
|
60
|
+
client_id=auth_details.get("client_id"),
|
|
61
|
+
client_secret=auth_details.get("client_secret"),
|
|
62
|
+
)
|
|
63
|
+
else: # software
|
|
64
|
+
return SoftwareClient(
|
|
65
|
+
base_url=base_url,
|
|
66
|
+
token=auth_details["token"],
|
|
67
|
+
refresh_token=auth_details.get("refresh_token"),
|
|
68
|
+
client_id=auth_details.get("client_id"),
|
|
69
|
+
client_secret=auth_details.get("client_secret"),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _get_auth_details(profile: Dict[str, Any], auth: Dict[str, Any], base_url: str) -> Dict[str, Any]:
|
|
74
|
+
"""Get authentication details from profile or generate them.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
profile: Profile configuration
|
|
78
|
+
auth: Auth configuration
|
|
79
|
+
base_url: Base URL for API
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Dictionary containing 'token' and optionally 'refresh_token', 'client_id', 'client_secret'
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
AuthenticationError: If authentication fails
|
|
86
|
+
ConfigurationError: If auth configuration is invalid
|
|
87
|
+
"""
|
|
88
|
+
auth_type = auth.get("type")
|
|
89
|
+
profile_type = profile.get("type")
|
|
90
|
+
|
|
91
|
+
if auth_type == "pat":
|
|
92
|
+
pat = auth.get("token")
|
|
93
|
+
if not pat:
|
|
94
|
+
raise ConfigurationError("PAT auth requires 'token' field")
|
|
95
|
+
|
|
96
|
+
# For Dremio Cloud, try to exchange PAT for OAuth token
|
|
97
|
+
if profile_type == "cloud":
|
|
98
|
+
try:
|
|
99
|
+
# Exchange PAT for short-lived access token
|
|
100
|
+
token_data = exchange_pat_for_oauth(base_url, pat)
|
|
101
|
+
return {
|
|
102
|
+
"token": token_data["access_token"],
|
|
103
|
+
"refresh_token": token_data.get("refresh_token") or pat, # Use PAT as refresh token if none returned? No, if none returned, likely can't refresh.
|
|
104
|
+
# Actually, standard behavior: PAT can act as refresh token in some flows, or we just rely on PAT.
|
|
105
|
+
# But if exchange worked, we get an access token.
|
|
106
|
+
# If we don't get a refresh token, we can't refresh.
|
|
107
|
+
# If we store PAT as 'refresh_token' maybe we can re-exchange?
|
|
108
|
+
# BaseClient expects standard refresh flow.
|
|
109
|
+
# Let's return just access token. If it expires, we're stuck unless we re-exchange.
|
|
110
|
+
# Better strategy: Not relying on BaseClient refresh for PAT exchange yet unless we implement re-exchange logic in BaseClient using PAT.
|
|
111
|
+
# BUT BaseClient uses refresh_oauth_token which takes a Refresh Token.
|
|
112
|
+
# If Dremio returns a refresh token on PAT exchange, great. If not, we just use access token.
|
|
113
|
+
# Fallback: Just return token and PAT as refresh token? No, exchange endpoint expects refresh token grant type.
|
|
114
|
+
# Let's keep it simple: Use returned access token.
|
|
115
|
+
} | ({"refresh_token": token_data["refresh_token"]} if "refresh_token" in token_data else {})
|
|
116
|
+
except Exception:
|
|
117
|
+
# If exchange fails (or not supported), fall back to using PAT gracefully
|
|
118
|
+
return {"token": pat}
|
|
119
|
+
|
|
120
|
+
return {"token": pat}
|
|
121
|
+
|
|
122
|
+
elif auth_type == "oauth": # Client Credentials
|
|
123
|
+
client_id = auth.get("client_id")
|
|
124
|
+
client_secret = auth.get("client_secret")
|
|
125
|
+
|
|
126
|
+
# If token provided manually in profile (e.g. cached), use it?
|
|
127
|
+
# For now, let's assume we authenticate fresh or leverage client_id/secret
|
|
128
|
+
|
|
129
|
+
if not client_id or not client_secret:
|
|
130
|
+
# Check if we have a raw token
|
|
131
|
+
token = auth.get("token")
|
|
132
|
+
if token:
|
|
133
|
+
return {"token": token}
|
|
134
|
+
raise ConfigurationError("OAuth auth requires 'client_id' and 'client_secret'")
|
|
135
|
+
|
|
136
|
+
token_data = authenticate_client_credentials(base_url, client_id, client_secret)
|
|
137
|
+
return {
|
|
138
|
+
"token": token_data["access_token"],
|
|
139
|
+
"refresh_token": token_data.get("refresh_token"),
|
|
140
|
+
"client_id": client_id,
|
|
141
|
+
"client_secret": client_secret,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
elif auth_type == "username_password":
|
|
145
|
+
# Check if we have a cached token
|
|
146
|
+
cached_token = auth.get("token")
|
|
147
|
+
if cached_token:
|
|
148
|
+
# TODO: Check if token is expired
|
|
149
|
+
return {"token": cached_token}
|
|
150
|
+
|
|
151
|
+
# Generate new token
|
|
152
|
+
username = auth.get("username")
|
|
153
|
+
password = auth.get("password")
|
|
154
|
+
|
|
155
|
+
if not username or not password:
|
|
156
|
+
raise ConfigurationError(
|
|
157
|
+
"Username/password auth requires 'username' and 'password' fields"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# Only supported for Software
|
|
161
|
+
if profile.get("type") != "software":
|
|
162
|
+
raise ConfigurationError(
|
|
163
|
+
"Username/password auth only supported for Dremio Software"
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
token = authenticate_with_username_password(base_url, username, password)
|
|
167
|
+
return {"token": token}
|
|
168
|
+
|
|
169
|
+
else:
|
|
170
|
+
raise ConfigurationError(f"Unsupported auth type: {auth_type}")
|