Skip to content

Commit

Permalink
Add lifecycle_management_policy details for storage account. Closes #146
Browse files Browse the repository at this point in the history
 (#155)
  • Loading branch information
Subhajit97 authored Jun 30, 2021
1 parent 0ffdb44 commit 241de87
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
49 changes: 48 additions & 1 deletion azure/table_azure_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ func tableAzureStorageAccount(_ context.Context) *plugin.Table {
Type: proto.ColumnType_JSON,
Transform: transform.FromField("Account.AccountProperties.Encryption.Services"),
},
{
Name: "lifecycle_management_policy",
Description: "The managementpolicy associated with the specified storage account.",
Type: proto.ColumnType_JSON,
Hydrate: getAzureStorageAccountLifecycleManagementPolicy,
Transform: transform.FromValue(),
},
{
Name: "network_ip_rules",
Description: "A list of IP ACL rules.",
Expand All @@ -364,7 +371,7 @@ func tableAzureStorageAccount(_ context.Context) *plugin.Table {
Transform: transform.FromField("Account.AccountProperties.NetworkRuleSet.VirtualNetworkRules"),
},

// Standard columns
// Steampipe standard columns
{
Name: "title",
Description: ColumnDescriptionTitle,
Expand All @@ -383,6 +390,8 @@ func tableAzureStorageAccount(_ context.Context) *plugin.Table {
Type: proto.ColumnType_JSON,
Transform: transform.FromField("Account.ID").Transform(idToAkas),
},

// Azure standard columns
{
Name: "region",
Description: ColumnDescriptionRegion,
Expand Down Expand Up @@ -459,6 +468,44 @@ func getStorageAccount(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra
return &storageAccountInfo{op, op.Name, &resourceGroup}, nil
}

func getAzureStorageAccountLifecycleManagementPolicy(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
accountData := h.Item.(*storageAccountInfo)

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

storageClient := storage.NewManagementPoliciesClient(subscriptionID)
storageClient.Authorizer = session.Authorizer

op, err := storageClient.Get(ctx, *accountData.ResourceGroup, *accountData.Name)
if err != nil {
if strings.Contains(err.Error(), "ManagementPolicyNotFound") {
return nil, nil
}
return nil, err
}

// Direct assignment returns ManagementPolicyProperties only
objectMap := make(map[string]interface{})
if op.ID != nil {
objectMap["id"] = op.ID
}
if op.Name != nil {
objectMap["name"] = op.Name
}
if op.Type != nil {
objectMap["type"] = op.Type
}
if op.ManagementPolicyProperties != nil {
objectMap["properties"] = op.ManagementPolicyProperties
}

return objectMap, nil
}

func getAzureStorageAccountBlobProperties(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
accountData := h.Item.(*storageAccountInfo)

Expand Down
13 changes: 13 additions & 0 deletions docs/tables/azure_storage_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,16 @@ where
and queue_logging_read
and queue_logging_write;
```


### List storage accounts without lifecycle

```sql
select
name,
lifecycle_management_policy -> 'properties' -> 'policy' -> 'rules' as lifecycle_rules
from
azure_storage_account
where
lifecycle_management_policy -> 'properties' -> 'policy' -> 'rules' is null;
```

0 comments on commit 241de87

Please sign in to comment.