gl-connectors-cli 0.1.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 (31) hide show
  1. gl_connectors_cli-0.1.0/PKG-INFO +200 -0
  2. gl_connectors_cli-0.1.0/README.md +184 -0
  3. gl_connectors_cli-0.1.0/gl_connectors_cli/__init__.py +5 -0
  4. gl_connectors_cli-0.1.0/gl_connectors_cli/__main__.py +12 -0
  5. gl_connectors_cli-0.1.0/gl_connectors_cli/api/__init__.py +19 -0
  6. gl_connectors_cli-0.1.0/gl_connectors_cli/api/auth.py +47 -0
  7. gl_connectors_cli-0.1.0/gl_connectors_cli/api/base.py +86 -0
  8. gl_connectors_cli-0.1.0/gl_connectors_cli/api/integrations.py +199 -0
  9. gl_connectors_cli-0.1.0/gl_connectors_cli/api/models.py +47 -0
  10. gl_connectors_cli-0.1.0/gl_connectors_cli/api/users.py +66 -0
  11. gl_connectors_cli-0.1.0/gl_connectors_cli/commands/__init__.py +1 -0
  12. gl_connectors_cli-0.1.0/gl_connectors_cli/commands/auth.py +236 -0
  13. gl_connectors_cli-0.1.0/gl_connectors_cli/commands/base.py +63 -0
  14. gl_connectors_cli-0.1.0/gl_connectors_cli/commands/integrations.py +533 -0
  15. gl_connectors_cli-0.1.0/gl_connectors_cli/commands/users.py +144 -0
  16. gl_connectors_cli-0.1.0/gl_connectors_cli/config.py +223 -0
  17. gl_connectors_cli-0.1.0/gl_connectors_cli/constants.py +119 -0
  18. gl_connectors_cli-0.1.0/gl_connectors_cli/main.py +103 -0
  19. gl_connectors_cli-0.1.0/gl_connectors_cli/utils.py +327 -0
  20. gl_connectors_cli-0.1.0/gl_connectors_cli.egg-info/PKG-INFO +200 -0
  21. gl_connectors_cli-0.1.0/gl_connectors_cli.egg-info/SOURCES.txt +29 -0
  22. gl_connectors_cli-0.1.0/gl_connectors_cli.egg-info/dependency_links.txt +1 -0
  23. gl_connectors_cli-0.1.0/gl_connectors_cli.egg-info/entry_points.txt +2 -0
  24. gl_connectors_cli-0.1.0/gl_connectors_cli.egg-info/requires.txt +10 -0
  25. gl_connectors_cli-0.1.0/gl_connectors_cli.egg-info/top_level.txt +1 -0
  26. gl_connectors_cli-0.1.0/pyproject.toml +42 -0
  27. gl_connectors_cli-0.1.0/setup.cfg +4 -0
  28. gl_connectors_cli-0.1.0/setup.py +10 -0
  29. gl_connectors_cli-0.1.0/tests/test_config.py +407 -0
  30. gl_connectors_cli-0.1.0/tests/test_main.py +207 -0
  31. gl_connectors_cli-0.1.0/tests/test_utils.py +399 -0
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.4
2
+ Name: gl-connectors-cli
3
+ Version: 0.1.0
4
+ Author-email: GL Connectors Team <bosa-eng@gdplabs.id>
5
+ Requires-Python: <3.14,>=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: requests<3.0.0,>=2.31.0
8
+ Requires-Dist: pydantic<3.0.0,>=2.11.7
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=8.4.1; extra == "dev"
11
+ Requires-Dist: pytest-cov>=6.2.1; extra == "dev"
12
+ Requires-Dist: ruff>=0.12.7; extra == "dev"
13
+ Requires-Dist: mypy>=1.17.0; extra == "dev"
14
+ Requires-Dist: pre-commit>=4.2.0; extra == "dev"
15
+ Requires-Dist: pip-tools>=7.0.0; extra == "dev"
16
+
17
+ # GL Connectors CLI
18
+
19
+ A command-line interface for managing GL Connectors integrations and authentication.
20
+
21
+ ## Prerequisites
22
+
23
+ <details>
24
+ <summary>Prerequisites details</summary>
25
+
26
+ 1. **Python v3.11 or above** (to run `python`)
27
+
28
+ - Using Conda (recommended):
29
+ You can use [Miniconda](https://docs.anaconda.com/miniconda/install) to install and manage Python versions.
30
+
31
+ 2. **Connector access** (contact your administrator for credentials)
32
+ </details>
33
+
34
+ ## Installation
35
+
36
+ Install the CLI using:
37
+
38
+ ```bash
39
+ pip install gl-connectors-cli
40
+ ```
41
+
42
+ ## Quick Start
43
+
44
+ Get up and create your first integration using GL Connectors CLI:
45
+
46
+ 1. **Login**:
47
+
48
+ ```bash
49
+ glcon auth login
50
+ # Make sure you have access to GL Connectors playground environment.
51
+ # You will be prompted to enter:
52
+
53
+ # Client API Key: sk-client-...
54
+ # Username (User Identifier): your user identifier
55
+ # User Secret: sk-user-...
56
+ ```
57
+
58
+ 2. **View Available Integrations**:
59
+
60
+ ```bash
61
+ glcon integrations
62
+ ```
63
+
64
+ You should have 0 integration(s) count for each connector listed.
65
+
66
+ 3. **Add Your First Integration**:
67
+
68
+ ```bash
69
+ glcon integrations add github
70
+ ```
71
+
72
+ You should see the following message:
73
+
74
+ ```
75
+ ✓ OAuth flow initiated for github!
76
+ Please visit the following URL to complete the integration:
77
+ https://github.com/login/oauth/authorize?client_id=...
78
+ ```
79
+
80
+ Open the URL in your browser and follow the OAuth flow.
81
+
82
+ 4. **Check your GitHub accounts**:
83
+
84
+ After you have completed the OAuth flow, you can check your GitHub accounts.
85
+
86
+ ```bash
87
+ glcon integrations show github
88
+ ```
89
+
90
+ Voila! You should see your GitHub accounts listed, as shown below:
91
+
92
+ ```
93
+ Integrations for github
94
+ =======================
95
+ ℹ Found 1 integration(s)
96
+
97
+ User Identifier | Status
98
+ ------------------------------------
99
+ | your-github-username | ✓ Selected
100
+ ```
101
+
102
+ That's it! You're now ready to manage your GL Connectors' integrations.
103
+
104
+ ## Command Reference
105
+
106
+ ### Authentication Commands
107
+
108
+ | Command | Description | Options |
109
+ | ------------------- | ------------------------------------ | ----------------- |
110
+ | `glcon auth login` | Authenticate with client credentials | `--api-url <url>` |
111
+ | `glcon auth status` | Check current authentication status | - |
112
+ | `glcon auth logout` | Clear stored credentials | - |
113
+
114
+ **Login prompts**:
115
+
116
+ - **Client API Key**: Your client API key (input hidden)
117
+ - **Username**: Your user identifier
118
+ - **User Secret**: Your user secret (input hidden)
119
+
120
+ **Configuration Options**:
121
+
122
+ - `--api-url`: Custom Connector URL (for development purposes)
123
+
124
+ ### Integration Commands
125
+
126
+ | Command | Description | Parameter(s) |
127
+ | ---------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------ |
128
+ | `glcon integrations` | List all connectors and integration counts | - |
129
+ | `glcon integrations list` | Same as above (explicit) | - |
130
+ | `glcon integrations add <connector>` | Add new integration via OAuth flow | `<connector>`: github, google, etc. |
131
+ | `glcon integrations show <connector>` | Show all accounts for a connector | `<connector>`: github, google, etc. |
132
+ | `glcon integrations show <connector> <identifier>` | Show specific integration details | `<connector>`: github, google, etc. `<identifier>`: email/username |
133
+ | `glcon integrations remove <connector> <identifier>` | Remove specific integration | `<connector>`: github, google, etc. `<identifier>`: email/username |
134
+ | `glcon integrations select <connector> <identifier>` | Set integration as primary | `<connector>`: github, google, etc. `<identifier>`: email/username |
135
+
136
+ **Examples**:
137
+
138
+ ```bash
139
+ glcon integrations # List all connectors
140
+ glcon integrations add github # Add GitHub integration
141
+ glcon integrations show google # Show all Google accounts
142
+ glcon integrations show google user@gmail.com # Show specific account details
143
+ glcon integrations remove github username # Remove GitHub integration
144
+ glcon integrations select google user@gmail.com # Set as primary Google account
145
+ ```
146
+
147
+ ### User Commands
148
+
149
+ | Command | Description | Parameter(s) |
150
+ | --------------------------------- | ------------------------- | ------------------------------ |
151
+ | `glcon users create <identifier>` | Create a new user account | `<identifier>`: email/username |
152
+
153
+ **Example**:
154
+
155
+ ```bash
156
+ glcon users create john.doe@example.com
157
+ ```
158
+
159
+ **Important**: Save the user secret securely! It's only shown once.
160
+
161
+ ## Configuration
162
+
163
+ The CLI stores configuration in `~/.connector/config.json`. This file contains:
164
+
165
+ - Authentication session (client key, user token, API URL)
166
+ - Session expiration information
167
+
168
+ The API URL is only configurable during authentication using the `--api-url` flag.
169
+
170
+ ## Getting Help
171
+
172
+ Get help for any command:
173
+
174
+ ```bash
175
+ glcon --help # Main help
176
+ glcon auth --help # Authentication commands help
177
+ glcon integrations --help # Integration commands help
178
+ glcon users --help # User management commands help
179
+ ```
180
+
181
+ ## Available Connectors
182
+
183
+ The available connectors depend on your Connector configuration. Common connectors include:
184
+
185
+ - **github**: GitHub API integration
186
+ - **google**: Google services integration
187
+ - **google_drive**: Google Drive integration
188
+ - **google_docs**: Google Docs integration
189
+ - **google_mail**: Google Mail integration
190
+
191
+ ## Contributing
192
+
193
+ We welcome contributions! Please see our documentation:
194
+
195
+ - **[CONTRIBUTING.md](CONTRIBUTING.md)** - Development setup, workflow, and code review guidelines
196
+ - **[constitution.md](constitution.md)** - Code generation standards
197
+
198
+ ## License
199
+
200
+ This project is maintained by the GL Connectors Team.
@@ -0,0 +1,184 @@
1
+ # GL Connectors CLI
2
+
3
+ A command-line interface for managing GL Connectors integrations and authentication.
4
+
5
+ ## Prerequisites
6
+
7
+ <details>
8
+ <summary>Prerequisites details</summary>
9
+
10
+ 1. **Python v3.11 or above** (to run `python`)
11
+
12
+ - Using Conda (recommended):
13
+ You can use [Miniconda](https://docs.anaconda.com/miniconda/install) to install and manage Python versions.
14
+
15
+ 2. **Connector access** (contact your administrator for credentials)
16
+ </details>
17
+
18
+ ## Installation
19
+
20
+ Install the CLI using:
21
+
22
+ ```bash
23
+ pip install gl-connectors-cli
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ Get up and create your first integration using GL Connectors CLI:
29
+
30
+ 1. **Login**:
31
+
32
+ ```bash
33
+ glcon auth login
34
+ # Make sure you have access to GL Connectors playground environment.
35
+ # You will be prompted to enter:
36
+
37
+ # Client API Key: sk-client-...
38
+ # Username (User Identifier): your user identifier
39
+ # User Secret: sk-user-...
40
+ ```
41
+
42
+ 2. **View Available Integrations**:
43
+
44
+ ```bash
45
+ glcon integrations
46
+ ```
47
+
48
+ You should have 0 integration(s) count for each connector listed.
49
+
50
+ 3. **Add Your First Integration**:
51
+
52
+ ```bash
53
+ glcon integrations add github
54
+ ```
55
+
56
+ You should see the following message:
57
+
58
+ ```
59
+ ✓ OAuth flow initiated for github!
60
+ Please visit the following URL to complete the integration:
61
+ https://github.com/login/oauth/authorize?client_id=...
62
+ ```
63
+
64
+ Open the URL in your browser and follow the OAuth flow.
65
+
66
+ 4. **Check your GitHub accounts**:
67
+
68
+ After you have completed the OAuth flow, you can check your GitHub accounts.
69
+
70
+ ```bash
71
+ glcon integrations show github
72
+ ```
73
+
74
+ Voila! You should see your GitHub accounts listed, as shown below:
75
+
76
+ ```
77
+ Integrations for github
78
+ =======================
79
+ ℹ Found 1 integration(s)
80
+
81
+ User Identifier | Status
82
+ ------------------------------------
83
+ | your-github-username | ✓ Selected
84
+ ```
85
+
86
+ That's it! You're now ready to manage your GL Connectors' integrations.
87
+
88
+ ## Command Reference
89
+
90
+ ### Authentication Commands
91
+
92
+ | Command | Description | Options |
93
+ | ------------------- | ------------------------------------ | ----------------- |
94
+ | `glcon auth login` | Authenticate with client credentials | `--api-url <url>` |
95
+ | `glcon auth status` | Check current authentication status | - |
96
+ | `glcon auth logout` | Clear stored credentials | - |
97
+
98
+ **Login prompts**:
99
+
100
+ - **Client API Key**: Your client API key (input hidden)
101
+ - **Username**: Your user identifier
102
+ - **User Secret**: Your user secret (input hidden)
103
+
104
+ **Configuration Options**:
105
+
106
+ - `--api-url`: Custom Connector URL (for development purposes)
107
+
108
+ ### Integration Commands
109
+
110
+ | Command | Description | Parameter(s) |
111
+ | ---------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------ |
112
+ | `glcon integrations` | List all connectors and integration counts | - |
113
+ | `glcon integrations list` | Same as above (explicit) | - |
114
+ | `glcon integrations add <connector>` | Add new integration via OAuth flow | `<connector>`: github, google, etc. |
115
+ | `glcon integrations show <connector>` | Show all accounts for a connector | `<connector>`: github, google, etc. |
116
+ | `glcon integrations show <connector> <identifier>` | Show specific integration details | `<connector>`: github, google, etc. `<identifier>`: email/username |
117
+ | `glcon integrations remove <connector> <identifier>` | Remove specific integration | `<connector>`: github, google, etc. `<identifier>`: email/username |
118
+ | `glcon integrations select <connector> <identifier>` | Set integration as primary | `<connector>`: github, google, etc. `<identifier>`: email/username |
119
+
120
+ **Examples**:
121
+
122
+ ```bash
123
+ glcon integrations # List all connectors
124
+ glcon integrations add github # Add GitHub integration
125
+ glcon integrations show google # Show all Google accounts
126
+ glcon integrations show google user@gmail.com # Show specific account details
127
+ glcon integrations remove github username # Remove GitHub integration
128
+ glcon integrations select google user@gmail.com # Set as primary Google account
129
+ ```
130
+
131
+ ### User Commands
132
+
133
+ | Command | Description | Parameter(s) |
134
+ | --------------------------------- | ------------------------- | ------------------------------ |
135
+ | `glcon users create <identifier>` | Create a new user account | `<identifier>`: email/username |
136
+
137
+ **Example**:
138
+
139
+ ```bash
140
+ glcon users create john.doe@example.com
141
+ ```
142
+
143
+ **Important**: Save the user secret securely! It's only shown once.
144
+
145
+ ## Configuration
146
+
147
+ The CLI stores configuration in `~/.connector/config.json`. This file contains:
148
+
149
+ - Authentication session (client key, user token, API URL)
150
+ - Session expiration information
151
+
152
+ The API URL is only configurable during authentication using the `--api-url` flag.
153
+
154
+ ## Getting Help
155
+
156
+ Get help for any command:
157
+
158
+ ```bash
159
+ glcon --help # Main help
160
+ glcon auth --help # Authentication commands help
161
+ glcon integrations --help # Integration commands help
162
+ glcon users --help # User management commands help
163
+ ```
164
+
165
+ ## Available Connectors
166
+
167
+ The available connectors depend on your Connector configuration. Common connectors include:
168
+
169
+ - **github**: GitHub API integration
170
+ - **google**: Google services integration
171
+ - **google_drive**: Google Drive integration
172
+ - **google_docs**: Google Docs integration
173
+ - **google_mail**: Google Mail integration
174
+
175
+ ## Contributing
176
+
177
+ We welcome contributions! Please see our documentation:
178
+
179
+ - **[CONTRIBUTING.md](CONTRIBUTING.md)** - Development setup, workflow, and code review guidelines
180
+ - **[constitution.md](constitution.md)** - Code generation standards
181
+
182
+ ## License
183
+
184
+ This project is maintained by the GL Connectors Team.
@@ -0,0 +1,5 @@
1
+ """GL Connectors CLI module for managing integrations and authentication."""
2
+
3
+ from gl_connectors_cli.main import main
4
+
5
+ __all__ = ["main"]
@@ -0,0 +1,12 @@
1
+ """CLI entry point.
2
+
3
+ Authors:
4
+ GL Connectors Team
5
+ """
6
+
7
+ import sys
8
+
9
+ from gl_connectors_cli.main import main
10
+
11
+ if __name__ == "__main__":
12
+ sys.exit(main())
@@ -0,0 +1,19 @@
1
+ """GL Connectors CLI API clients.
2
+
3
+ Author:
4
+ I Gusti Ngurah Gana Untaran (i.gusti.n.g.untaran@gdplabs.id)
5
+ """
6
+
7
+ from gl_connectors_cli.api.auth import AuthAPIClient
8
+ from gl_connectors_cli.api.integrations import IntegrationsAPIClient
9
+ from gl_connectors_cli.api.models import IntegrationDetail, Token, User
10
+ from gl_connectors_cli.api.users import UsersAPIClient
11
+
12
+ __all__ = [
13
+ "AuthAPIClient",
14
+ "UsersAPIClient",
15
+ "IntegrationsAPIClient",
16
+ "User",
17
+ "Token",
18
+ "IntegrationDetail",
19
+ ]
@@ -0,0 +1,47 @@
1
+ """Authentication API client for GL Connectors CLI.
2
+
3
+ Author:
4
+ I Gusti Ngurah Gana Untaran (i.gusti.n.g.untaran@gdplabs.id)
5
+ """
6
+
7
+ from gl_connectors_cli.api.base import BaseAPIClient
8
+ from gl_connectors_cli.api.models import Token
9
+ from gl_connectors_cli.constants import API_KEY_HEADER, HTTP_POST
10
+ from gl_connectors_cli.utils import CLIError
11
+
12
+
13
+ class AuthAPIClient(BaseAPIClient):
14
+ """Authentication API client."""
15
+
16
+ def authenticate_user(self, client_key: str, identifier: str, secret: str) -> Token:
17
+ """Authenticate user and get JWT token.
18
+
19
+ Args:
20
+ client_key: Client API key
21
+ identifier: User identifier
22
+ secret: User secret
23
+
24
+ Returns:
25
+ Authentication token information
26
+
27
+ Raises:
28
+ CLIError: If authentication fails
29
+
30
+ """
31
+ headers = {
32
+ API_KEY_HEADER: client_key,
33
+ }
34
+
35
+ data = {"identifier": identifier, "secret": secret}
36
+
37
+ try:
38
+ response = self._make_request(HTTP_POST, "/clients/oauth-token", headers=headers, data=data)
39
+ token_data = response.get("data", None)
40
+
41
+ if not token_data:
42
+ raise CLIError("Authentication error. Please check your credentials and try again.")
43
+
44
+ return Token(**token_data)
45
+
46
+ except Exception as e:
47
+ raise CLIError(str(e)) from e
@@ -0,0 +1,86 @@
1
+ """Base API client for GL Connectors CLI.
2
+
3
+ Author:
4
+ I Gusti Ngurah Gana Untaran (i.gusti.n.g.untaran@gdplabs.id)
5
+ """
6
+
7
+ import json
8
+ from typing import Any, Dict, Optional
9
+
10
+ import requests
11
+
12
+ from gl_connectors_cli.constants import HTTP_DELETE, HTTP_GET, HTTP_POST, HTTP_PUT
13
+ from gl_connectors_cli.utils import CLIError
14
+
15
+
16
+ class BaseAPIClient:
17
+ """Base API client with shared request functionality."""
18
+
19
+ def __init__(self, base_url: str):
20
+ """Initialize base API client.
21
+
22
+ Args:
23
+ base_url: Connector base URL
24
+
25
+ """
26
+ self.base_url = base_url.rstrip("/")
27
+ self.session = requests.Session()
28
+
29
+ def _make_request(
30
+ self,
31
+ method: str,
32
+ endpoint: str,
33
+ headers: Optional[Dict[str, str]] = None,
34
+ data: Optional[Dict[str, Any]] = None,
35
+ params: Optional[Dict[str, str]] = None,
36
+ ) -> Dict[str, Any]:
37
+ """Make HTTP request to Connector.
38
+
39
+ Args:
40
+ method: HTTP method (GET, POST, DELETE, etc.)
41
+ endpoint: API endpoint path
42
+ headers: Request headers
43
+ data: Request body data
44
+ params: URL parameters
45
+
46
+ Returns:
47
+ Response JSON data
48
+
49
+ Raises:
50
+ CLIError: If request fails
51
+
52
+ """
53
+ url = f"{self.base_url}{endpoint}"
54
+
55
+ try:
56
+ if method.upper() == HTTP_GET:
57
+ response = self.session.get(url, headers=headers, params=params)
58
+ elif method.upper() == HTTP_POST:
59
+ response = self.session.post(url, headers=headers, json=data, params=params)
60
+ elif method.upper() == HTTP_DELETE:
61
+ response = self.session.delete(url, headers=headers, params=params)
62
+ elif method.upper() == HTTP_PUT:
63
+ response = self.session.put(url, headers=headers, json=data, params=params)
64
+ else:
65
+ raise CLIError(f"Unsupported HTTP method: {method}")
66
+
67
+ response_data = response.json()
68
+ if not response.ok or ("success" in response_data and response_data["success"] is False):
69
+ error_data = response_data.get("error", {})
70
+ error_message = error_data.get("message", response.status_code)
71
+ raise CLIError(f"API error: {error_message}")
72
+
73
+ return response_data
74
+
75
+ except requests.exceptions.ConnectionError as e:
76
+ raise CLIError(f"Failed to connect to {self.base_url}: {str(e)}") from e
77
+ except requests.exceptions.Timeout as e:
78
+ raise CLIError(f"Request timeout: {str(e)}") from e
79
+ except requests.exceptions.RequestException as e:
80
+ raise CLIError(f"Request failed: {str(e)}") from e
81
+ except json.JSONDecodeError as e:
82
+ raise CLIError(f"Invalid JSON response from server: {str(e)}") from e
83
+ except CLIError as e:
84
+ raise e
85
+ except Exception as e:
86
+ raise CLIError(f"An unexpected error occurred: {str(e)}") from e