-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
326 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from cirrus.management.cli import cli | ||
|
||
|
||
def main() -> None: | ||
cli() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import sys | ||
from functools import wraps | ||
from typing import Any, Callable | ||
|
||
import boto3 | ||
import botocore.exceptions | ||
import click | ||
from cirrus.cli.utils import click as utils_click | ||
from cirrus.cli.utils import logging | ||
from cirrus.core import exceptions | ||
|
||
from cirrus.management import DESCRIPTION, NAME | ||
from cirrus.management.commands.deployments import list_deployments | ||
from cirrus.management.commands.manage import manage as manage_group | ||
from cirrus.management.commands.payload import payload as payload_group | ||
from cirrus.management.exceptions import SSOError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def handle_sso_error(func: Callable) -> Callable: | ||
@wraps(func) | ||
def wrapper(*args, **kwargs) -> Any: | ||
try: | ||
return func(*args, **kwargs) | ||
except ( | ||
botocore.exceptions.UnauthorizedSSOTokenError, | ||
botocore.exceptions.TokenRetrievalError, | ||
botocore.exceptions.SSOTokenLoadError, | ||
) as e: | ||
raise SSOError( | ||
"SSO session not authorized. Run `aws sso login` and try again.", | ||
) from e | ||
|
||
return wrapper | ||
|
||
|
||
class MainGroup(utils_click.AliasedShortMatchGroup): | ||
def invoke(self, *args, **kwargs) -> Any: | ||
try: | ||
return handle_sso_error(super().invoke)(*args, **kwargs) | ||
except exceptions.CirrusError as e: | ||
logger.error( | ||
e, | ||
exc_info=( | ||
e if logger.getEffectiveLevel() < logging.logging.INFO else False | ||
), | ||
) | ||
sys.exit(e.exit_code) | ||
|
||
|
||
@click.group( | ||
name=NAME, | ||
help=DESCRIPTION, | ||
cls=MainGroup, | ||
) | ||
@click.option( | ||
"--profile", | ||
help="AWS CLI profile name to use for session", | ||
) | ||
@click.pass_context | ||
@logging.verbosity() | ||
def cli(ctx, verbose, profile: str | None = None) -> None: | ||
ctx.obj = boto3.Session(profile_name=profile) | ||
|
||
|
||
cli.add_command(list_deployments) | ||
cli.add_command(manage_group) | ||
cli.add_command(payload_group) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
|
||
import boto3 | ||
import click | ||
|
||
from cirrus.management.deployment import Deployment | ||
from cirrus.management.utils.click import pass_session | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@click.command() | ||
@pass_session | ||
def list_deployments(session: boto3.Session) -> None: | ||
""" | ||
List all project deployments (accessible via current AWS role) | ||
""" | ||
for deployment in Deployment.yield_deployments(session=session): | ||
click.echo(f"{deployment.name} ({deployment.secret_arn})") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.