From 7426b2001c90ba64a43f547877f778b1725ec5e7 Mon Sep 17 00:00:00 2001 From: Subhajit Kumar Mondal Date: Wed, 27 Jan 2021 15:55:23 +0530 Subject: [PATCH] Rename azure_storage_table to azure_storage_table_service. Closes #9 --- .../dependencies.txt | 0 .../test-get-expected.json | 0 .../test-get-query.sql | 2 +- .../test-hydrate-expected.json | 0 .../test-hydrate-query.sql | 2 +- .../test-list-expected.json | 0 .../test-list-query.sql | 2 +- .../test-not-found-expected.json | 0 .../test-not-found-query.sql | 2 +- .../test-turbot-expected.json | 0 .../test-turbot-query.sql | 2 +- .../variables.json | 0 .../variables.tf | 0 azure/plugin.go | 2 +- ...o => table_azure_storage_table_service.go} | 49 +++++++------------ azure/utils.go | 12 +++-- 16 files changed, 33 insertions(+), 40 deletions(-) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/dependencies.txt (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-get-expected.json (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-get-query.sql (78%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-hydrate-expected.json (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-hydrate-query.sql (78%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-list-expected.json (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-list-query.sql (60%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-not-found-expected.json (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-not-found-query.sql (73%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-turbot-expected.json (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/test-turbot-query.sql (73%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/variables.json (100%) rename azure-test/tests/{azure_storage_table => azure_storage_table_service}/variables.tf (100%) rename azure/{table_azure_storage_table.go => table_azure_storage_table_service.go} (72%) diff --git a/azure-test/tests/azure_storage_table/dependencies.txt b/azure-test/tests/azure_storage_table_service/dependencies.txt similarity index 100% rename from azure-test/tests/azure_storage_table/dependencies.txt rename to azure-test/tests/azure_storage_table_service/dependencies.txt diff --git a/azure-test/tests/azure_storage_table/test-get-expected.json b/azure-test/tests/azure_storage_table_service/test-get-expected.json similarity index 100% rename from azure-test/tests/azure_storage_table/test-get-expected.json rename to azure-test/tests/azure_storage_table_service/test-get-expected.json diff --git a/azure-test/tests/azure_storage_table/test-get-query.sql b/azure-test/tests/azure_storage_table_service/test-get-query.sql similarity index 78% rename from azure-test/tests/azure_storage_table/test-get-query.sql rename to azure-test/tests/azure_storage_table_service/test-get-query.sql index 1e0b4169..63a4370c 100644 --- a/azure-test/tests/azure_storage_table/test-get-query.sql +++ b/azure-test/tests/azure_storage_table_service/test-get-query.sql @@ -1,3 +1,3 @@ select name, id, storage_account_name, type, cors_rules -from azure.azure_storage_table +from azure.azure_storage_table_service where resource_group = '{{resourceName}}' and storage_account_name = '{{resourceName}}' \ No newline at end of file diff --git a/azure-test/tests/azure_storage_table/test-hydrate-expected.json b/azure-test/tests/azure_storage_table_service/test-hydrate-expected.json similarity index 100% rename from azure-test/tests/azure_storage_table/test-hydrate-expected.json rename to azure-test/tests/azure_storage_table_service/test-hydrate-expected.json diff --git a/azure-test/tests/azure_storage_table/test-hydrate-query.sql b/azure-test/tests/azure_storage_table_service/test-hydrate-query.sql similarity index 78% rename from azure-test/tests/azure_storage_table/test-hydrate-query.sql rename to azure-test/tests/azure_storage_table_service/test-hydrate-query.sql index 1e0b4169..63a4370c 100644 --- a/azure-test/tests/azure_storage_table/test-hydrate-query.sql +++ b/azure-test/tests/azure_storage_table_service/test-hydrate-query.sql @@ -1,3 +1,3 @@ select name, id, storage_account_name, type, cors_rules -from azure.azure_storage_table +from azure.azure_storage_table_service where resource_group = '{{resourceName}}' and storage_account_name = '{{resourceName}}' \ No newline at end of file diff --git a/azure-test/tests/azure_storage_table/test-list-expected.json b/azure-test/tests/azure_storage_table_service/test-list-expected.json similarity index 100% rename from azure-test/tests/azure_storage_table/test-list-expected.json rename to azure-test/tests/azure_storage_table_service/test-list-expected.json diff --git a/azure-test/tests/azure_storage_table/test-list-query.sql b/azure-test/tests/azure_storage_table_service/test-list-query.sql similarity index 60% rename from azure-test/tests/azure_storage_table/test-list-query.sql rename to azure-test/tests/azure_storage_table_service/test-list-query.sql index 6e49a8d7..e031fa7a 100644 --- a/azure-test/tests/azure_storage_table/test-list-query.sql +++ b/azure-test/tests/azure_storage_table_service/test-list-query.sql @@ -1,3 +1,3 @@ select name, id -from azure.azure_storage_table +from azure.azure_storage_table_service where id = '{{ output.resource_id.value }}' \ No newline at end of file diff --git a/azure-test/tests/azure_storage_table/test-not-found-expected.json b/azure-test/tests/azure_storage_table_service/test-not-found-expected.json similarity index 100% rename from azure-test/tests/azure_storage_table/test-not-found-expected.json rename to azure-test/tests/azure_storage_table_service/test-not-found-expected.json diff --git a/azure-test/tests/azure_storage_table/test-not-found-query.sql b/azure-test/tests/azure_storage_table_service/test-not-found-query.sql similarity index 73% rename from azure-test/tests/azure_storage_table/test-not-found-query.sql rename to azure-test/tests/azure_storage_table_service/test-not-found-query.sql index e7c63038..6434d369 100644 --- a/azure-test/tests/azure_storage_table/test-not-found-query.sql +++ b/azure-test/tests/azure_storage_table_service/test-not-found-query.sql @@ -1,3 +1,3 @@ select name, id -from azure.azure_storage_table +from azure.azure_storage_table_service where resource_group = '{{resourceName}}' and storage_account_name = 'dummy-{{resourceName}}' \ No newline at end of file diff --git a/azure-test/tests/azure_storage_table/test-turbot-expected.json b/azure-test/tests/azure_storage_table_service/test-turbot-expected.json similarity index 100% rename from azure-test/tests/azure_storage_table/test-turbot-expected.json rename to azure-test/tests/azure_storage_table_service/test-turbot-expected.json diff --git a/azure-test/tests/azure_storage_table/test-turbot-query.sql b/azure-test/tests/azure_storage_table_service/test-turbot-query.sql similarity index 73% rename from azure-test/tests/azure_storage_table/test-turbot-query.sql rename to azure-test/tests/azure_storage_table_service/test-turbot-query.sql index cc881954..b2b28ed0 100644 --- a/azure-test/tests/azure_storage_table/test-turbot-query.sql +++ b/azure-test/tests/azure_storage_table_service/test-turbot-query.sql @@ -1,3 +1,3 @@ select title, akas -from azure.azure_storage_table +from azure.azure_storage_table_service where resource_group = '{{resourceName}}' and storage_account_name = '{{resourceName}}' \ No newline at end of file diff --git a/azure-test/tests/azure_storage_table/variables.json b/azure-test/tests/azure_storage_table_service/variables.json similarity index 100% rename from azure-test/tests/azure_storage_table/variables.json rename to azure-test/tests/azure_storage_table_service/variables.json diff --git a/azure-test/tests/azure_storage_table/variables.tf b/azure-test/tests/azure_storage_table_service/variables.tf similarity index 100% rename from azure-test/tests/azure_storage_table/variables.tf rename to azure-test/tests/azure_storage_table_service/variables.tf diff --git a/azure/plugin.go b/azure/plugin.go index b5dcbb23..16115f01 100644 --- a/azure/plugin.go +++ b/azure/plugin.go @@ -54,7 +54,7 @@ func Plugin(ctx context.Context) *plugin.Plugin { "azure_storage_account": tableAzureStorageAccount(ctx), "azure_storage_blob": tableAzureStorageBlob(ctx), "azure_storage_queue": tableAzureStorageQueue(ctx), - "azure_storage_table": tableAzureStorageTable(ctx), + "azure_storage_table_service": tableAzureStorageTableService(ctx), "azure_subnet": tableAzureSubnet(ctx), "azure_virtual_network": tableAzureVirtualNetwork(ctx), }, diff --git a/azure/table_azure_storage_table.go b/azure/table_azure_storage_table_service.go similarity index 72% rename from azure/table_azure_storage_table.go rename to azure/table_azure_storage_table_service.go index 8f47b954..f004fb26 100644 --- a/azure/table_azure_storage_table.go +++ b/azure/table_azure_storage_table_service.go @@ -10,7 +10,7 @@ import ( "github.com/turbot/steampipe-plugin-sdk/plugin" ) -type tableInfo = struct { +type tableServiceInfo = struct { Table storage.TableServiceProperties Account *string Name *string @@ -20,29 +20,28 @@ type tableInfo = struct { //// TABLE DEFINITION //// -func tableAzureStorageTable(_ context.Context) *plugin.Table { +func tableAzureStorageTableService(_ context.Context) *plugin.Table { return &plugin.Table{ - Name: "azure_storage_table", - Description: "Azure Storage Table", + Name: "azure_storage_table_service", + Description: "Azure Storage Table Service", Get: &plugin.GetConfig{ KeyColumns: plugin.AllColumns([]string{"storage_account_name", "resource_group"}), - ItemFromKey: tableDataFromKey, - Hydrate: getStorageTable, + Hydrate: getStorageTableService, ShouldIgnoreError: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound"}), }, List: &plugin.ListConfig{ ParentHydrate: listStorageAccounts, - Hydrate: listStorageTables, + Hydrate: listStorageTableServices, }, Columns: []*plugin.Column{ { Name: "name", Type: proto.ColumnType_STRING, - Description: "The friendly name that identifies the table", + Description: "The friendly name that identifies the table service", }, { Name: "id", - Description: "Contains ID to identify a table uniquely", + Description: "Contains ID to identify a table service uniquely", Type: proto.ColumnType_STRING, Transform: transform.FromField("Table.ID"), }, @@ -99,22 +98,9 @@ func tableAzureStorageTable(_ context.Context) *plugin.Table { } } -//// BUILD HYDRATE INPUT //// - -func tableDataFromKey(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { - quals := d.KeyColumnQuals - resourceGroup := quals["resource_group"].GetStringValue() - accountName := quals["storage_account_name"].GetStringValue() - item := &tableInfo{ - Account: &accountName, - ResourceGroup: &resourceGroup, - } - return item, nil -} - //// FETCH FUNCTIONS //// -func listStorageTables(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { +func listStorageTableServices(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { // Get the details of storage account account := h.Item.(*storageAccountInfo) @@ -132,8 +118,8 @@ func listStorageTables(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra return nil, err } - for _, table := range *result.Value { - d.StreamLeafListItem(ctx, &tableInfo{table, account.Name, table.Name, account.ResourceGroup, account.Account.Location}) + for _, tableService := range *result.Value { + d.StreamLeafListItem(ctx, &tableServiceInfo{tableService, account.Name, tableService.Name, account.ResourceGroup, account.Account.Location}) } return nil, err @@ -141,8 +127,11 @@ func listStorageTables(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra //// HYDRATE FUNCTIONS //// -func getStorageTable(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - tableData := h.Item.(*tableInfo) +func getStorageTableService(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + plugin.Logger(ctx).Trace("getStorageTableService") + + resourceGroup := d.KeyColumnQuals["resource_group"].GetStringValue() + accountName := d.KeyColumnQuals["storage_account_name"].GetStringValue() session, err := GetNewSession(ctx, d.ConnectionManager, "MANAGEMENT") if err != nil { @@ -153,7 +142,7 @@ func getStorageTable(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrate storageClient := storage.NewAccountsClient(subscriptionID) storageClient.Authorizer = session.Authorizer - storageDetails, err := storageClient.GetProperties(context.Background(), *tableData.ResourceGroup, *tableData.Account, "") + storageDetails, err := storageClient.GetProperties(context.Background(), resourceGroup, accountName, "") if err != nil { return nil, err @@ -164,10 +153,10 @@ func getStorageTable(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrate tableClient := storage.NewTableServicesClient(subscriptionID) tableClient.Authorizer = session.Authorizer - op, err := tableClient.GetServiceProperties(context.Background(), *tableData.ResourceGroup, *tableData.Account) + op, err := tableClient.GetServiceProperties(context.Background(), resourceGroup, accountName) if err != nil { return nil, err } - return &tableInfo{op, tableData.Account, op.Name, tableData.ResourceGroup, location}, nil + return &tableServiceInfo{op, &accountName, op.Name, &resourceGroup, location}, nil } diff --git a/azure/utils.go b/azure/utils.go index d79d191e..f9a154ba 100644 --- a/azure/utils.go +++ b/azure/utils.go @@ -35,12 +35,16 @@ func extractResourceGroupFromID(ctx context.Context, d *transform.TransformData) } func convertDateToTime(ctx context.Context, d *transform.TransformData) (interface{}, error) { - dateValue := d.Value + dateValue := d.Value.(*date.Time) - // convert from *date.Time to *date.Time - timeValue := dateValue.(*date.Time).ToTime().Format(time.RFC3339) + if dateValue != nil { + // convert from *date.Time to *date.Time + timeValue := dateValue.ToTime().Format(time.RFC3339) - return timeValue, nil + return timeValue, nil + } + + return nil, nil } func resourceInterfaceDescription(key string) string {