|
| 1 | +package aws |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 7 | + "github.com/aws/aws-sdk-go-v2/service/quicksight" |
| 8 | + |
| 9 | + "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" |
| 10 | + "github.com/turbot/steampipe-plugin-sdk/v5/plugin" |
| 11 | + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" |
| 12 | +) |
| 13 | + |
| 14 | +//// TABLE DEFINITION |
| 15 | + |
| 16 | +func tableAwsQuickSightAccountSetting(_ context.Context) *plugin.Table { |
| 17 | + return &plugin.Table{ |
| 18 | + Name: "aws_quicksight_account_setting", |
| 19 | + Description: "AWS QuickSight Account Setting", |
| 20 | + List: &plugin.ListConfig{ |
| 21 | + Hydrate: listAwsQuickSightAccountSettings, |
| 22 | + IgnoreConfig: &plugin.IgnoreConfig{ |
| 23 | + ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), |
| 24 | + }, |
| 25 | + KeyColumns: []*plugin.KeyColumn{ |
| 26 | + {Name: "region", Require: plugin.Required}, |
| 27 | + {Name: "quicksight_account_id", Require: plugin.Optional}, |
| 28 | + }, |
| 29 | + Tags: map[string]string{"service": "quicksight", "action": "DescribeAccountSettings"}, |
| 30 | + }, |
| 31 | + GetMatrixItemFunc: SupportedRegionMatrix(AWS_QUICKSIGHT_SERVICE_ID), |
| 32 | + Columns: awsRegionalColumns([]*plugin.Column{ |
| 33 | + { |
| 34 | + Name: "account_name", |
| 35 | + Description: "The account name displayed for the account.", |
| 36 | + Type: proto.ColumnType_STRING, |
| 37 | + Transform: transform.FromField("AccountSettings.AccountName"), |
| 38 | + }, |
| 39 | + // As we have already a column "account_id" as a common column for all the tables, we have renamed the column to "quicksight_account_id" |
| 40 | + { |
| 41 | + Name: "quicksight_account_id", |
| 42 | + Description: "The ID for the Amazon Web Services account that contains the settings that you want to list.", |
| 43 | + Type: proto.ColumnType_STRING, |
| 44 | + Transform: transform.FromQual("quicksight_account_id"), |
| 45 | + }, |
| 46 | + { |
| 47 | + Name: "edition", |
| 48 | + Description: "The edition of Amazon QuickSight that you're currently subscribed to: Enterprise edition or Standard edition.", |
| 49 | + Type: proto.ColumnType_STRING, |
| 50 | + Transform: transform.FromField("AccountSettings.Edition"), |
| 51 | + }, |
| 52 | + { |
| 53 | + Name: "default_namespace", |
| 54 | + Description: "The default namespace for this AWS account.", |
| 55 | + Type: proto.ColumnType_STRING, |
| 56 | + Transform: transform.FromField("AccountSettings.DefaultNamespace"), |
| 57 | + }, |
| 58 | + { |
| 59 | + Name: "notification_email", |
| 60 | + Description: "The email address that QuickSight uses to send notifications.", |
| 61 | + Type: proto.ColumnType_STRING, |
| 62 | + Transform: transform.FromField("AccountSettings.NotificationEmail"), |
| 63 | + }, |
| 64 | + { |
| 65 | + Name: "termination_protection_enabled", |
| 66 | + Description: "A boolean value that indicates whether termination protection is enabled.", |
| 67 | + Type: proto.ColumnType_BOOL, |
| 68 | + Transform: transform.FromField("AccountSettings.TerminationProtectionEnabled"), |
| 69 | + }, |
| 70 | + { |
| 71 | + Name: "public_sharing_enabled", |
| 72 | + Description: "A boolean value that indicates whether public sharing is enabled.", |
| 73 | + Type: proto.ColumnType_BOOL, |
| 74 | + Transform: transform.FromField("AccountSettings.PublicSharingEnabled"), |
| 75 | + }, |
| 76 | + |
| 77 | + // Standard columns |
| 78 | + { |
| 79 | + Name: "title", |
| 80 | + Description: resourceInterfaceDescription("title"), |
| 81 | + Type: proto.ColumnType_STRING, |
| 82 | + Transform: transform.FromField("AccountSettings.AccountName"), |
| 83 | + }, |
| 84 | + }), |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +//// LIST FUNCTION |
| 89 | + |
| 90 | +func listAwsQuickSightAccountSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { |
| 91 | + // Create client |
| 92 | + svc, err := QuickSightClient(ctx, d) |
| 93 | + if err != nil { |
| 94 | + plugin.Logger(ctx).Error("aws_quicksight_account_setting.listAwsQuickSightAccountSettings", "connection_error", err) |
| 95 | + return nil, err |
| 96 | + } |
| 97 | + |
| 98 | + accountId := d.EqualsQuals["quicksight_account_id"].GetStringValue() |
| 99 | + // Get AWS Account ID |
| 100 | + commonData, err := getCommonColumns(ctx, d, h) |
| 101 | + if err != nil { |
| 102 | + return nil, err |
| 103 | + } |
| 104 | + commonColumnData := commonData.(*awsCommonColumnData) |
| 105 | + |
| 106 | + if accountId == "" { |
| 107 | + accountId = commonColumnData.AccountId |
| 108 | + } |
| 109 | + |
| 110 | + // Build the params |
| 111 | + params := &quicksight.DescribeAccountSettingsInput{ |
| 112 | + AwsAccountId: aws.String(accountId), |
| 113 | + } |
| 114 | + |
| 115 | + // Get call |
| 116 | + data, err := svc.DescribeAccountSettings(ctx, params) |
| 117 | + if err != nil { |
| 118 | + plugin.Logger(ctx).Error("aws_quicksight_account_setting.listAwsQuickSightAccountSettings", "api_error", err) |
| 119 | + return nil, err |
| 120 | + } |
| 121 | + |
| 122 | + d.StreamListItem(ctx, data) |
| 123 | + |
| 124 | + return nil, nil |
| 125 | +} |
0 commit comments