dremio-cli 1.9.0__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.
Files changed (128) hide show
  1. {dremio_cli-1.9.0/dremio_cli.egg-info → dremio_cli-1.10.0}/PKG-INFO +1 -1
  2. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/README.md +3 -2
  3. dremio_cli-1.10.0/docs/profiles.md +147 -0
  4. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/quickstart.md +5 -6
  5. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/client/auth.py +86 -43
  6. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/client/base.py +81 -86
  7. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/client/cloud.py +14 -1
  8. dremio_cli-1.10.0/dremio_cli/client/factory.py +170 -0
  9. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/client/software.py +14 -1
  10. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/profile.py +16 -15
  11. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/table.py +0 -90
  12. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/user.py +11 -20
  13. dremio_cli-1.10.0/dremio_cli/config.py +203 -0
  14. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/utils/validators.py +1 -1
  15. {dremio_cli-1.9.0 → dremio_cli-1.10.0/dremio_cli.egg-info}/PKG-INFO +1 -1
  16. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli.egg-info/SOURCES.txt +0 -2
  17. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/pyproject.toml +1 -1
  18. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_config.py +0 -8
  19. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_integration.py +6 -4
  20. dremio_cli-1.9.0/docs/profiles.md +0 -140
  21. dremio_cli-1.9.0/docs/service_users.md +0 -39
  22. dremio_cli-1.9.0/dremio_cli/client/factory.py +0 -135
  23. dremio_cli-1.9.0/dremio_cli/config.py +0 -435
  24. dremio_cli-1.9.0/tests/test_service_users.py +0 -62
  25. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/LICENSE +0 -0
  26. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/MANIFEST.in +0 -0
  27. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/README.md +0 -0
  28. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/completions/dremio-completion.bash +0 -0
  29. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/completions/dremio-completion.zsh +0 -0
  30. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/advanced-features.md +0 -0
  31. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/catalog.md +0 -0
  32. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/completion.md +0 -0
  33. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/dac.md +0 -0
  34. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/dac_governance.md +0 -0
  35. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/dac_reflections.md +0 -0
  36. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/dac_sources.md +0 -0
  37. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/dac_tables.md +0 -0
  38. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/dac_validations.md +0 -0
  39. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/favorites.md +0 -0
  40. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/grants.md +0 -0
  41. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/history.md +0 -0
  42. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/init.md +0 -0
  43. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/installation.md +0 -0
  44. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/jobs.md +0 -0
  45. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/lineage.md +0 -0
  46. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/monitor.md +0 -0
  47. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/reflections.md +0 -0
  48. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/repl.md +0 -0
  49. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/roles.md +0 -0
  50. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/scripts.md +0 -0
  51. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/sources.md +0 -0
  52. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/spaces-folders.md +0 -0
  53. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/sql.md +0 -0
  54. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/tables.md +0 -0
  55. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/tags-wiki.md +0 -0
  56. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/tui.md +0 -0
  57. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/users.md +0 -0
  58. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/docs/views.md +0 -0
  59. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/__init__.py +0 -0
  60. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/__main__.py +0 -0
  61. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/cli.py +0 -0
  62. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/client/__init__.py +0 -0
  63. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/__init__.py +0 -0
  64. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/catalog.py +0 -0
  65. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/completion.py +0 -0
  66. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/favorite.py +0 -0
  67. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/folder.py +0 -0
  68. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/grant.py +0 -0
  69. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/history.py +0 -0
  70. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/init.py +0 -0
  71. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/job.py +0 -0
  72. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/lineage.py +0 -0
  73. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/monitor.py +0 -0
  74. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/reflection.py +0 -0
  75. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/repl.py +0 -0
  76. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/role.py +0 -0
  77. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/script.py +0 -0
  78. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/source.py +0 -0
  79. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/space.py +0 -0
  80. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/sql.py +0 -0
  81. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/sync.py +0 -0
  82. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/tag.py +0 -0
  83. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/udf.py +0 -0
  84. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/ui.py +0 -0
  85. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/view.py +0 -0
  86. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/commands/wiki.py +0 -0
  87. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/dac/__init__.py +0 -0
  88. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/dac/config.py +0 -0
  89. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/dac/diff.py +0 -0
  90. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/dac/graph.py +0 -0
  91. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/dac/state.py +0 -0
  92. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/dac/sync.py +0 -0
  93. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/env.py +0 -0
  94. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/formatters/__init__.py +0 -0
  95. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/formatters/json.py +0 -0
  96. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/formatters/table.py +0 -0
  97. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/formatters/yaml.py +0 -0
  98. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/history.py +0 -0
  99. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/__init__.py +0 -0
  100. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/app.py +0 -0
  101. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/screens.py +0 -0
  102. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/tui/catalog/widgets.py +0 -0
  103. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/utils/__init__.py +0 -0
  104. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/utils/console.py +0 -0
  105. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/utils/exceptions.py +0 -0
  106. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli/utils/helpers.py +0 -0
  107. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli.egg-info/dependency_links.txt +0 -0
  108. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli.egg-info/entry_points.txt +0 -0
  109. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli.egg-info/requires.txt +0 -0
  110. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/dremio_cli.egg-info/top_level.txt +0 -0
  111. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/setup.cfg +0 -0
  112. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/setup.py +0 -0
  113. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/__init__.py +0 -0
  114. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/conftest.py +0 -0
  115. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_grant_commands.py +0 -0
  116. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_history_favorite.py +0 -0
  117. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_job_commands.py +0 -0
  118. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_multi_sql_execution.py +0 -0
  119. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_reflection_commands.py +0 -0
  120. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_role_commands.py +0 -0
  121. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_script_commands.py +0 -0
  122. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_source_commands.py +0 -0
  123. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_space_folder_commands.py +0 -0
  124. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_sql_commands.py +0 -0
  125. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_table_commands.py +0 -0
  126. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_tag_wiki_commands.py +0 -0
  127. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_user_commands.py +0 -0
  128. {dremio_cli-1.9.0 → dremio_cli-1.10.0}/tests/test_view_commands.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dremio-cli
