itcpr 2.0.2__tar.gz → 2.0.3__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.
- itcpr-2.0.3/MANIFEST.in +4 -0
- itcpr-2.0.3/PKG-INFO +313 -0
- itcpr-2.0.3/README.md +283 -0
- itcpr-2.0.3/itcpr/__init__.py +4 -0
- itcpr-2.0.3/itcpr/api.py +73 -0
- itcpr-2.0.3/itcpr/auth.py +167 -0
- itcpr-2.0.3/itcpr/cli.py +249 -0
- itcpr-2.0.3/itcpr/config.py +93 -0
- itcpr-2.0.3/itcpr/gitops.py +181 -0
- itcpr-2.0.3/itcpr/storage.py +155 -0
- itcpr-2.0.3/itcpr/sync.py +174 -0
- itcpr-2.0.3/itcpr/utils.py +40 -0
- itcpr-2.0.3/itcpr.egg-info/PKG-INFO +313 -0
- itcpr-2.0.3/itcpr.egg-info/SOURCES.txt +19 -0
- itcpr-2.0.3/itcpr.egg-info/entry_points.txt +2 -0
- itcpr-2.0.3/itcpr.egg-info/requires.txt +9 -0
- itcpr-2.0.3/pyproject.toml +40 -0
- itcpr-2.0.3/setup.py +46 -0
- itcpr-2.0.2/LICENSE +0 -10
- itcpr-2.0.2/PKG-INFO +0 -120
- itcpr-2.0.2/README.md +0 -104
- itcpr-2.0.2/itcpr/__init__.py +0 -0
- itcpr-2.0.2/itcpr/kwant.py +0 -133
- itcpr-2.0.2/itcpr/mumax3.py +0 -297
- itcpr-2.0.2/itcpr.egg-info/PKG-INFO +0 -120
- itcpr-2.0.2/itcpr.egg-info/SOURCES.txt +0 -11
- itcpr-2.0.2/itcpr.egg-info/requires.txt +0 -5
- itcpr-2.0.2/pyproject.toml +0 -13
- {itcpr-2.0.2 → itcpr-2.0.3}/itcpr.egg-info/dependency_links.txt +0 -0
- {itcpr-2.0.2 → itcpr-2.0.3}/itcpr.egg-info/top_level.txt +0 -0
- {itcpr-2.0.2 → itcpr-2.0.3}/setup.cfg +0 -0
itcpr-2.0.3/MANIFEST.in
ADDED
itcpr-2.0.3/PKG-INFO
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: itcpr
|
|
3
|
+
Version: 2.0.3
|
|
4
|
+
Summary: CLI tool for syncing GitHub repositories from ITCPR Cloud
|
|
5
|
+
Home-page: https://github.com/ITCPR/itcpr
|
|
6
|
+
Author: ITCPR
|
|
7
|
+
Author-email: ITCPR <info@itcpr.org>
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: itcpr,github,git,sync,cli,repository
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Requires-Dist: click>=8.0.0
|
|
20
|
+
Requires-Dist: requests>=2.28.0
|
|
21
|
+
Requires-Dist: keyring>=23.0.0
|
|
22
|
+
Requires-Dist: tomli-w>=1.0.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest; extra == "dev"
|
|
25
|
+
Requires-Dist: black; extra == "dev"
|
|
26
|
+
Requires-Dist: flake8; extra == "dev"
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
|
|
31
|
+
# ITCPR Agent
|
|
32
|
+
|
|
33
|
+
A production-ready CLI tool for syncing GitHub repositories from ITCPR Cloud to your local machine.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- 🔐 Device-based authentication with cloud.itcpr.org
|
|
38
|
+
- 📦 Automatic repository synchronization
|
|
39
|
+
- 🔄 Manual or continuous sync modes
|
|
40
|
+
- 💾 Local SQLite database for metadata tracking
|
|
41
|
+
- 🔒 Secure token storage using OS keyring
|
|
42
|
+
- 🛡️ Safe git operations with conflict detection
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
### From Source
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cd cloud-cli
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Uninstall
|
|
54
|
+
|
|
55
|
+
To remove the CLI tool:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip uninstall itcpr
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Note:** This will remove the CLI tool but will **not** delete:
|
|
62
|
+
- Configuration files (`~/.itcpr/config.toml`)
|
|
63
|
+
- Local repository database (`~/.itcpr/repos.db`)
|
|
64
|
+
- Stored device tokens (in OS keyring)
|
|
65
|
+
|
|
66
|
+
To completely remove all data:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Uninstall the package
|
|
70
|
+
pip uninstall itcpr
|
|
71
|
+
|
|
72
|
+
# Remove configuration and data
|
|
73
|
+
rm -rf ~/.itcpr
|
|
74
|
+
|
|
75
|
+
# Remove stored tokens (OS keyring)
|
|
76
|
+
# On macOS: Use Keychain Access app to remove "itcpr" entries
|
|
77
|
+
# On Linux: Use your keyring manager (e.g., seahorse, kwallet)
|
|
78
|
+
# On Windows: Use Credential Manager
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Requirements
|
|
82
|
+
|
|
83
|
+
- Python 3.10+
|
|
84
|
+
- Git (system installation)
|
|
85
|
+
- Access to cloud.itcpr.org
|
|
86
|
+
|
|
87
|
+
## Quick Start
|
|
88
|
+
|
|
89
|
+
### 1. Login
|
|
90
|
+
|
|
91
|
+
Authenticate your device with ITCPR Cloud:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
itcpr login
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This will:
|
|
98
|
+
- Open your browser to the device login page
|
|
99
|
+
- Display a device code
|
|
100
|
+
- Wait for approval
|
|
101
|
+
- Store credentials securely
|
|
102
|
+
|
|
103
|
+
### 2. Check Status
|
|
104
|
+
|
|
105
|
+
View your assigned repositories:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
itcpr status
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3. List Repositories
|
|
112
|
+
|
|
113
|
+
See all repositories assigned to your device:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
itcpr repos
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 4. Clone a Repository
|
|
120
|
+
|
|
121
|
+
Clone a repository to your local machine:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
itcpr clone paperport-itcpr
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Or specify a custom path:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
itcpr clone paperport-itcpr --path ~/projects/paperport
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 5. Sync Repositories
|
|
134
|
+
|
|
135
|
+
Sync all cloned repositories:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
itcpr sync
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Run continuous sync (watches for changes):
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
itcpr sync --watch
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
With custom interval:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
itcpr sync --watch --interval 120 # Sync every 2 minutes
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 6. Logout
|
|
154
|
+
|
|
155
|
+
Clear stored credentials:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
itcpr logout
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Commands
|
|
162
|
+
|
|
163
|
+
### `itcpr login`
|
|
164
|
+
|
|
165
|
+
Starts device authentication flow. Opens browser to `cloud.itcpr.org/device` and polls for approval.
|
|
166
|
+
|
|
167
|
+
### `itcpr logout`
|
|
168
|
+
|
|
169
|
+
Revokes device token and clears local metadata.
|
|
170
|
+
|
|
171
|
+
### `itcpr status`
|
|
172
|
+
|
|
173
|
+
Shows:
|
|
174
|
+
- Logged-in user information
|
|
175
|
+
- Device ID
|
|
176
|
+
- Assigned repositories
|
|
177
|
+
- Local repositories with sync status
|
|
178
|
+
|
|
179
|
+
### `itcpr repos`
|
|
180
|
+
|
|
181
|
+
Lists all repositories assigned to this device with their clone status.
|
|
182
|
+
|
|
183
|
+
### `itcpr clone <repo>`
|
|
184
|
+
|
|
185
|
+
Clones a repository from GitHub using short-lived installation tokens.
|
|
186
|
+
|
|
187
|
+
Options:
|
|
188
|
+
- `--path, -p`: Custom local path for the repository
|
|
189
|
+
|
|
190
|
+
### `itcpr sync`
|
|
191
|
+
|
|
192
|
+
One-shot synchronization of all cloned repositories.
|
|
193
|
+
|
|
194
|
+
Options:
|
|
195
|
+
- `--watch, -w`: Run continuous sync loop
|
|
196
|
+
- `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
|
|
197
|
+
|
|
198
|
+
## How It Works
|
|
199
|
+
|
|
200
|
+
### Authentication
|
|
201
|
+
|
|
202
|
+
1. Device requests authentication code from backend
|
|
203
|
+
2. User approves device in browser at `cloud.itcpr.org/device`
|
|
204
|
+
3. Device token is stored securely in OS keyring
|
|
205
|
+
4. Token is used for all API requests
|
|
206
|
+
|
|
207
|
+
### Repository Sync
|
|
208
|
+
|
|
209
|
+
1. Fetches latest changes from remote
|
|
210
|
+
2. Detects uncommitted local changes
|
|
211
|
+
3. Commits local changes if any
|
|
212
|
+
4. Pulls remote changes with rebase
|
|
213
|
+
5. Pushes local commits if permitted
|
|
214
|
+
6. Aborts on merge conflicts (requires manual resolution)
|
|
215
|
+
|
|
216
|
+
### Security
|
|
217
|
+
|
|
218
|
+
- **No Personal Access Tokens**: Only uses backend-issued short-lived GitHub installation tokens
|
|
219
|
+
- **Device Tokens**: Revocable device authentication
|
|
220
|
+
- **OS Keyring**: Credentials stored securely using system keyring
|
|
221
|
+
- **Safe Git Operations**: Never force-pushes, detects conflicts
|
|
222
|
+
|
|
223
|
+
## Configuration
|
|
224
|
+
|
|
225
|
+
Configuration is stored in `~/.itcpr/config.toml`.
|
|
226
|
+
|
|
227
|
+
Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
|
|
228
|
+
|
|
229
|
+
## Troubleshooting
|
|
230
|
+
|
|
231
|
+
### "Not logged in" error
|
|
232
|
+
|
|
233
|
+
Run `itcpr login` to authenticate your device.
|
|
234
|
+
|
|
235
|
+
### "Repository not assigned" error
|
|
236
|
+
|
|
237
|
+
The repository must be assigned to your device in ITCPR Cloud. Contact an administrator.
|
|
238
|
+
|
|
239
|
+
### Merge conflicts
|
|
240
|
+
|
|
241
|
+
If a merge conflict is detected during sync:
|
|
242
|
+
1. Resolve conflicts manually in the repository
|
|
243
|
+
2. Commit the resolution
|
|
244
|
+
3. Run `itcpr sync` again
|
|
245
|
+
|
|
246
|
+
### Git command not found
|
|
247
|
+
|
|
248
|
+
Ensure Git is installed and available in your PATH:
|
|
249
|
+
```bash
|
|
250
|
+
git --version
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Token storage issues
|
|
254
|
+
|
|
255
|
+
On Linux, you may need to install a keyring backend:
|
|
256
|
+
```bash
|
|
257
|
+
# For GNOME
|
|
258
|
+
sudo apt-get install python3-keyring
|
|
259
|
+
|
|
260
|
+
# For KDE
|
|
261
|
+
sudo apt-get install python3-keyring kdewallet
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Development
|
|
265
|
+
|
|
266
|
+
### Project Structure
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
itcpr/
|
|
270
|
+
├── itcpr/
|
|
271
|
+
│ ├── __init__.py # Package initialization
|
|
272
|
+
│ ├── cli.py # CLI commands
|
|
273
|
+
│ ├── auth.py # Authentication
|
|
274
|
+
│ ├── api.py # API client
|
|
275
|
+
│ ├── gitops.py # Git operations
|
|
276
|
+
│ ├── sync.py # Sync logic
|
|
277
|
+
│ ├── config.py # Configuration
|
|
278
|
+
│ ├── storage.py # SQLite storage
|
|
279
|
+
│ └── utils.py # Utilities
|
|
280
|
+
├── setup.py # Setup script
|
|
281
|
+
├── pyproject.toml # Project metadata
|
|
282
|
+
└── README.md # This file
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Running Tests
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# Install in development mode
|
|
289
|
+
pip install -e .
|
|
290
|
+
|
|
291
|
+
# Run CLI
|
|
292
|
+
itcpr --help
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## API Endpoints
|
|
296
|
+
|
|
297
|
+
The CLI communicates with these backend endpoints:
|
|
298
|
+
|
|
299
|
+
- `POST /api/device/start` - Start device authentication
|
|
300
|
+
- `GET /api/device/poll` - Poll for authentication approval
|
|
301
|
+
- `POST /api/device/revoke` - Revoke device token
|
|
302
|
+
- `GET /api/agent/me` - Get device/user information
|
|
303
|
+
- `GET /api/agent/repos` - Get assigned repositories
|
|
304
|
+
- `POST /api/agent/token` - Get GitHub installation token
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
MIT License
|
|
309
|
+
|
|
310
|
+
## Support
|
|
311
|
+
|
|
312
|
+
For issues and questions, contact ITCPR support or open an issue on GitHub.
|
|
313
|
+
|
itcpr-2.0.3/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# ITCPR Agent
|
|
2
|
+
|
|
3
|
+
A production-ready CLI tool for syncing GitHub repositories from ITCPR Cloud to your local machine.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 Device-based authentication with cloud.itcpr.org
|
|
8
|
+
- 📦 Automatic repository synchronization
|
|
9
|
+
- 🔄 Manual or continuous sync modes
|
|
10
|
+
- 💾 Local SQLite database for metadata tracking
|
|
11
|
+
- 🔒 Secure token storage using OS keyring
|
|
12
|
+
- 🛡️ Safe git operations with conflict detection
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### From Source
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
cd cloud-cli
|
|
20
|
+
pip install -e .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Uninstall
|
|
24
|
+
|
|
25
|
+
To remove the CLI tool:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip uninstall itcpr
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Note:** This will remove the CLI tool but will **not** delete:
|
|
32
|
+
- Configuration files (`~/.itcpr/config.toml`)
|
|
33
|
+
- Local repository database (`~/.itcpr/repos.db`)
|
|
34
|
+
- Stored device tokens (in OS keyring)
|
|
35
|
+
|
|
36
|
+
To completely remove all data:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Uninstall the package
|
|
40
|
+
pip uninstall itcpr
|
|
41
|
+
|
|
42
|
+
# Remove configuration and data
|
|
43
|
+
rm -rf ~/.itcpr
|
|
44
|
+
|
|
45
|
+
# Remove stored tokens (OS keyring)
|
|
46
|
+
# On macOS: Use Keychain Access app to remove "itcpr" entries
|
|
47
|
+
# On Linux: Use your keyring manager (e.g., seahorse, kwallet)
|
|
48
|
+
# On Windows: Use Credential Manager
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Requirements
|
|
52
|
+
|
|
53
|
+
- Python 3.10+
|
|
54
|
+
- Git (system installation)
|
|
55
|
+
- Access to cloud.itcpr.org
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
### 1. Login
|
|
60
|
+
|
|
61
|
+
Authenticate your device with ITCPR Cloud:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
itcpr login
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This will:
|
|
68
|
+
- Open your browser to the device login page
|
|
69
|
+
- Display a device code
|
|
70
|
+
- Wait for approval
|
|
71
|
+
- Store credentials securely
|
|
72
|
+
|
|
73
|
+
### 2. Check Status
|
|
74
|
+
|
|
75
|
+
View your assigned repositories:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
itcpr status
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. List Repositories
|
|
82
|
+
|
|
83
|
+
See all repositories assigned to your device:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
itcpr repos
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. Clone a Repository
|
|
90
|
+
|
|
91
|
+
Clone a repository to your local machine:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
itcpr clone paperport-itcpr
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or specify a custom path:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
itcpr clone paperport-itcpr --path ~/projects/paperport
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 5. Sync Repositories
|
|
104
|
+
|
|
105
|
+
Sync all cloned repositories:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
itcpr sync
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Run continuous sync (watches for changes):
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
itcpr sync --watch
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
With custom interval:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
itcpr sync --watch --interval 120 # Sync every 2 minutes
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 6. Logout
|
|
124
|
+
|
|
125
|
+
Clear stored credentials:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
itcpr logout
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Commands
|
|
132
|
+
|
|
133
|
+
### `itcpr login`
|
|
134
|
+
|
|
135
|
+
Starts device authentication flow. Opens browser to `cloud.itcpr.org/device` and polls for approval.
|
|
136
|
+
|
|
137
|
+
### `itcpr logout`
|
|
138
|
+
|
|
139
|
+
Revokes device token and clears local metadata.
|
|
140
|
+
|
|
141
|
+
### `itcpr status`
|
|
142
|
+
|
|
143
|
+
Shows:
|
|
144
|
+
- Logged-in user information
|
|
145
|
+
- Device ID
|
|
146
|
+
- Assigned repositories
|
|
147
|
+
- Local repositories with sync status
|
|
148
|
+
|
|
149
|
+
### `itcpr repos`
|
|
150
|
+
|
|
151
|
+
Lists all repositories assigned to this device with their clone status.
|
|
152
|
+
|
|
153
|
+
### `itcpr clone <repo>`
|
|
154
|
+
|
|
155
|
+
Clones a repository from GitHub using short-lived installation tokens.
|
|
156
|
+
|
|
157
|
+
Options:
|
|
158
|
+
- `--path, -p`: Custom local path for the repository
|
|
159
|
+
|
|
160
|
+
### `itcpr sync`
|
|
161
|
+
|
|
162
|
+
One-shot synchronization of all cloned repositories.
|
|
163
|
+
|
|
164
|
+
Options:
|
|
165
|
+
- `--watch, -w`: Run continuous sync loop
|
|
166
|
+
- `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
|
|
167
|
+
|
|
168
|
+
## How It Works
|
|
169
|
+
|
|
170
|
+
### Authentication
|
|
171
|
+
|
|
172
|
+
1. Device requests authentication code from backend
|
|
173
|
+
2. User approves device in browser at `cloud.itcpr.org/device`
|
|
174
|
+
3. Device token is stored securely in OS keyring
|
|
175
|
+
4. Token is used for all API requests
|
|
176
|
+
|
|
177
|
+
### Repository Sync
|
|
178
|
+
|
|
179
|
+
1. Fetches latest changes from remote
|
|
180
|
+
2. Detects uncommitted local changes
|
|
181
|
+
3. Commits local changes if any
|
|
182
|
+
4. Pulls remote changes with rebase
|
|
183
|
+
5. Pushes local commits if permitted
|
|
184
|
+
6. Aborts on merge conflicts (requires manual resolution)
|
|
185
|
+
|
|
186
|
+
### Security
|
|
187
|
+
|
|
188
|
+
- **No Personal Access Tokens**: Only uses backend-issued short-lived GitHub installation tokens
|
|
189
|
+
- **Device Tokens**: Revocable device authentication
|
|
190
|
+
- **OS Keyring**: Credentials stored securely using system keyring
|
|
191
|
+
- **Safe Git Operations**: Never force-pushes, detects conflicts
|
|
192
|
+
|
|
193
|
+
## Configuration
|
|
194
|
+
|
|
195
|
+
Configuration is stored in `~/.itcpr/config.toml`.
|
|
196
|
+
|
|
197
|
+
Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
|
|
198
|
+
|
|
199
|
+
## Troubleshooting
|
|
200
|
+
|
|
201
|
+
### "Not logged in" error
|
|
202
|
+
|
|
203
|
+
Run `itcpr login` to authenticate your device.
|
|
204
|
+
|
|
205
|
+
### "Repository not assigned" error
|
|
206
|
+
|
|
207
|
+
The repository must be assigned to your device in ITCPR Cloud. Contact an administrator.
|
|
208
|
+
|
|
209
|
+
### Merge conflicts
|
|
210
|
+
|
|
211
|
+
If a merge conflict is detected during sync:
|
|
212
|
+
1. Resolve conflicts manually in the repository
|
|
213
|
+
2. Commit the resolution
|
|
214
|
+
3. Run `itcpr sync` again
|
|
215
|
+
|
|
216
|
+
### Git command not found
|
|
217
|
+
|
|
218
|
+
Ensure Git is installed and available in your PATH:
|
|
219
|
+
```bash
|
|
220
|
+
git --version
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Token storage issues
|
|
224
|
+
|
|
225
|
+
On Linux, you may need to install a keyring backend:
|
|
226
|
+
```bash
|
|
227
|
+
# For GNOME
|
|
228
|
+
sudo apt-get install python3-keyring
|
|
229
|
+
|
|
230
|
+
# For KDE
|
|
231
|
+
sudo apt-get install python3-keyring kdewallet
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Development
|
|
235
|
+
|
|
236
|
+
### Project Structure
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
itcpr/
|
|
240
|
+
├── itcpr/
|
|
241
|
+
│ ├── __init__.py # Package initialization
|
|
242
|
+
│ ├── cli.py # CLI commands
|
|
243
|
+
│ ├── auth.py # Authentication
|
|
244
|
+
│ ├── api.py # API client
|
|
245
|
+
│ ├── gitops.py # Git operations
|
|
246
|
+
│ ├── sync.py # Sync logic
|
|
247
|
+
│ ├── config.py # Configuration
|
|
248
|
+
│ ├── storage.py # SQLite storage
|
|
249
|
+
│ └── utils.py # Utilities
|
|
250
|
+
├── setup.py # Setup script
|
|
251
|
+
├── pyproject.toml # Project metadata
|
|
252
|
+
└── README.md # This file
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Running Tests
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# Install in development mode
|
|
259
|
+
pip install -e .
|
|
260
|
+
|
|
261
|
+
# Run CLI
|
|
262
|
+
itcpr --help
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## API Endpoints
|
|
266
|
+
|
|
267
|
+
The CLI communicates with these backend endpoints:
|
|
268
|
+
|
|
269
|
+
- `POST /api/device/start` - Start device authentication
|
|
270
|
+
- `GET /api/device/poll` - Poll for authentication approval
|
|
271
|
+
- `POST /api/device/revoke` - Revoke device token
|
|
272
|
+
- `GET /api/agent/me` - Get device/user information
|
|
273
|
+
- `GET /api/agent/repos` - Get assigned repositories
|
|
274
|
+
- `POST /api/agent/token` - Get GitHub installation token
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT License
|
|
279
|
+
|
|
280
|
+
## Support
|
|
281
|
+
|
|
282
|
+
For issues and questions, contact ITCPR support or open an issue on GitHub.
|
|
283
|
+
|
itcpr-2.0.3/itcpr/api.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""API client for cloud.itcpr.org."""
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from typing import List, Dict, Any, Optional
|
|
5
|
+
from .auth import Auth
|
|
6
|
+
from .utils import get_logger, print_error
|
|
7
|
+
|
|
8
|
+
logger = get_logger(__name__)
|
|
9
|
+
|
|
10
|
+
class APIClient:
|
|
11
|
+
"""Client for ITCPR Cloud API."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, auth: Auth):
|
|
14
|
+
self.auth = auth
|
|
15
|
+
self.api_base = auth.api_base
|
|
16
|
+
|
|
17
|
+
def _get_headers(self) -> Dict[str, str]:
|
|
18
|
+
"""Get request headers with authentication."""
|
|
19
|
+
headers = {"Content-Type": "application/json"}
|
|
20
|
+
token = self.auth.get_token()
|
|
21
|
+
if token:
|
|
22
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
23
|
+
return headers
|
|
24
|
+
|
|
25
|
+
def _request(self, method: str, endpoint: str, **kwargs) -> requests.Response:
|
|
26
|
+
"""Make authenticated API request."""
|
|
27
|
+
url = f"{self.api_base}{endpoint}"
|
|
28
|
+
headers = self._get_headers()
|
|
29
|
+
headers.update(kwargs.pop("headers", {}))
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
response = requests.request(method, url, headers=headers, timeout=30, **kwargs)
|
|
33
|
+
return response
|
|
34
|
+
except requests.RequestException as e:
|
|
35
|
+
logger.error(f"API request failed: {e}")
|
|
36
|
+
raise
|
|
37
|
+
|
|
38
|
+
def get_me(self) -> Dict[str, Any]:
|
|
39
|
+
"""Get current user/device information."""
|
|
40
|
+
response = self._request("GET", "/api/agent/me")
|
|
41
|
+
response.raise_for_status()
|
|
42
|
+
return response.json()
|
|
43
|
+
|
|
44
|
+
def get_repos(self) -> List[Dict[str, Any]]:
|
|
45
|
+
"""Get list of assigned repositories."""
|
|
46
|
+
response = self._request("GET", "/api/agent/repos")
|
|
47
|
+
response.raise_for_status()
|
|
48
|
+
data = response.json()
|
|
49
|
+
return data.get("repos", [])
|
|
50
|
+
|
|
51
|
+
def get_github_token(self, repo_name: Optional[str] = None) -> str:
|
|
52
|
+
"""Get short-lived GitHub installation token."""
|
|
53
|
+
payload = {}
|
|
54
|
+
if repo_name:
|
|
55
|
+
payload["repo"] = repo_name
|
|
56
|
+
|
|
57
|
+
response = self._request("POST", "/api/agent/token", json=payload)
|
|
58
|
+
response.raise_for_status()
|
|
59
|
+
data = response.json()
|
|
60
|
+
return data.get("token")
|
|
61
|
+
|
|
62
|
+
def validate_token(self) -> bool:
|
|
63
|
+
"""Validate current device token."""
|
|
64
|
+
try:
|
|
65
|
+
self.get_me()
|
|
66
|
+
return True
|
|
67
|
+
except requests.HTTPError as e:
|
|
68
|
+
if e.response.status_code == 401:
|
|
69
|
+
return False
|
|
70
|
+
raise
|
|
71
|
+
except Exception:
|
|
72
|
+
return False
|
|
73
|
+
|