Skip to content

Commit

Permalink
Merge pull request #516 from inspec/support-power-bi-dashboard-tiles
Browse files Browse the repository at this point in the history
RESOURCE-143 Support power bi dashboard tiles
  • Loading branch information
soumyo13 authored Feb 25, 2022
2 parents 1a6c0b7 + c408a9b commit 42d686d
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ identifier = "inspec/resources/azure/azure_power_bi_dashboard Resource"
parent = "inspec/resources/azure"
+++

Use the `azure_power_bi_dashboard` InSpec audit resource to test the properties related to Azure Power BI dashboard.
Use the `azure_power_bi_dashboard` InSpec audit resource to test the properties related to Azure Power BI Dashboard.

## Azure REST API Version, Endpoint, and HTTP Client Parameters

Expand Down Expand Up @@ -60,10 +60,10 @@ Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/p

## Examples

**Test that the Power BI dashboard is read only.**
**Test that the Power BI Dashboard is read only.**

```ruby
describe azure_power_bi_dashboard(group_id: 'GROUP_ID', dashboard_id: 'dashboard_ID') do
describe azure_power_bi_dashboard(group_id: 'GROUP_ID', dashboard_id: 'DASHBOARD_ID') do
its('isReadOnly') { should eq 'true' }
end
```
Expand All @@ -90,4 +90,4 @@ end

## Azure Permissions

Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be set up with a `dashboard.Read.All` role on the Azure Power BI Workspace you wish to test.
Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be set up with a `Dashboard.Read.All` role on the Azure Power BI Workspace you wish to test.
104 changes: 104 additions & 0 deletions docs-chef-io/content/inspec/resources/azure_power_bi_dashboard_tile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
+++
title = "azure_power_bi_dashboard_tile Resource"
platform = "azure"
draft = false
gh_repo = "inspec-azure"

[menu.inspec]
title = "azure_power_bi_dashboard_tile"
identifier = "inspec/resources/azure/azure_power_bi_dashboard_tile Resource"
parent = "inspec/resources/azure"
+++

Use the `azure_power_bi_dashboard_tile` InSpec audit resource to test the properties related to Azure Power BI dashboard tile.

## Azure REST API Version, Endpoint, and HTTP Client Parameters

{{% inspec_azure_common_parameters %}}

## Installation

{{% inspec_azure_install %}}

## Syntax

```ruby
describe azure_power_bi_dashboard_tile(group_id: 'GROUP_ID', dashboard_id: 'dashboard_ID', title_id: 'TITLE_ID') do
it { should exist }
end
```

## Parameters

`dashboard_id` _(required)_

: The dashboard ID.

`tile_id` _(required)_

: The tile ID.

`group_id` _(optional)_

: The workspace ID.

## Properties

`id`
: Power BI dashboard tile ID.

`title`
: The dashboard display name.

`embedUrl`
: The tile embed url.

`rowSpan`
: number of rows a tile should span.

`colSpan`
: number of columns a tile should span.

`reportId`
: The report ID, which is available only for tiles created from a report.

`datasetId`
: The dataset ID, which is available only for tiles created from a report or using a dataset, such as Q&A tiles.

For properties applicable to all resources, such as `type`, `name`, `id`, and `properties`, refer to [`azure_generic_resource`]({{< relref "azure_generic_resource.md#properties" >}}).

Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/power-bi/dashboards/get-tile) for other properties available.

## Examples

**Test that the Power BI dashboard tile is on left corner.**

```ruby
describe azure_power_bi_dashboard_tile(group_id: 'GROUP_ID', dashboard_id: 'dashboard_ID', title_id: 'TITLE_ID') do
its('rowSpan') { should eq 0 }
end
```

## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](/inspec/matchers/).

### exists

