def create(self):
        logger.info(f"requesting quicksight create_analysis: {self.id}")
        quicksight_client = get_quicksight_client()

        try:
            response = quicksight_client.create_analysis(
                AwsAccountId=self.aws_account_id,
                AnalysisId=self.id,
                Name=self.name,
                Permissions=self._get_permissions(),
                SourceEntity=self._get_source_entity(),
            )
            logger.info(
                f"finished quicksight create_analysis for id:{self.id}, response: {response}"
            )
        except quicksight_client.exceptions.ResourceExistsException:
            response = quicksight_client.describe_analysis(
                AwsAccountId=self.aws_account_id, AnalysisId=self.id)
            response = response["Analysis"]
        except quicksight_client.exceptions.InvalidParameterValueException as exc:
            logger.error(str(exc))
            raise QuickSightFailure()

        self.arn = response["Arn"]
        return response
    def update_template_permissions(
            self,
            permission: TemplatePermissionType = TemplatePermissionType.PUBLIC,
            principal=None):
        quicksight_client = get_quicksight_client()

        logger.debug(
            f"requesting quicksight update_template_permissions, principal: {principal}"
        )
        if permission == TemplatePermissionType.PUBLIC:
            principal = "*"

        logger.info(
            f"requesting quicksight update_template_permissions: {self.id} from template"
        )
        response = quicksight_client.update_template_permissions(
            AwsAccountId=self.aws_account_id,
            TemplateId=self.id,
            GrantPermissions=[{
                "Principal": principal,
                "Actions": ["quicksight:DescribeTemplate"]
            }],
        )
        logger.info(
            f"finished quicksight update_template_permissions for id:{self.id} from template, response: {response}"
        )
        return response
    def create_from_analysis(self, analysis):
        logger.info(
            f"requesting quicksight create_template id {self.id} from analysis"
        )
        quicksight_client = get_quicksight_client()

        analysis_source_entity = SourceEntity(
            self.data_sets,
            analysis.arn,
            self.config_data,
            source_entity_type="SourceAnalysis")

        response = quicksight_client.create_template(
            AwsAccountId=self.aws_account_id,
            TemplateId=self.id,
            Name=self.name,
            Permissions=self._get_permissions(),
            SourceEntity=analysis_source_entity.get_source_entity(),
            VersionDescription="1",
        )
        logger.info(
            f"finished quicksight create_template id:{self.id} from analysis "
            f"response: {response}")

        self.arn = response["Arn"]
        return response
Exemple #4
0
    def create(self):
        logger.info(f"creating quicksight datasource id:{self.id}")
        quicksight_client = get_quicksight_client()

        data_source_parameters = {
            "AthenaParameters": {
                "WorkGroup": self.athena_workgroup
            }
        }

        try:
            response = quicksight_client.create_data_source(
                AwsAccountId=self.aws_account_id,
                DataSourceId=self.id,
                Name=self.name,
                Type="ATHENA",
                DataSourceParameters=data_source_parameters,
                Permissions=self._get_permissions(),
                SslProperties={"DisableSsl": False},
            )
            logger.info(
                f"finished creating quicksight datasource for id:{self.id}"
                f"response {response}")
        except quicksight_client.exceptions.ResourceExistsException:
            logger.info(f"datasource for id:{self.id} already exists")
            response = quicksight_client.describe_data_source(
                AwsAccountId=self.aws_account_id, DataSourceId=self.id)
            response = response["DataSource"]

        self.arn = response["Arn"]
        return response
