-
Notifications
You must be signed in to change notification settings - Fork 18
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_tenant closes #140 #142
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"display_name": null, | ||
"name": "{{ output.current_tenant_display_name.value }}", | ||
"tenant_id": "{{ output.tenant_id.value }}" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select name, display_name, tenant_id | ||
from azure.azure_tenant | ||
where tenant_id = '{{ output.tenant_id.value }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select display_name, title | ||
from azure.azure_tenant | ||
where display_name = 'dummy-{{ resourceName }}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"name": "{{ output.current_tenant_display_name.value }}", | ||
"title": "{{ output.current_tenant_display_name.value }}" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select name, title | ||
from azure.azure_tenant | ||
where tenant_id = '{{ output.tenant_id.value }}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
variable "resource_name" { | ||
type = string | ||
default = "turbot-test-20200125-create-update" | ||
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 environment used for the test." | ||
} | ||
|
||
variable "azure_tenant" { | ||
type = string | ||
default = "cdffd708-7da0-4cea-abeb-0a4c334d7f64" | ||
description = "Azure environment used for the test." | ||
} | ||
|
||
provider "azuread" { | ||
# Cannot be passed as a variable | ||
# version = "=0.10.0" | ||
environment = var.azure_environment | ||
subscription_id = var.azure_subscription | ||
tenant_id = var.azure_tenant | ||
} | ||
|
||
data "azurerm_client_config" "current" { | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
output "current_tenant_display_name" { | ||
value = data.azurerm_client_config.current.tenant_id | ||
} | ||
|
||
output "tenant_id" { | ||
value = data.azurerm_client_config.current.tenant_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-06-01/subscriptions" | ||
"github.com/turbot/steampipe-plugin-sdk/grpc/proto" | ||
"github.com/turbot/steampipe-plugin-sdk/plugin" | ||
"github.com/turbot/steampipe-plugin-sdk/plugin/transform" | ||
) | ||
|
||
//// TABLE DEFINITION | ||
|
||
func tableAzureTenant(_ context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "azure_tenant", | ||
Description: "Azure Tenant", | ||
List: &plugin.ListConfig{ | ||
Hydrate: listTenants, | ||
}, | ||
Columns: []*plugin.Column{ | ||
{ | ||
Name: "name", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The display name of the tenant.", | ||
Transform: transform.From(getNameOrID), | ||
}, | ||
{ | ||
Name: "id", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The fully qualified ID of the tenant. For example, /tenants/00000000-0000-0000-0000-000000000000.", | ||
Transform: transform.FromGo(), | ||
}, | ||
{ | ||
Name: "tenant_id", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The tenant ID. For example, 00000000-0000-0000-0000-000000000000.", | ||
Transform: transform.FromField("TenantID"), | ||
}, | ||
{ | ||
Name: "tenant_category", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The tenant category. Possible values include: 'Home', 'ProjectedBy', 'ManagedBy'", | ||
Transform: transform.FromField("TenantCategory").Transform(transform.ToString), | ||
}, | ||
{ | ||
Name: "country", | ||
Type: proto.ColumnType_STRING, | ||
Description: "Country/region name of the address for the tenant.", | ||
}, | ||
{ | ||
Name: "country_code", | ||
Type: proto.ColumnType_STRING, | ||
Description: "Country/region abbreviation for the tenant.", | ||
}, | ||
{ | ||
Name: "display_name", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The list of domains for the tenant.", | ||
}, | ||
{ | ||
Name: "domains", | ||
Type: proto.ColumnType_JSON, | ||
Description: "The list of domains for the tenant.", | ||
}, | ||
|
||
// Standard columns | ||
{ | ||
Name: "title", | ||
Description: ColumnDescriptionTitle, | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.From(getNameOrID), | ||
}, | ||
{ | ||
Name: "akas", | ||
Description: ColumnDescriptionAkas, | ||
Type: proto.ColumnType_JSON, | ||
Transform: transform.FromField("ID").Transform(idToAkas), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
//// LIST FUNCTION | ||
|
||
func listTenants(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
session, err := GetNewSession(ctx, d, "MANAGEMENT") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client := subscriptions.NewTenantsClient() | ||
client.Authorizer = session.Authorizer | ||
|
||
op, err := client.List(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, resp := range op.Values() { | ||
d.StreamListItem(ctx, resp) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
//// TRANSFORM FUNCTION | ||
|
||
func getNameOrID(ctx context.Context, d *transform.TransformData) (interface{}, error) { | ||
data := d.HydrateItem.(subscriptions.TenantIDDescription) | ||
if data.DisplayName != nil { | ||
return data.DisplayName, nil | ||
} | ||
return data.TenantID, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Table: azure_tenant | ||
|
||
A dedicated and trusted instance of Azure AD that's automatically created when your organization signs up for a Microsoft cloud service subscription, such as Microsoft Azure, Microsoft Intune, or Microsoft 365. An Azure tenant represents a single organization. | ||
|
||
## Examples | ||
|
||
### Basic info | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
tenant_id, | ||
tenant_category, | ||
country, | ||
country_code, | ||
display_name, | ||
domains | ||
from | ||
azure_tenant; | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both values are same - can we keep only one of it for this table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://newwarriors-turbot.cloud.turbot-dev.com/overview?filter=resourceId%3A193588185481103&overviewActivityFilter=sort%3A-timestamp
We have this info available for tenant in mods