```ruby
# Use should to test for an Azure Power BI dashboard tile that should be in the resource group

describe azure_power_bi_dashboard_tile(group_id: 'GROUP_ID', dashboard_id: 'dashboard_ID', title_id: 'TITLE_ID') do
it { should exist }
end

# Use should_not to test for an Azure Power BI dashboard tile that should not be in the resource group

describe azure_power_bi_dashboard_tile(group_id: 'GROUP_ID', dashboard_id: 'dashboard_ID', title_id: 'TITLE_ID') do
it { should_not exist }
end
```

## Azure Permissions

Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be set up with a `dashboard.Read.All` role on the Azure Power BI Workspace you wish to test.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
+++
title = "azure_power_bi_dashboard_tiles Resource"
platform = "azure"
draft = false
gh_repo = "inspec-azure"

[menu.inspec]
title = "azure_power_bi_dashboard_tiles"
identifier = "inspec/resources/azure/azure_power_bi_dashboard_tiles Resource"
parent = "inspec/resources/azure"
+++

Use the `azure_power_bi_dashboard_tiles` InSpec audit resource to test the properties related to all Azure Power BI dashboard tiles within a project.

## Azure REST API Version, Endpoint, and HTTP Client Parameters

{{% inspec_azure_common_parameters %}}

## Installation

{{% inspec_azure_install %}}

## Syntax

An `azure_power_bi_dashboard_tiles` resource block returns all Azure Power BI dashboard tiles within dashboard and a group.

```ruby
describe azure_power_bi_dashboard_tiles(dashboard_id: 'dashboard_ID') do
#...
end
```

```ruby
describe azure_power_bi_dashboard_tiles(group_id: 'GROUP_ID') do
#...
end
```

## Parameters

`group_id` _(required)_
: The workspace ID.

`dashboard_id` _(optional)_
: The dashboard ID.

## Properties

`ids`
: List of all dashboard IDs.

: **Field**: `id`

`titles`
: List of all the titles.

: **Field**: `title`

`embedUrls`
: List of all dashboard embed urls.

: **Field**: `embedUrl`

`rowSpans`
: List of all row spans.

: **Field**: `rowSpan`

`colSpans`
: List of all col spans.

: **Field**: `colSpan`

`reportIds`
: List of all report IDs.

: **Field**: `reportId`

`datasetIds`
: List of all dataset IDs.

: **Field**: `datasetId`


{{% inspec_filter_table %}}
Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/power-bi/dashboards/get-dashboards) for other properties available.

## Examples

**Loop through Power BI dashboard tiles by their IDs.**

```ruby
azure_power_bi_dashboard_tiles.ids.each do |id|
describe azure_power_bi_dashboard_tile(dashboard_id: id) do
it { should exist }
end
end
```

**Test to ensure all Power BI dashboard tiles that are in top left corner.**

```ruby
describe azure_power_bi_dashboard_tiles.where(rowSpan: true) do
it { should exist }
end
```

## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).

### exists

```ruby
# Use should to test for an Azure Power BI dashboard tile that should be in the resource group.

describe azure_power_bi_dashboard_tiles do
it { should_not exist }
end

# Use should_not to test for an Azure Power BI dashboard tile that should not be in the resource group

describe azure_power_bi_dashboard_tiles do
it { should exist }
end
```

## Azure Permissions

Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be set up with a `dashboard.Read.All` role on the Azure Power BI Workspace you wish to test.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ identifier = "inspec/resources/azure/azure_power_bi_dashboards Resource"
parent = "inspec/resources/azure"
+++

Use the `azure_power_bi_dashboards` InSpec audit resource to test the properties related to all AzurePower BI dashboards within a project.
Use the `azure_power_bi_dashboards` InSpec audit resource to test the properties related to all AzurePower BI Dashboards within a project.

## Azure REST API Version, Endpoint, and HTTP Client Parameters

Expand All @@ -22,7 +22,7 @@ Use the `azure_power_bi_dashboards` InSpec audit resource to test the properties

## Syntax

An `azure_power_bi_dashboards` resource block returns all AzurePower BI dashboards within a group.
An `azure_power_bi_dashboards` resource block returns all AzurePower BI Dashboards within a group.