Exemple #5
0
    def delete(self):
        logger.info(f"requesting quicksight delete_analysis id:{self.id}")
        quicksight_client = get_quicksight_client()

        response = quicksight_client.delete_analysis(AwsAccountId=self.aws_account_id, AnalysisId=self.id)
        logger.info(f"finished quicksight delete_analysis for id:{self.id} " f"response: {response}")
        return response
    def create_from_dashboard(self, dashboard):
        # TODO: REFACTOR+MERGE with create_from_analysis after testing to be the same
        logger.info(
            f"requesting quicksight create_template id {self.id} from dashboard"
        )
        quicksight_client = get_quicksight_client()

        analysis_source_entity = SourceEntity(
            self.data_sets,
            dashboard.arn,
            self.config_data,
            source_entity_type="SourceAnalysis")

        response = quicksight_client.create_template(
            AwsAccountId=self.aws_account_id,
            TemplateId=self.id,
            Name=self.name,
            Permissions=self._get_permissions(),
            SourceEntity=analysis_source_entity.get_source_entity(),
            VersionDescription="1",
        )
        logger.info(
            f"finished quicksight create_template id:{self.id} from analysis, response: {response}"
        )

        self.arn = response["Arn"]
        return response
    def _create_data_set(self, physical_table_map, logical_table_map):
        quicksight_client = get_quicksight_client()

        self._update_data_source_arn(physical_table_map)

        try:
            response = quicksight_client.create_data_set(
                AwsAccountId=self.aws_account_id,
                DataSetId=self.id,
                Name=self.name,
                Permissions=self._get_permissions(),
                PhysicalTableMap=physical_table_map,
                LogicalTableMap=logical_table_map,
                ImportMode='DIRECT_QUERY')
            logger.info(
                f"finished creating quicksight create_data_set id:{self.id}, "
                f"response:{response}")
        except quicksight_client.exceptions.ResourceExistsException:
            logger.info(f"dataset for id:{self.id} already exists")
            response = quicksight_client.describe_data_set(
                AwsAccountId=self.aws_account_id, DataSetId=self.id)
            response = response["DataSet"]
        except quicksight_client.exceptions.InvalidParameterValueException as exc:
            logger.error(str(exc))
            raise QuickSightFailure()

        self.arn = response['Arn']
        return response
    def delete(self):
        logger.info(f"deleting quicksight datasource id:{self.id}")
        quicksight_client = get_quicksight_client()

        response = quicksight_client.delete_data_source(AwsAccountId=self.aws_account_id, DataSourceId=self.id)
        logger.info(f"finished deleting quicksight datasource for id:{self.id} response:{response}")
        self.arn = response["Arn"]
        return response
Exemple #9
0
def get_quicksight_api_stubber():
    # stubber setup for pipeline
    global stubber_quicksight
    from util.helpers import get_quicksight_client
    quicksight_client = get_quicksight_client()
    if not stubber_quicksight:
        stubber_quicksight = Stubber(quicksight_client)
    return stubber_quicksight
    def delete(self):
        quicksight_client = get_quicksight_client()

        logger.info(f"requesting quicksight delete_template id:{self.id}")
        response = quicksight_client.delete_template(
            AwsAccountId=self.aws_account_id, TemplateId=self.id)
        logger.info(f"finished quicksight delete_template for id:{self.id} "
                    f"response: {response}")
        return response
    def delete(self):
        logger.info(f"requesting quicksight delete_dashboard id:{self.id}")
        quicksight_client = get_quicksight_client()

        response = quicksight_client.delete_dashboard(
            AwsAccountId=self.aws_account_id, DashboardId=self.id)
        logger.info(f"finished quicksight delete_dashboard for id:{self.id} "
                    f"response: {response}")

        return response
    def edition(self) -> str:
        qs = get_quicksight_client()
        try:
            settings = qs.describe_account_settings(
                AwsAccountId=get_aws_account_id())
            edition = settings.get("AccountSettings").get("Edition")
        except qs.exceptions.ResourceNotFoundException:
            edition = "DISABLED"

        logger.info("running with QuickSight %s" % edition)
        return edition
    def delete(self):
        logger.info(f"deleting quicksight dataset id:{self.id}")
        quicksight_client = get_quicksight_client()

        response = quicksight_client.delete_data_set(
            AwsAccountId=self.aws_account_id, DataSetId=self.id)
        logger.info(f"finished deleting quicksight dataset for id:{self.id}, "
                    f"response:{response}")

        self.arn = response['Arn']
        return response
 def update(self):
     quicksight_client = get_quicksight_client()
     quicksight_client.describe_data_source
     data_source_parameters = {"AthenaParameters": {"WorkGroup": self.athena_workgroup}}
     try:
         response = quicksight_client.update_data_source(
             AwsAccountId=self.aws_account_id,
             DataSourceId=self.id,
             Name=self.name,
             DataSourceParameters=data_source_parameters,
             SslProperties={"DisableSsl": False},
         )
     except quicksight_client.exceptions.ConflictException as exc:
         logger.debug(str(exc))
         response = response["DataSource"]
     return response
    def create(self):
        logger.info(f"requesting quicksight create_dashboard: {self.id}")
        quicksight_client = get_quicksight_client()

        response = quicksight_client.create_dashboard(
            AwsAccountId=self.aws_account_id,
            DashboardId=self.id,
            Name=self.name,
            Permissions=self._get_permissions(),
            SourceEntity=self._get_source_entity(),
            DashboardPublishOptions=self._get_dashboard_publish_options())
        logger.info(f"finished quicksight create_dashboard for id:{self.id} "
                    f"response: {response}")

        self.arn = response['Arn']
        return response
    def create_from_template(self, source_template_arn):
        quicksight_client = get_quicksight_client()

        logger.info(
            f"requesting quicksight create_template id:{self.id} from template"
        )
        source_entity = self._get_source_entity_using_template(
            source_template_arn)
        response = quicksight_client.create_template(
            AwsAccountId=self.aws_account_id,
            TemplateId=self.id,
            Name=self.name,
            Permissions=self._get_permissions(),
            SourceEntity=source_entity,
            VersionDescription="1",
        )
        logger.info(
            f"finished quicksight create_template id:{self.id} from template, response: {response}"
        )

        self.arn = response["Arn"]
        return response
