Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table azure_data_factory. Closes #156 #158

Merged
merged 5 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
13 changes: 13 additions & 0 deletions azure-test/tests/azure_data_factory/test-get-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"id": "{{ output.resource_id.value }}",
"name": "{{ resourceName }}",
"region": "{{ output.location.value }}",
"resource_group": "{{ resourceName }}",
"subscription_id": "{{ output.subscription_id.value }}",
"tags": {
"name": "{{ resourceName }}"
},
"type": "Microsoft.DataFactory/factories"
}
]
3 changes: 3 additions & 0 deletions azure-test/tests/azure_data_factory/test-get-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, type, tags, region, resource_group, subscription_id
from azure.azure_data_factory
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}';
7 changes: 7 additions & 0 deletions azure-test/tests/azure_data_factory/test-list-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"id": "{{ output.resource_id.value }}",
"name": "{{ resourceName }}",
"type": "Microsoft.DataFactory/factories"
}
]
3 changes: 3 additions & 0 deletions azure-test/tests/azure_data_factory/test-list-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, type
from azure.azure_data_factory
where name = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
3 changes: 3 additions & 0 deletions azure-test/tests/azure_data_factory/test-not-found-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, tags, title, akas
from azure.azure_data_factory
where name = 'dummy-{{ resourceName }}' and resource_group = '{{ resourceName }}';
13 changes: 13 additions & 0 deletions azure-test/tests/azure_data_factory/test-turbot-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"akas": [
"{{ output.resource_aka.value }}",
"{{ output.resource_aka_lower.value }}"
],
"name": "{{ resourceName }}",
"tags": {
"name": "{{ resourceName }}"
},
"title": "{{ resourceName }}"
}
]
3 changes: 3 additions & 0 deletions azure-test/tests/azure_data_factory/test-turbot-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, tags, title, akas
from azure.azure_data_factory
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}';
1 change: 1 addition & 0 deletions azure-test/tests/azure_data_factory/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
71 changes: 71 additions & 0 deletions azure-test/tests/azure_data_factory/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

variable "resource_name" {
type = string
default = "steampipe-test"
description = "Name of the resource used throughout the test."
}

variable "azure_environment" {
type = string
default = "public"
description = "Azure environment used for the test."
}

variable "azure_subscription" {
type = string
default = "3510ae4d-530b-497d-8f30-53b9616fc6c1"
description = "Azure subscription used for the test."
}

provider "azurerm" {
# Cannot be passed as a variable
version = "=1.36.0"
environment = var.azure_environment
subscription_id = var.azure_subscription
}

data "azurerm_client_config" "current" {}

data "null_data_source" "resource" {
inputs = {
scope = "azure:///subscriptions/${data.azurerm_client_config.current.subscription_id}"
}
}

resource "azurerm_resource_group" "named_test_resource" {
name = var.resource_name
location = "East US"
}

resource "azurerm_data_factory" "named_test_resource" {
name = var.resource_name
location = azurerm_resource_group.named_test_resource.location
resource_group_name = azurerm_resource_group.named_test_resource.name
tags = {
name = var.resource_name
}
}

output "resource_aka" {
value = "azure://${azurerm_data_factory.named_test_resource.id}"
}

output "resource_aka_lower" {
value = "azure://${lower(azurerm_data_factory.named_test_resource.id)}"
}

output "resource_name" {
value = var.resource_name
}

output "resource_id" {
value = azurerm_data_factory.named_test_resource.id
}

output "location" {
value = azurerm_resource_group.named_test_resource.location
}

output "subscription_id" {
value = var.azure_subscription
}
1 change: 1 addition & 0 deletions azure/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"azure_cosmosdb_account": tableAzureCosmosDBAccount(ctx),
"azure_cosmosdb_mongo_database": tableAzureCosmosDBMongoDatabase(ctx),
"azure_cosmosdb_sql_database": tableAzureCosmosDBSQLDatabase(ctx),
"azure_data_factory": tableAzureDataFactory(ctx),
"azure_diagnostic_setting": tableAzureDiagnosticSetting(ctx),
"azure_express_route_circuit": tableAzureExpressRouteCircuit(ctx),
"azure_firewall": tableAzureFirewall(ctx),
Expand Down
201 changes: 201 additions & 0 deletions azure/table_azure_data_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package azure

import (
"context"

"github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory"
"github.com/turbot/steampipe-plugin-sdk/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/plugin/transform"

"github.com/turbot/steampipe-plugin-sdk/plugin"
)

//// TABLE DEFINITION

