How common-fate/granted works
Based on our analysis of the file tree and the README, it’s clear that Granted is a Go-based CLI tool whose primary purpose is to simplify cloud access—primarily for AWS—by managing role assumption, credential caching, and even launching multiple cloud accounts simultaneously in the browser. In addition to its CLI capabilities, the project includes a modular layout with packages dedicated to browser integration, secure storage, cloud API interactions, and configuration.
Main Components
• CLI/Entry Points: Represent the command entry files under the “cmd” directory. There are at least two main entry points:
– The core “granted” CLI (cmd/granted) and
– Testing and auxiliary commands (cmd/testing).
• Core Business Logic and Libraries: Represent the many sub-packages in “pkg” (e.g., pkg/assume, pkg/granted, pkg/browser, pkg/cfaws, pkg/securestorage). These encapsulate the various functionalities such as:
– Role assumption and SSO logic (pkg/assume, pkg/granted/sso.go)
– AWS integration (pkg/cfaws)
– Browser integration for multi-account access (pkg/browser)
– Secure storage operations (pkg/securestorage)
– Caching and configuration (pkg/cache, pkg/config, pkg/cfcfg)
• Build and Versioning: The “internal/build” package handles version and configuration details that can be shown as part of the build process.
• Testing/Utilities: Acknowledge that there are helper scripts (in the “scripts” folder) and a “cmd/testing” directory for integration or system testing.
• External Dependencies and CI/CD: Include GitHub Actions workflows (from the “.github/workflows” directory) as an external process for continuous integration and testing.
Relationships and Data Flow
• The CLI layer (cmd directories) receives user input and then calls into the core libraries (pkg/*) for business logic.
• For role assumption and credential management, the CLI routes commands to modules in pkg/assume and pkg/granted, which further communicate with the AWS integration modules in pkg/cfaws.
• Browser interactions, to open multiple cloud roles simultaneously, are handled in pkg/browser and are triggered by commands from cmd.
• Secure storage for credentials and SSO tokens (in pkg/securestorage) works hand-in-hand with the authentication and caching modules.
• The caching system (pkg/cache) captures temporary state that might be used by both the CLI and the auto-sync mechanisms (pkg/autosync).
Architectural Patterns
• Separation of Concerns: Notice the clear separation between command-line interface logic, business logic, and platform-dependent integration.
• Modular Design: Each pkg sub-directory encapsulates a distinct domain (e.g., AWS API integration, browser detection, credential management) so that changes in one module do not directly affect the others.
• Extensibility: The project’s modular structure and the presence of hooks (e.g., pkg/hook/accessrequesthook) suggest that it’s designed for future extension and integration with additional cloud providers or additional features.
Incorporate Relevant Technology and Tools
• GitHub Actions: Represent CI/CD pipelines and workflows from the “.github” directory.
• Build Tools: Makefile and the “internal/build” package denote the build/version control process.
• Configuration Management: Include the configuration components (from pkg/config, pkg/cfcfg) as they are crucial for aligning different system parts.