Skip to content

Commit

Permalink
Merge pull request #126 from aws-samples/origin/feature/logging
Browse files Browse the repository at this point in the history
Refactor code, implement logging
  • Loading branch information
megareez authored Jan 4, 2022
2 parents 1287d45 + 86a0f2f commit bb0b454
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 356 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*~
*#
*.swp
*.log

# Python specific
build/
Expand Down
9 changes: 1 addition & 8 deletions cid/builtin/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
# This plugin implements TAO dashboard

def onInit(cxt):
# STS context, extract user session -> detect Bubblewand
cxt.defaultAthenaDataSource = 'defaultDS'
cxt.defaultAthenaDatabase = 'defaultDS'
cxt.defaultAthenaTable = 'defaultDS'
pass
# This plugin implements Core dashboards
4 changes: 2 additions & 2 deletions cid/builtin/core/data/queries/shared/account_map.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE VIEW account_map AS
SELECT account_id,
concat(account_name, ': ', account_id) account_name
SELECT ${account_id} as account_id,
concat(${account_name}, ': ', ${account_id}) account_name
FROM ${metadata_table_name}
7 changes: 4 additions & 3 deletions cid/builtin/core/data/queries/shared/aws_accounts.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE OR REPLACE VIEW aws_accounts AS WITH m AS (
SELECT account_id,
account_name,
CREATE OR REPLACE VIEW aws_accounts AS WITH
m AS (
SELECT ${account_id} as account_id,
${account_name} as account_name,
email account_email_id
FROM ${metadata_table_name}
),
Expand Down
38 changes: 22 additions & 16 deletions cid/cli.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,75 @@
import logging
import click
from os import environ as env

from cid import Cid

logger = logging.getLogger(__name__)

version = '1.0 Beta'
prog_name="CLOUD INTELLIGENCE DASHBOARDS (CID) CLI"
print(f'{prog_name} {version}\n')

App = Cid()

@click.group()
@click.option('--profile_name', help='AWS Profile name to use', default=env.get('AWS_PROFILE'))
@click.option('--region_name', help="AWS Region (default:'us-east-1')", default=env.get('AWS_REGION', env.get('AWS_DEFAULT_REGION', 'us-east-1')))
@click.option('--aws_access_key_id', help='', default=env.get('AWS_ACCESS_KEY_ID'))
@click.option('--aws_secret_access_key', help='', default=env.get('AWS_SECRET_ACCESS_KEY'))
@click.option('--aws_session_token', help='', default=env.get('AWS_SESSION_TOKEN'))
@click.option('--profile_name', help='AWS Profile name to use', default=None)
@click.option('--region_name', help="AWS Region (default:'us-east-1')", default=None)
@click.option('--aws_access_key_id', help='', default=None)
@click.option('--aws_secret_access_key', help='', default=None)
@click.option('--aws_session_token', help='', default=None)
@click.option('-v', '--verbose', count=True)
@click.pass_context
def main(ctx, **kwargs):
logger.setLevel(logger.getEffectiveLevel()-10*kwargs.pop('verbose'))
params = {
'verbose': kwargs.pop('verbose'),
}
App = Cid(**params)
App.run(**kwargs)
ctx.obj = App


@main.command()
def map():
@click.pass_obj
def map(App):
"""Create account mapping"""
App.map()


@main.command()
def deploy():
@click.pass_obj
def deploy(App):
"""Deploy Dashboard"""

App.deploy()


@main.command()
@click.option('--dashboard-id', help='QuickSight dashboard id', default=None)
def status(**kwargs):
@click.pass_obj
def status(App, **kwargs):
"""Show Dashboard status"""

App.status(dashboard_id=kwargs.get('dashboard_id'))

@main.command()
@click.option('--dashboard-id', help='QuickSight dashboard id', default=None)
def delete(**kwargs):
@click.pass_obj
def delete(App, **kwargs):
"""Delete Dashboard"""

App.delete(dashboard_id=kwargs.get('dashboard_id'))

@main.command()
@click.option('--dashboard-id', help='QuickSight dashboard id', default=None)
@click.option('--force', help='Allow force update', is_flag=True)
def update(**kwargs):
@click.pass_obj
def update(App, **kwargs):
"""Update Dashboard"""

App.update(dashboard_id=kwargs.get('dashboard_id'), force=kwargs.get('force'))


@main.command()
@click.option('--dashboard-id', help='QuickSight dashboard id', default=None)
def open(**kwargs):
@click.pass_obj
def open(App, **kwargs):
"""Open Dashboard in browser"""

App.open(dashboard_id=kwargs.get('dashboard_id'))
Expand Down
Loading

0 comments on commit bb0b454

Please sign in to comment.