func tableAzureDataFactory(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_data_factory",
Description: "Azure Data Factory",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}),
Hydrate: getDataFactory,
ShouldIgnoreError: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "Invalid input"}),
},
List: &plugin.ListConfig{
Hydrate: listDataFactories,
},
Columns: []*plugin.Column{
{
Name: "name",
Description: "The resource name.",
Type: proto.ColumnType_STRING,
},
{
Name: "id",
Description: "The resource identifier.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "type",
Description: "The resource type.",
Type: proto.ColumnType_STRING,
},
{
Name: "version",
Description: "Version of the factory.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("FactoryProperties.Version"),
},
{
Name: "create_time",
Description: "Specifies the time, the factory was created.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("FactoryProperties.CreateTime").Transform(convertDateToTime),
},
{
Name: "etag",
Description: "An unique read-only string that changes whenever the resource is updated.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ETag"),
},
{
Name: "provisioning_state",
Description: "Factory provisioning state, example Succeeded.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("FactoryProperties.ProvisioningState"),
},
{
Name: "public_network_access",
Description: "Whether or not public network access is allowed for the data factory.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("FactoryProperties.PublicNetworkAccess").Transform(transform.ToString),
},
{
Name: "additional_properties",
Description: "Unmatched properties from the message are deserialized this collection.",
Type: proto.ColumnType_JSON,
},
{
Name: "identity",
Description: "Managed service identity of the factory.",
Type: proto.ColumnType_JSON,
},
{
Name: "encryption",
Description: "Properties to enable Customer Managed Key for the factory.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("FactoryProperties.EncryptionConfiguration"),
},
{
Name: "repo_configuration",
Description: "Git repo information of the factory.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("FactoryProperties.RepoConfiguration"),
},
{
Name: "global_parameters",
Description: "List of parameters for factory.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("FactoryProperties.GlobalParameters"),
},

// Steampipe standard columns
{
Name: "title",
Description: ColumnDescriptionTitle,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
{
Name: "tags",
Description: ColumnDescriptionTags,
Type: proto.ColumnType_JSON,
},
{
Name: "akas",
Description: ColumnDescriptionAkas,
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ID").Transform(idToAkas),
},

// Azure standard column
{
Subhajit97 marked this conversation as resolved.
Show resolved Hide resolved
Name: "region",
Description: ColumnDescriptionRegion,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Location").Transform(toLower),
},
{
Name: "resource_group",
Description: ColumnDescriptionResourceGroup,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(extractResourceGroupFromID),
},
{
Name: "subscription_id",
Description: ColumnDescriptionSubscription,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(idToSubscriptionID),
},
},
}
}

//// LIST FUNCTION

func listDataFactories(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

factoryClient := datafactory.NewFactoriesClient(subscriptionID)
factoryClient.Authorizer = session.Authorizer

pagesLeft := true
for pagesLeft {
result, err := factoryClient.List(context.Background())
if err != nil {
return nil, err
}
for _, factory := range result.Values() {
d.StreamListItem(ctx, factory)
}
result.NextWithContext(context.Background())
pagesLeft = result.NotDone()
}
return nil, err
}

//// HYDRATE FUNCTIONS

func getDataFactory(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getDataFactory")

Subhajit97 marked this conversation as resolved.
Show resolved Hide resolved
// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

factoryClient := datafactory.NewFactoriesClient(subscriptionID)
factoryClient.Authorizer = session.Authorizer

name := d.KeyColumnQuals["name"].GetStringValue()
resourceGroup := d.KeyColumnQuals["resource_group"].GetStringValue()

// Return nil, if no input provide
if name == "" || resourceGroup == "" {
return nil, nil
}

op, err := factoryClient.Get(ctx, resourceGroup, name, "*")
if err != nil {
return nil, err
}

return op, nil
}
48 changes: 48 additions & 0 deletions docs/tables/azure_data_factory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Table: azure_data_factory

Azure Data Factory is the platform that solves such data scenarios. It is the cloud-based ETL and data integration service that allows to create data-driven workflows for orchestrating data movement and transforming data at scale.

## Examples

### Basic info

```sql
select
name,
id,
type,
provisioning_state,
etag
from
azure_data_factory;
```


### List system assigned identity type factories

```sql
select
name,
id,
type,
identity ->> 'type' as identity_type
from
azure_data_factory
where
identity ->> 'type' = 'SystemAssigned';
```


### List factories with public network access enabled

```sql
select
name,
id,
type,
public_network_access
from
azure_data_factory
where
public_network_access = 'Enabled';
```