#!/usr/bin/env python3
# Copyright (c) 2020 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com
#

from czid import czrn

from src.api.v4_connections import get_connection_for_shell
from src.features.connections.shell import get_aws_credentials_for_account
from src.lib.cwm import get_cwm_v2_for_czrn
from src.utils.aws import get_aws_session

CZOPS_BUCKET = "cz-internal-ops-931830253929"


def get_metrics(aws_session, arguments):
    czrn_target = arguments.get("--czrn")
    profile = arguments.get("--profile")

    print(f"Requesting metrics for {czrn_target}")
    service, region, cloud_account_id, resource_type, cloud_local_id = czrn.extract_all_components(czrn_target)
    connection = get_connection_for_shell(cloud_account_id)

    assumed_credentials = get_aws_credentials_for_account(connection, aws_session, "resource_owner_role_arn")
    aws_session = get_aws_session(profile_name=profile, region_name=region, aws_credentials=assumed_credentials)

    print(aws_session)
    results = get_cwm_v2_for_czrn(czrn_target, aws_session, days=1)
    print(results)