```ruby
describe azure_power_bi_dashboards do
Expand Down Expand Up @@ -70,7 +70,7 @@ Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/p

## Examples

**Loop throughPower BI dashboards by their IDs.**
**Loop throughPower BI Dashboards by their IDs.**

```ruby
azure_power_bi_dashboards.ids.each do |id|
Expand Down
39 changes: 39 additions & 0 deletions libraries/azure_power_bi_dashboard_tile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'azure_generic_resource'

class AzurePowerBIDashboardTile < AzureGenericResource
name 'azure_power_bi_dashboard_tile'
desc 'Retrieves and verifies the settings of a Azure Power BI Dashboard tile'
example <<-EXAMPLE
describe azure_power_bi_dashboard_tile(tile_id: '3262-4671-bdc8', dashboard_id: 'b84b01c6-3262-4671-bdc8-ff99becf2a0b', group_id: '95a4871a-33a4-4f35-9eea-8ff006b4840b') do
it { should exist }
end
EXAMPLE

attr_reader :table

AUDIENCE = 'https://analysis.windows.net/powerbi/api'.freeze

def initialize(opts = {})
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash)

Validators.validate_parameters(resource_name: @__resource_name__, required: %i(tiles_id dashboard_id),
allow: %i(group_id),
opts: opts)

opts[:name] = opts.delete(:dashboard_id)
opts[:resource_uri] = ['https://api.powerbi.com/v1.0/myorg'].tap do |arr|
arr << "groups/#{opts.delete(:group_id)}" if opts[:group_id].present?
arr << "dashboards/#{opts[:name]}"
arr << "tiles/#{opts[:tiles_id]}"
end.join('/')
opts[:audience] = AUDIENCE
opts[:add_subscription_id] = false
opts[:is_uri_a_url] = true
opts[:api_version] = 'v1.0'
super
end

def to_s
super(AzurePowerBIDashboardTile)
end
end
35 changes: 35 additions & 0 deletions libraries/azure_power_bi_dashboard_tiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'azure_generic_resources'

class AzurePowerBIDashboardTiles < AzureGenericResources
name 'azure_power_bi_dashboard_tiles'
desc 'Retrieves and verifies the settings of all Azure Power BI Dashboard Tiles'
example <<-EXAMPLE
describe azure_power_bi_dashboard_tiles(dashboard_id: 'b84b01c6-3262-4671-bdc8-ff99becf2a0b', group_id: '95a4871a-33a4-4f35-9eea-8ff006b4840b') do
it { should exist }
end
EXAMPLE

AUDIENCE = 'https://analysis.windows.net/powerbi/api'.freeze

def initialize(opts = {})
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash)

opts[:resource_uri] = ['https://api.powerbi.com/v1.0/myorg'].tap do |arr|
arr << "groups/#{opts.delete(:group_id)}" if opts[:group_id].present?
arr << "dashboards/#{opts[:name]}"
arr << 'tiles'
end.join('/')
opts[:audience] = AUDIENCE
opts[:add_subscription_id] = false
opts[:is_uri_a_url] = true
opts[:api_version] = 'v1.0'
super
return if failed_resource?

populate_filter_table_from_response
end

def to_s
super(AzurePowerBIDashboardTiles)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
group_id = input(:inspec_powerbi_workspace_id, value: '')
dashboard_id = 'b84b01c6-3262-4671-bdc8-ff99becf2a0b'
tile_id = '3262-4671-bdc8-'
control 'Verify settings of a Power BI Dashboard tile' do
describe azure_power_bi_dashboard_tile(group_id: group_id, dashboard_id: dashboard_id, tile_id: tile_id) do
it { should exist }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
group_id = input(:inspec_powerbi_workspace_id, value: '')
control 'verify settings of all Power BI Dashboard Tiles in a group' do
describe azure_power_bi_dashboards(group_id: group_id, dashboard_id: 'b84b01c6-3262-4671-bdc8-ff99becf2a0b') do
it { should exist }
end
end
Loading

0 comments on commit 42d686d

Please sign in to comment.