Internal CLI tool for microservices management, infrastructure administration and monitoring with AWS Cognito authentication
Project description
CoreCLI
Internal CLI tool for microservices management, infrastructure administration and monitoring with AWS Cognito authentication.
Features
- 🔐 AWS Cognito Authentication - Secure authentication using PKCE (Proof Key for Code Exchange) flow
- 🚀 Microservices Management - Interact with internal microservices infrastructure
- 📊 Basic Monitoring - Monitor and manage microservices health
- 🔄 Token Management - Automatic token refresh and session handling
- 💻 CLI-First Design - Built with modern CLI best practices using Typer
Requirements
- Python 3.9 or higher
- AWS Cognito user pool configured with Hosted UI
- Valid AWS Cognito credentials
Installation
Via pip (Recommended)
pip install corclient
Via Homebrew (macOS/Linux)
# Add the tap
brew tap ProjectCORTeam/corcli https://github.com/ProjectCORTeam/corcli.git
# Install
brew install corclient
To update:
brew update && brew upgrade corclient
Development Installation
git clone https://github.com/ProjectCORTeam/corcli.git
cd corcli
pip install -e .
Quick Start
1. Login
Authenticate with AWS Cognito using the Hosted UI:
cor login
This will:
- Open your browser to the Cognito Hosted UI
- Start a local callback server
- Complete the PKCE flow
- Store tokens securely
Custom Redirect URI
If you need to redirect to a custom app scheme:
cor login --app-redirect myapp://callback
2. Check Authentication Status
View your current authentication details:
cor whoami
This displays:
- User information from the ID token
- Token expiration time
- Active session details
3. Refresh Tokens
Manually refresh your access tokens:
cor refresh
The CLI automatically refreshes tokens when needed, but you can manually trigger a refresh if required.
4. Logout
Clear local session and revoke tokens:
cor logout
This will:
- Revoke active tokens with Cognito
- Clear local token storage
- End your authentication session
5. Calling the GraphQL API (Amplify / AppSync)
After logging in, you can call the backend GraphQL API using the same session. Set the endpoint URL and use the graphql module from your code:
# Opcional: endpoint por defecto es https://api.cor-dev.com/graphql
export COR_GRAPHQL_URL="https://api.cor-dev.com/graphql"
From Python:
from corecli.graphql import graphql_request
# Ejemplo: listar equipos
result = graphql_request("""
query ListTeams {
listTeams {
items { id name description }
}
}
""")
print(result["data"]["listTeams"]["items"])
The client sends your Cognito id_token in the Authorization: Bearer <token> header and refreshes it automatically if expired.
Configuration
CoreCLI requires the following environment variables or configuration:
# AWS Cognito Configuration
COGNITO_DOMAIN=your-domain.auth.region.amazoncognito.com
COGNITO_CLIENT_ID=your-client-id
COGNITO_REDIRECT_URI=http://localhost:8080/callback
# GraphQL API (Amplify/AppSync) - opcional; default https://api.cor-dev.com/graphql
COR_GRAPHQL_URL=https://api.cor-dev.com/graphql
Configuration can be set via:
- Environment variables
- Configuration file (
.corecli/config) - Command-line arguments
Usage Examples
Basic Authentication Flow
# Login to Cognito
cor login
# Check who is logged in
cor whoami
# When done, logout
cor logout
Using with Custom Applications
# Login and redirect to custom app
cor login --app-redirect myapp://authenticated
# The CLI will handle authentication and redirect to your app
Command Reference
| Command | Description | Options |
|---|---|---|
cor login |
Authenticate with Cognito | --app-redirect, -r - Custom redirect URI |
cor whoami |
Show authenticated user info | None |
cor refresh |
Refresh authentication tokens | None |
cor logout |
End session and revoke tokens | None |
Development
Setup Development Environment
# Clone repository
git clone https://github.com/ProjectCORTeam/corcli.git
cd corcli
# Install in development mode with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks (optional but recommended)
pip install pre-commit
pre-commit install
# Run the CLI
cor --help
Development Tools
The project uses modern Python development tools:
- Ruff - Fast Python linter (replaces flake8, isort, and more)
- Black - Code formatter
- MyPy - Static type checker
- Pre-commit - Git hooks for automated checks
Running Checks Locally
# Run linting
make lint
# Fix linting issues automatically
make lint-fix
# Format code
make format
# Check formatting (without modifying)
make format-check
# Run type checking
make type-check
# Build and verify package
make build
# Run all checks
make all
# Clean build artifacts
make clean
Or manually:
# Linting
ruff check corecli/
# Formatting
black corecli/
# Type checking
mypy corecli/
# Build
python -m build
twine check dist/*
Project Structure
corecli/
├── corecli/
│ ├── __init__.py # Package initialization
│ ├── cli.py # CLI commands and interface
│ ├── auth.py # Authentication logic
│ ├── pkce.py # PKCE flow implementation
│ └── utils.py # Utility functions
├── pyproject.toml # Project metadata
├── setup.py # Package setup
└── README.md # This file
Security Considerations
- PKCE Flow: Uses the industry-standard PKCE flow for secure OAuth 2.0 authentication
- Token Storage: Tokens are stored securely in the local user directory
- Automatic Refresh: Access tokens are automatically refreshed before expiration
- Session Management: Proper logout flow revokes tokens server-side
Troubleshooting
Authentication Fails
If authentication fails, check:
- Cognito domain and client ID are correct
- Redirect URI is whitelisted in Cognito
- User pool has Hosted UI enabled
- Network connectivity to Cognito endpoints
Token Refresh Issues
If token refresh fails:
- Check that refresh token hasn't expired
- Verify Cognito client settings allow refresh tokens
- Try logging out and logging in again
Port Already in Use
If the callback server can't start:
# The default port (8080) might be in use
# Kill the process or configure a different port
Contributing
This is an internal tool for ProjectCOR Team. If you're a team member:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and ensure they pass all checks:
make lint make format make type-check make build
- Commit your changes using Conventional Commits:
git commit -m 'feat: add amazing feature' git commit -m 'fix: resolve authentication issue' git commit -m 'docs: update README'
- Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Quality Checks
All pull requests must pass:
- ✅ Ruff linting - Code quality and style checks
- ✅ Black formatting - Consistent code formatting
- ✅ MyPy type checking - Static type validation (warnings allowed)
- ✅ Package build - Successful package creation
- ✅ Twine validation - PyPI metadata verification
These checks run automatically on every release.
Versioning
We use Semantic Versioning via semantic-release. Versions are automatically generated based on commit messages following Conventional Commits.
Commit Message Format
feat:- New feature (minor version bump)fix:- Bug fix (patch version bump)feat!:orBREAKING CHANGE:- Breaking change (major version bump)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For internal support:
- Report issues: GitHub Issues
- Documentation: GitHub Wiki
- Releases: GitHub Releases
Authors
- Carlos Ferrer - Initial work - ProjectCOR Team
Built with ❤️ by the ProjectCOR Team
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file corclient-1.1.1.tar.gz.
File metadata
- Download URL: corclient-1.1.1.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cbe98ad0f61a0fe575b11e1f299940964a16f7bc340b8a33f8e9d5bf531ff04
|
|
| MD5 |
9449ea4ec62b983ee3cb8451f6fe1b27
|
|
| BLAKE2b-256 |
296148ff0734236524a96b97a681218e623c576757517fa62fb0bf48dc83c60c
|
Provenance
The following attestation bundles were made for corclient-1.1.1.tar.gz:
Publisher:
pypi-release.yaml on ProjectCORTeam/corcli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
corclient-1.1.1.tar.gz -
Subject digest:
0cbe98ad0f61a0fe575b11e1f299940964a16f7bc340b8a33f8e9d5bf531ff04 - Sigstore transparency entry: 950832266
- Sigstore integration time:
-
Permalink:
ProjectCORTeam/corcli@a2d54607c2138d6404fe757927abb751abfc639f -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/ProjectCORTeam
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yaml@a2d54607c2138d6404fe757927abb751abfc639f -
Trigger Event:
release
-
Statement type:
File details
Details for the file corclient-1.1.1-py3-none-any.whl.
File metadata
- Download URL: corclient-1.1.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1cf904a27cd78773c1e22f2d23ba85a2a5a327076aa49faf2720aa9fd8d2148
|
|
| MD5 |
4f9c9741b78c7ca4b24940f1870e7647
|
|
| BLAKE2b-256 |
69069ade04d74dd150b2220929d09c21d8e20ea853c8130f84e1629d1ef58ff9
|
Provenance
The following attestation bundles were made for corclient-1.1.1-py3-none-any.whl:
Publisher:
pypi-release.yaml on ProjectCORTeam/corcli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
corclient-1.1.1-py3-none-any.whl -
Subject digest:
e1cf904a27cd78773c1e22f2d23ba85a2a5a327076aa49faf2720aa9fd8d2148 - Sigstore transparency entry: 950832309
- Sigstore integration time:
-
Permalink:
ProjectCORTeam/corcli@a2d54607c2138d6404fe757927abb751abfc639f -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/ProjectCORTeam
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yaml@a2d54607c2138d6404fe757927abb751abfc639f -
Trigger Event:
release
-
Statement type: