Skip to content

Commit

Permalink
Rename azure_storage_table to azure_storage_table_service. Closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Subhajit97 committed Jan 27, 2021
1 parent d04ac04 commit 7426b20
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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}}'
Original file line number Diff line number Diff line change
@@ -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}}'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
select name, id
from azure.azure_storage_table
from azure.azure_storage_table_service
where id = '{{ output.resource_id.value }}'
Original file line number Diff line number Diff line change
@@ -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}}'
Original file line number Diff line number Diff line change
@@ -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}}'
2 changes: 1 addition & 1 deletion azure/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
},
Expand Down Expand Up @@ -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)

Expand All @@ -132,17 +118,20 @@ 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
}

//// 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 {
Expand All @@ -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
Expand All @@ -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
}
12 changes: 8 additions & 4 deletions azure/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7426b20

Please sign in to comment.