Exemple #17
0
    def describe(self):
        call_type = self._get_type_for_boto3_call(self.type)
        id_parameter_name = self._get_id_name_for_boto3_call(self.type)

        operation = f"describe_{call_type}"
        logger.info(f"requesting quicksight {operation} id:{self.id}")
        obj = get_quicksight_client()

        if not (hasattr(obj, operation) and callable(getattr(obj, operation))):
            raise NotImplementedError(
                f"Internal error, 'QuickSight' client object has no callable function '{operation}'"
            )
        func = getattr(obj, operation)
        parameters = {
            "AwsAccountId": self.aws_account_id,
            id_parameter_name: self.id,
        }

        response = func(**parameters)
        logger.info(
            f"finished quicksight {operation} for id:{self.id} response: {response}"
        )
        return response
Exemple #18
0
    def _create_data_set(self, physical_table_map, logical_table_map,
                         column_groups_map):
        quicksight_client = get_quicksight_client()

        self._update_data_source_arn(physical_table_map)
        self._update_schema(physical_table_map)

        params = dict(
            AwsAccountId=self.aws_account_id,
            DataSetId=self.id,
            Name=self.name,
            Permissions=self._get_permissions(),
            PhysicalTableMap=physical_table_map,
            LogicalTableMap=logical_table_map,
            ImportMode="DIRECT_QUERY",
        )

        if self.sub_type in ["geo", "feed"]:
            params.update({"ColumnGroups": column_groups_map})
        try:
            logger.info(
                f"Params for creating the dataset for id:{self.id}:: {params}")
            response = quicksight_client.create_data_set(**params)
            logger.info(
                f"finished creating quicksight create_data_set id:{self.id}, response:{response}"
            )
        except quicksight_client.exceptions.ResourceExistsException:
            logger.info(f"dataset for id:{self.id} already exists")
            response = quicksight_client.describe_data_set(
                AwsAccountId=self.aws_account_id, DataSetId=self.id)
            response = response["DataSet"]
        except quicksight_client.exceptions.InvalidParameterValueException as exc:
            logger.error(str(exc))
            raise QuickSightFailure()

        self.arn = response["Arn"]
        return response
def test_get_quicksight_client():
    client = get_quicksight_client()
    assert "https://quicksight." in client.meta.endpoint_url