gptc-hubble-sdk 0.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 (62) hide show
  1. gptc_hubble_sdk-0.10.0/LICENSE +201 -0
  2. gptc_hubble_sdk-0.10.0/MANIFEST.in +1 -0
  3. gptc_hubble_sdk-0.10.0/PKG-INFO +21 -0
  4. gptc_hubble_sdk-0.10.0/README.md +30 -0
  5. gptc_hubble_sdk-0.10.0/gptc_hubble_sdk.egg-info/PKG-INFO +21 -0
  6. gptc_hubble_sdk-0.10.0/gptc_hubble_sdk.egg-info/SOURCES.txt +60 -0
  7. gptc_hubble_sdk-0.10.0/gptc_hubble_sdk.egg-info/dependency_links.txt +1 -0
  8. gptc_hubble_sdk-0.10.0/gptc_hubble_sdk.egg-info/entry_points.txt +4 -0
  9. gptc_hubble_sdk-0.10.0/gptc_hubble_sdk.egg-info/requires.txt +10 -0
  10. gptc_hubble_sdk-0.10.0/gptc_hubble_sdk.egg-info/top_level.txt +1 -0
  11. gptc_hubble_sdk-0.10.0/hubble/__init__.py +157 -0
  12. gptc_hubble_sdk-0.10.0/hubble/__main__.py +15 -0
  13. gptc_hubble_sdk-0.10.0/hubble/api.py +117 -0
  14. gptc_hubble_sdk-0.10.0/hubble/client/__init__.py +0 -0
  15. gptc_hubble_sdk-0.10.0/hubble/client/base.py +109 -0
  16. gptc_hubble_sdk-0.10.0/hubble/client/client.py +383 -0
  17. gptc_hubble_sdk-0.10.0/hubble/client/endpoints.py +27 -0
  18. gptc_hubble_sdk-0.10.0/hubble/client/session.py +47 -0
  19. gptc_hubble_sdk-0.10.0/hubble/dockerauth.py +134 -0
  20. gptc_hubble_sdk-0.10.0/hubble/excepts.py +164 -0
  21. gptc_hubble_sdk-0.10.0/hubble/executor/__init__.py +17 -0
  22. gptc_hubble_sdk-0.10.0/hubble/executor/__main__.py +15 -0
  23. gptc_hubble_sdk-0.10.0/hubble/executor/helper.py +911 -0
  24. gptc_hubble_sdk-0.10.0/hubble/executor/hubapi.py +185 -0
  25. gptc_hubble_sdk-0.10.0/hubble/executor/hubio.py +1388 -0
  26. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/__init__.py +152 -0
  27. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/base.py +12 -0
  28. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/list.py +11 -0
  29. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/new.py +52 -0
  30. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/pull.py +49 -0
  31. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/push.py +105 -0
  32. gptc_hubble_sdk-0.10.0/hubble/executor/parsers/status.py +45 -0
  33. gptc_hubble_sdk-0.10.0/hubble/executor/requirements.py +154 -0
  34. gptc_hubble_sdk-0.10.0/hubble/parsers/__init__.py +46 -0
  35. gptc_hubble_sdk-0.10.0/hubble/parsers/base.py +12 -0
  36. gptc_hubble_sdk-0.10.0/hubble/parsers/helper.py +308 -0
  37. gptc_hubble_sdk-0.10.0/hubble/parsers/token.py +59 -0
  38. gptc_hubble_sdk-0.10.0/hubble/payment/__init__.py +0 -0
  39. gptc_hubble_sdk-0.10.0/hubble/payment/base.py +89 -0
  40. gptc_hubble_sdk-0.10.0/hubble/payment/client.py +131 -0
  41. gptc_hubble_sdk-0.10.0/hubble/payment/endpoints.py +12 -0
  42. gptc_hubble_sdk-0.10.0/hubble/payment/session.py +31 -0
  43. gptc_hubble_sdk-0.10.0/hubble/resources/Python.gitignore +164 -0
  44. gptc_hubble_sdk-0.10.0/hubble/resources/ci-vendors.json +205 -0
  45. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/Dockerfile +13 -0
  46. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/README.md +3 -0
  47. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/config.yml +8 -0
  48. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/executor.py +8 -0
  49. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/jax.Dockerfile +27 -0
  50. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/requirements.txt +0 -0
  51. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/tf.Dockerfile +16 -0
  52. gptc_hubble_sdk-0.10.0/hubble/resources/executor-template/torch.Dockerfile +20 -0
  53. gptc_hubble_sdk-0.10.0/hubble/utils/__init__.py +1 -0
  54. gptc_hubble_sdk-0.10.0/hubble/utils/api_utils.py +42 -0
  55. gptc_hubble_sdk-0.10.0/hubble/utils/auth.py +585 -0
  56. gptc_hubble_sdk-0.10.0/hubble/utils/config.py +88 -0
  57. gptc_hubble_sdk-0.10.0/hubble/utils/jwks.py +33 -0
  58. gptc_hubble_sdk-0.10.0/hubble/utils/jwt_parser.py +98 -0
  59. gptc_hubble_sdk-0.10.0/hubble/utils/notebook.py +24 -0
  60. gptc_hubble_sdk-0.10.0/hubble/utils/pbar.py +45 -0
  61. gptc_hubble_sdk-0.10.0/pyproject.toml +60 -0
  62. gptc_hubble_sdk-0.10.0/setup.cfg +4 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ recursive-include hubble/resources *
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: gptc-hubble-sdk
3
+ Version: 0.10.0
4
+ Summary: SDK for Hubble API at GPT::C0MPUTΞR.
5
+ Author-email: "GPT::C0MPUTΞR" <info@khulnasoft.com>
6
+ License: Apache 2.0
7
+ Project-URL: Source, https://github.com/gpt-computer/gptc-hubble-sdk/
8
+ Project-URL: Tracker, https://github.com/gpt-computer/gptc-hubble-sdk/issues
9
+ Requires-Python: >=3.7.0
10
+ License-File: LICENSE
11
+ Requires-Dist: requests
12
+ Requires-Dist: aiohttp
13
+ Requires-Dist: rich
14
+ Requires-Dist: importlib-metadata
15
+ Requires-Dist: filelock
16
+ Requires-Dist: pathspec
17
+ Requires-Dist: docker
18
+ Requires-Dist: pyyaml
19
+ Requires-Dist: python-jose
20
+ Requires-Dist: setuptools<80
21
+ Dynamic: license-file
@@ -0,0 +1,30 @@
1
+ # gptc-hubble-sdk
2
+
3
+ <img alt="PyPI" src="https://img.shields.io/pypi/v/gptc-hubble-sdk">
4
+ <img src="https://codecov.io/gh/gpt-computer/gptc-hubble-sdk/branch/main/graph/badge.svg?token=Sttz9HTmDq"/>
5
+
6
+
7
+ ## Install
8
+
9
+ ```shell
10
+ pip install gptc-hubble-sdk
11
+ ```
12
+
13
+ ```shell
14
+ conda install gptc-hubble-sdk -c conda-forge
15
+ ```
16
+
17
+ Or with [uv](https://github.com/astral-sh/uv):
18
+
19
+ ```shell
20
+ uv pip install gptc-hubble-sdk
21
+ ```
22
+
23
+ ## Core functionality
24
+
25
+ * Python API and CLI.
26
+ * Authentication and token management.
27
+ * Artifact management.
28
+
29
+ ## [Documentation](https://docs.gpt-computer.github.io/gpt-computer-cloud/login/)
30
+
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: gptc-hubble-sdk
3
+ Version: 0.10.0
4
+ Summary: SDK for Hubble API at GPT::C0MPUTΞR.
5
+ Author-email: "GPT::C0MPUTΞR" <info@khulnasoft.com>
6
+ License: Apache 2.0
7
+ Project-URL: Source, https://github.com/gpt-computer/gptc-hubble-sdk/
8
+ Project-URL: Tracker, https://github.com/gpt-computer/gptc-hubble-sdk/issues
9
+ Requires-Python: >=3.7.0
10
+ License-File: LICENSE
11
+ Requires-Dist: requests
12
+ Requires-Dist: aiohttp
13
+ Requires-Dist: rich
14
+ Requires-Dist: importlib-metadata
15
+ Requires-Dist: filelock
16
+ Requires-Dist: pathspec
17
+ Requires-Dist: docker
18
+ Requires-Dist: pyyaml
19
+ Requires-Dist: python-jose
20
+ Requires-Dist: setuptools<80
21
+ Dynamic: license-file
@@ -0,0 +1,60 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ gptc_hubble_sdk.egg-info/PKG-INFO
6
+ gptc_hubble_sdk.egg-info/SOURCES.txt
7
+ gptc_hubble_sdk.egg-info/dependency_links.txt
8
+ gptc_hubble_sdk.egg-info/entry_points.txt
9
+ gptc_hubble_sdk.egg-info/requires.txt
10
+ gptc_hubble_sdk.egg-info/top_level.txt
11
+ hubble/__init__.py
12
+ hubble/__main__.py
13
+ hubble/api.py
14
+ hubble/dockerauth.py
15
+ hubble/excepts.py
16
+ hubble/client/__init__.py
17
+ hubble/client/base.py
18
+ hubble/client/client.py
19
+ hubble/client/endpoints.py
20
+ hubble/client/session.py
21
+ hubble/executor/__init__.py
22
+ hubble/executor/__main__.py
23
+ hubble/executor/helper.py
24
+ hubble/executor/hubapi.py
25
+ hubble/executor/hubio.py
26
+ hubble/executor/requirements.py
27
+ hubble/executor/parsers/__init__.py
28
+ hubble/executor/parsers/base.py
29
+ hubble/executor/parsers/list.py
30
+ hubble/executor/parsers/new.py
31
+ hubble/executor/parsers/pull.py
32
+ hubble/executor/parsers/push.py
33
+ hubble/executor/parsers/status.py
34
+ hubble/parsers/__init__.py
35
+ hubble/parsers/base.py
36
+ hubble/parsers/helper.py
37
+ hubble/parsers/token.py
38
+ hubble/payment/__init__.py
39
+ hubble/payment/base.py
40
+ hubble/payment/client.py
41
+ hubble/payment/endpoints.py
42
+ hubble/payment/session.py
43
+ hubble/resources/Python.gitignore
44
+ hubble/resources/ci-vendors.json
45
+ hubble/resources/executor-template/Dockerfile
46
+ hubble/resources/executor-template/README.md
47
+ hubble/resources/executor-template/config.yml
48
+ hubble/resources/executor-template/executor.py
49
+ hubble/resources/executor-template/jax.Dockerfile
50
+ hubble/resources/executor-template/requirements.txt
51
+ hubble/resources/executor-template/tf.Dockerfile
52
+ hubble/resources/executor-template/torch.Dockerfile
53
+ hubble/utils/__init__.py
54
+ hubble/utils/api_utils.py
55
+ hubble/utils/auth.py
56
+ hubble/utils/config.py
57
+ hubble/utils/jwks.py
58
+ hubble/utils/jwt_parser.py
59
+ hubble/utils/notebook.py
60
+ hubble/utils/pbar.py
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ docker-credential-gptc-hubble = hubble.dockerauth:main
3
+ gptc-auth = hubble.__main__:main
4
+ gptc-hub = hubble.executor.__main__:main
@@ -0,0 +1,10 @@
1
+ requests
2
+ aiohttp
3
+ rich
4
+ importlib-metadata
5
+ filelock
6
+ pathspec
7
+ docker
8
+ pyyaml
9
+ python-jose
10
+ setuptools<80
@@ -0,0 +1,157 @@
1
+ """
2
+ The Hubble Python Client
3
+ """
4
+ import asyncio
5
+ import datetime as _datetime
6
+ import os as _os
7
+ import sys as _sys
8
+ from functools import wraps
9
+ from typing import Optional
10
+
11
+ import requests
12
+ from importlib_metadata import version
13
+
14
+ from .client.client import Client # noqa F401
15
+ from .excepts import AuthenticationRequiredError
16
+ from .utils.api_utils import get_json_from_response
17
+ from .utils.auth import Auth # noqa F401
18
+ from .utils.notebook import is_notebook # noqa F401
19
+
20
+ try:
21
+ __version__ = version("gptc-hubble-sdk")
22
+ except Exception:
23
+ __version__ = "v0.0.0"
24
+
25
+
26
+ __windows__ = _sys.platform == 'win32'
27
+ __uptime__ = _datetime.datetime.now().isoformat()
28
+
29
+
30
+ def login_required(func):
31
+ """Annotate a function so that it requires login to GPT::C0MPUTΞR to run.
32
+
33
+ Example:
34
+
35
+ .. highlight:: python
36
+ .. code-block:: python
37
+
38
+ @login_required
39
+ def foo():
40
+ print(1)
41
+
42
+ :param levels: required build level to run this function.
43
+ :return: annotated function
44
+ """
45
+
46
+ @wraps(func)
47
+ def arg_wrapper(*args, **kwargs):
48
+ try:
49
+ Client(jsonify=True).get_user_info()
50
+ return func(*args, **kwargs)
51
+ except AuthenticationRequiredError:
52
+ import sys
53
+
54
+ if sys.__stdin__.isatty():
55
+ from rich import print
56
+ from rich.prompt import Confirm
57
+
58
+ print(
59
+ ':closed_lock_with_key: [yellow bold]You are not logged in to GPT::C0MPUTΞR. [/]'
60
+ f'[yellow bold]However, {func!r} requires login to GPT::C0MPUTΞR[/].'
61
+ )
62
+ if Confirm.ask('Do you want to login now?'):
63
+ login(prompt='login')
64
+ return func(*args, **kwargs)
65
+ print(
66
+ '[yellow]You can login later by running [bold]gptc auth login[/] '
67
+ 'or set env variable [bold]GPTC_AUTH_TOKEN[/][/].'
68
+ )
69
+
70
+ raise AuthenticationRequiredError(
71
+ response={},
72
+ message=f'Gptc auth token is not provided or has expired. {func!r} requires login to GPT::C0MPUTΞR, '
73
+ f'please run `gptc auth login -f` or set env variable `GPTC_AUTH_TOKEN` with correct token',
74
+ ) from None
75
+
76
+ return arg_wrapper
77
+
78
+
79
+ def login(interactive: Optional[bool] = None, **kwargs):
80
+ """This function guides user to login."""
81
+
82
+ if interactive is None:
83
+ interactive = is_notebook()
84
+
85
+ if interactive:
86
+ Auth.login_notebook(**kwargs)
87
+ else:
88
+ Auth.login_sync(**kwargs)
89
+
90
+
91
+ def notebook_login(**kwargs):
92
+ """This function guides user to log-in via P.A.T. or via browser."""
93
+ Auth.login_notebook(**kwargs)
94
+
95
+
96
+ def logout():
97
+ """Logout."""
98
+ asyncio.run(Auth.logout())
99
+
100
+
101
+ def is_logged_in():
102
+ """Check if user is logged in."""
103
+ return True if Client(jsonify=True).token else False
104
+
105
+
106
+ def get_token(interactive: bool = False) -> Optional[str]:
107
+ """Get token."""
108
+ if _os.environ.get('SHOW_HUBBLE_HINT') == 'ALWAYS':
109
+ token = show_hint(interactive)
110
+ elif _os.environ.get('SHOW_HUBBLE_HINT', 'ONCE') == 'ONCE':
111
+ token = show_hint(interactive)
112
+ _os.environ['SHOW_HUBBLE_HINT'] = 'NEVER'
113
+ else:
114
+ token = Client(jsonify=True).token
115
+
116
+ return token
117
+
118
+
119
+ def show_hint(interactive: bool = False) -> Optional[str]: # noqa: E501
120
+ """
121
+ Show hint if the user is not logged in.
122
+
123
+ """
124
+ from rich import print
125
+
126
+ try:
127
+ c = Client(jsonify=True)
128
+
129
+ user_info = c.get_user_info(log_error=False)
130
+ if isinstance(user_info, requests.Response):
131
+ user_info = get_json_from_response(user_info)
132
+ user = user_info.get('data', {})
133
+ name = user.get('nickname') or user.get('name')
134
+ username = user.get('name')
135
+
136
+ print(
137
+ f':closed_lock_with_key: [green bold]You are logged in to GPT::C0MPUTΞR[/] '
138
+ f'as [bold]{name} (username: {username})[/]. '
139
+ f'To log out, use [dim]gptc auth logout[/].'
140
+ )
141
+ return c.token
142
+ except AuthenticationRequiredError:
143
+ print(
144
+ ':closed_lock_with_key: [yellow bold]You are not logged in to GPT::C0MPUTΞR[/]. '
145
+ 'To log in, use [bold]gptc auth login[/] or set env variable [bold]GPTC_AUTH_TOKEN[/].'
146
+ )
147
+ if interactive:
148
+ from rich.prompt import Confirm
149
+
150
+ if Confirm.ask('Do you want to login now?'):
151
+ login(prompt='login')
152
+
153
+ return show_hint(interactive=interactive)
154
+ return None
155
+ except Exception as ex:
156
+ print(f'Unknown error: {ex}')
157
+ return None
@@ -0,0 +1,15 @@
1
+ def main():
2
+ from .parsers import get_main_parser
3
+
4
+ args = get_main_parser().parse_args()
5
+
6
+ try:
7
+ from . import api
8
+
9
+ getattr(api, args.auth_cli.replace('-', '_'))(args)
10
+ except KeyboardInterrupt:
11
+ pass
12
+
13
+
14
+ if __name__ == '__main__':
15
+ main()
@@ -0,0 +1,117 @@
1
+ import os
2
+
3
+ from . import Client
4
+ from . import login as _login
5
+ from . import logout as _logout
6
+ from .excepts import AuthenticationFailedError, AuthenticationRequiredError
7
+ from .utils.api_utils import get_json_from_response
8
+
9
+
10
+ def logout(*args):
11
+ _logout()
12
+
13
+
14
+ def login(args):
15
+ client = Client(jsonify=True)
16
+ username = ''
17
+
18
+ if args.force:
19
+ _login(prompt='login', force=True)
20
+ return
21
+
22
+ try:
23
+ username = client.username
24
+ except Exception as ex:
25
+ if isinstance(ex, (AuthenticationRequiredError, AuthenticationFailedError)):
26
+ _login(prompt='login')
27
+ else:
28
+ raise ex
29
+ else:
30
+ from .dockerauth import auto_deploy_hubble_docker_credential_helper
31
+
32
+ auto_deploy_hubble_docker_credential_helper()
33
+
34
+ if username:
35
+ from rich.console import Console
36
+
37
+ console = Console()
38
+ console.print(
39
+ f':closed_lock_with_key: You are already logged in as [b green]{username}[/b green].',
40
+ '',
41
+ 'If you want to log in to another account, please run either:',
42
+ '- [b]gptc auth logout[/]',
43
+ '- or, [b]gptc auth login -f[/]',
44
+ sep=os.linesep,
45
+ )
46
+
47
+
48
+ def token(args):
49
+ client = Client(max_retries=None)
50
+
51
+ if args.operation == 'create':
52
+ response = client.create_personal_access_token(
53
+ name=args.name, expiration_days=args.expire
54
+ )
55
+
56
+ response.raise_for_status()
57
+ json_response = get_json_from_response(response)
58
+ token = json_response['data']['token']
59
+ if args.format == 'raw':
60
+ print(token)
61
+ elif args.format == 'table':
62
+ import rich
63
+ from rich.panel import Panel
64
+
65
+ rich.print(
66
+ Panel(
67
+ f'''[b]{token}[/b]
68
+
69
+ You can set it as an env var [b]GPTC_AUTH_TOKEN[/b]''',
70
+ title=':party_popper: [green]New token created[/]',
71
+ subtitle=':point_up:️ [yellow] This token is only shown once![/]',
72
+ width=50,
73
+ )
74
+ )
75
+
76
+ if args.operation == 'delete':
77
+ response = client.delete_personal_access_token(name=args.name)
78
+
79
+ response.raise_for_status()
80
+
81
+ import rich
82
+ from rich.panel import Panel
83
+
84
+ rich.print(
85
+ Panel(
86
+ f'[b]{args.name}[/b]',
87
+ title=':party_popper: [green]Successfully deleted',
88
+ width=50,
89
+ )
90
+ )
91
+
92
+ if args.operation == 'list':
93
+ response = client.list_personal_access_tokens()
94
+ response.raise_for_status()
95
+ json_response = get_json_from_response(response)
96
+ tokens = json_response['data']['personal_access_tokens']
97
+
98
+ import rich
99
+ from rich.table import Table
100
+
101
+ table = Table(title='Your Personal Access Tokens', highlight=True)
102
+ table.add_column('Name')
103
+ table.add_column('Type')
104
+ table.add_column('Create at', justify='center')
105
+ table.add_column('Expire at', justify='center')
106
+ table.add_column('Last use at', justify='center')
107
+
108
+ for token in tokens:
109
+ table.add_row(
110
+ token['name'],
111
+ token['type'],
112
+ token['createdAt'],
113
+ token['expireAt'],
114
+ token['updatedAt'],
115
+ )
116
+
117
+ rich.print(table)
File without changes