3
- Version: 1.9.0
3
+ Version: 1.10.0
4
4
  Summary: A comprehensive command-line interface for Dremio Cloud and Dremio Software
5
5
  Home-page: https://github.com/your-org/dremio-cli
6
6
  Author: Your Name
@@ -30,8 +30,9 @@ Complete documentation for the Dremio Command Line Interface.
30
30
  - **[History](history.md)** - View and re-run commands
31
31
 
32
32
  ### Administration
33
- - **[Users & Roles](users_roles.md)** - Manage users and Access Control
34
- - **[Service Users & External Auth](service_users.md)** - Service accounts and IdP JWTs
33
+ - **[Users](users.md)** - User account management
34
+ - **[Roles](roles.md)** - Role-based access control
35
+
35
36
  - **[Dremio-as-Code Guide](dac.md)** - GitOps for Dremio
36
37
 
37
38
 
@@ -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
+ ```
@@ -16,13 +16,12 @@ dremio profile create production \
16
16
  ### For Dremio Software
17
17
 
18
18
  ```bash
19
- dremio profile create --name local-dev \
19
+ dremio profile create local \
20
20
  --type software \
21
- --base-url http://localhost:9047 \
22
- --auth-type basic \
23
- --username admin \
24
- --password secret
25
- mio123
21
+ --base-url http://localhost:9047/api/v3 \
22
+ --auth-type username_password \
23
+ --username dremio \
24
+ --password dremio123
26
25
  ```
27
26
 
28
27
  ## 2. Verify Your Profile
@@ -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
 
@@ -49,45 +50,38 @@ def authenticate_with_username_password(
49
50
  if not token:
50
51
  raise AuthenticationError("No token in authentication response")
51
52
 
52
- # Return self-contained token
53
- return f"_dremio{token}"
53
+ # Return raw token (BaseClient adds prefix)
54
+ return token
54
55
 
55
56
  except requests.RequestException as e:
56
57
  raise AuthenticationError(f"Authentication request failed: {e}")
57
58
 
58
59
 
59
- def refresh_oauth_token(
60
+ def exchange_pat_for_oauth(
60
61
  base_url: str,
61
- refresh_token: str,
62
- client_id: Optional[str] = None,
63
- client_secret: Optional[str] = None,
62
+ pat: str,
64
63
  ) -> Dict[str, Any]:
65
- """Refresh OAuth token.
64
+ """Exchange PAT for OAuth token.
66
65
 
67
66
  Args:
68
67
  base_url: Base URL for Dremio
69
- refresh_token: Refresh token
70
- client_id: OAuth client ID
71
- client_secret: OAuth client secret
68
+ pat: Personal Access Token
72
69
 
73
70
  Returns:
74
- Dictionary with new access_token and refresh_token
71
+ Dictionary with access_token (and optionally refresh_token)
75
72
 
76
73
  Raises:
77
- AuthenticationError: If refresh fails
74
+ AuthenticationError: If exchange fails
78
75
  """
79
76
  oauth_url = f"{base_url}/oauth/token"
80
77
 
78
+ # Standard RFC 8693 Token Exchange params for Dremio
81
79
  data = {
82
- "grant_type": "refresh_token",
83
- "refresh_token": refresh_token,
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"
84
83
  }
85
84
 
86
- if client_id:
87
- data["client_id"] = client_id
88
- if client_secret:
89
- data["client_secret"] = client_secret
90
-
91
85
  try:
92
86
  response = requests.post(
93
87
  oauth_url,
@@ -97,56 +91,105 @@ def refresh_oauth_token(
97
91
  )
98
92
 
99
93
  if not response.ok:
100
- raise AuthenticationError(f"Token refresh failed: {response.text}")
94
+ raise AuthenticationError(f"PAT exchange failed: {response.text}")
101
95
 
102
96
  return response.json()
103
97
 
104
98
  except requests.RequestException as e:
105
- raise AuthenticationError(f"Token refresh request failed: {e}")
99
+ raise AuthenticationError(f"PAT exchange request failed: {e}")
106
100
 
107
101
 
108
- def exchange_external_jwt(
102
+ def authenticate_client_credentials(
109
103
  base_url: str,
110
- external_token: str,
111
- ) -> str:
112
- """Exchange external JWT for Dremio Access Token.
104
+ client_id: str,
105
+ client_secret: str,
106
+ ) -> Dict[str, Any]:
107
+ """Authenticate using OAuth Client Credentials.
113
108
 
114
109
  Args:
115
110
  base_url: Base URL for Dremio
116
- external_token: External Identity Provider JWT
111
+ client_id: Client ID
112
+ client_secret: Client Secret
117
113
 
118
114
  Returns:
119
- Dremio Access Token
115
+ Dictionary with access_token
120
116
 
121
117
  Raises:
122
- AuthenticationError: If exchange fails
118
+ AuthenticationError: If authentication fails
123
119
  """
124
- oauth_url = f"{base_url.rstrip('/')}/oauth/token"
120
+ oauth_url = f"{base_url}/oauth/token"
125
121
 
126
122
  data = {
127
- "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
128
- "subject_token": external_token,
129
- "subject_token_type": "urn:ietf:params:oauth:token-type:jwt"
123
+ "grant_type": "client_credentials"
130
124
  }
131
125
 
132
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.
133
129
  response = requests.post(
134
130
  oauth_url,
135
- data=data, # Form encoded
136
- headers={"Content-Type": "application/x-www-form-urlencoded"},
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
137
  timeout=30,
138
138
  )
139
139
 
140
140
  if not response.ok:
141
- raise AuthenticationError(f"Token exchange failed: {response.text}")
141
+ raise AuthenticationError(f"Client credentials auth failed: {response.text}")
142
142
 
143
- # Response should contain access_token
144
- result = response.json()
145
- token = result.get("access_token")
146
- if not token:
147
- raise AuthenticationError("No access_token in exchange response")
148
-
149
- return token
143
+ return response.json()
150
144
 
151
145
  except requests.RequestException as e:
152
- raise AuthenticationError(f"Token exchange request failed: {e}")
146
+ raise AuthenticationError(f"Client credentials request failed: {e}")
147
+
148
+
149
+ def refresh_oauth_token(
150
+ base_url: str,
151
+ refresh_token: str,
152
+ client_id: Optional[str] = None,
153
+ client_secret: Optional[str] = None,
154
+ ) -> Dict[str, Any]:
155
+ """Refresh OAuth token.
156
+
157
+ Args:
158
+ base_url: Base URL for Dremio
159
+ refresh_token: Refresh token
160
+ client_id: OAuth client ID
161
+ client_secret: OAuth client secret
162
+
163
+ Returns:
164
+ Dictionary with new access_token and refresh_token
165
+
166
+ Raises:
167
+ AuthenticationError: If refresh fails
168
+ """
169
+ oauth_url = f"{base_url}/oauth/token"
170
+
171
+ data = {
172
+ "grant_type": "refresh_token",
173
+ "refresh_token": refresh_token,
174
+ }
175
+
176
+ if client_id:
177
+ data["client_id"] = client_id
178
+ if client_secret:
179
+ data["client_secret"] = client_secret
180
+
181
+ try:
182
+ response = requests.post(
183
+ oauth_url,
184
+ json=data,
185
+ headers={"Content-Type": "application/json"},
186
+ timeout=30,
187
+ )
188
+
189
+ if not response.ok:
190
+ raise AuthenticationError(f"Token refresh failed: {response.text}")
191
+
192
+ return response.json()
193
+
194
+ except requests.RequestException as e:
195
+ raise AuthenticationError(f"Token refresh request failed: {e}")
@@ -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. Check your credentials.")
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
- """Make GET request.
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
- """Make POST request.
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
- """Make PUT request.
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
- """Make DELETE request.
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
- """Make PATCH request.
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__(base_url, token, timeout)
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: