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

Support for Dashboard Sharing #26

Merged
merged 11 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
90 changes: 90 additions & 0 deletions docs/resources/dashboard_share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "squaredup_dashboard_share Resource - terraform-provider-squaredup"
subcategory: ""
description: |-
Enable Open Access for a dashboard
---

# squaredup_dashboard_share (Resource)

Enable Open Access for a dashboard

## Example Usage

```terraform
resource "squaredup_workspace" "application_workspace" {
display_name = "Application Team"
description = "Workspace with Dashboards for Application Team"
open_access_enabled = true
}

resource "squaredup_dashboard" "sample_dashboard" {
dashboard_template = <<EOT
{
"_type": "layout/grid",
"contents": [
{
"x": 0,
"h": 2,
"i": "1",
"y": 0,
"config": {
"title": "",
"description": "",
"_type": "tile/text",
"visualisation": {
"config": {
"content": "Sample Tile",
"autoSize": true,
"fontSize": 16,
"align": "center"
}
}
},
"w": 4
}
],
"columns": 1,
"version": 1
}
EOT
workspace_id = squaredup_workspace.application_workspace.id
display_name = "Sample Dashboard"
}

resource "squaredup_dashboard_share" "sample_dashboard_share" {
dashboard_id = squaredup_dashboard.sample_dashboard.id
workspace_id = squaredup_workspace.application_workspace.id
require_authentication = true
enable_link = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `dashboard_id` (String) The ID of the dashboard
- `require_authentication` (Boolean) If false, the dashboard will be accessible to anyone with the link
- `workspace_id` (String) The ID of the workspace where the dashboard is located

### Optional

- `enable_link` (Boolean) If false, the dashboard will not be accessible via Open Access Link
shaswot77 marked this conversation as resolved.
Show resolved Hide resolved

### Read-Only

- `id` (String) The ID of the Open Access
shaswot77 marked this conversation as resolved.
Show resolved Hide resolved
- `last_updated` (String) The last time the Open Access was updated
- `open_access_link` (String) The Open Access Link for the dashboard

## Import

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this import section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import allows you to import resources that were not created through terraform to its configuration.


Import is supported using the following syntax:

```shell
# Shared Dashboard can be imported using the OA ID.
shaswot77 marked this conversation as resolved.
Show resolved Hide resolved
terraform import squaredup_dashboard.example openacc-123
```
2 changes: 2 additions & 0 deletions examples/resources/squaredup_dashboard_share/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Shared Dashboard can be imported using the OA ID.
shaswot77 marked this conversation as resolved.
Show resolved Hide resolved
terraform import squaredup_dashboard.example openacc-123
46 changes: 46 additions & 0 deletions examples/resources/squaredup_dashboard_share/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
resource "squaredup_workspace" "application_workspace" {
display_name = "Application Team"
description = "Workspace with Dashboards for Application Team"
open_access_enabled = true
}

resource "squaredup_dashboard" "sample_dashboard" {
dashboard_template = <<EOT
{
"_type": "layout/grid",
"contents": [
{
"x": 0,
"h": 2,
"i": "1",
"y": 0,
"config": {
"title": "",
"description": "",
"_type": "tile/text",
"visualisation": {
"config": {
"content": "Sample Tile",
"autoSize": true,
"fontSize": 16,
"align": "center"
}
}
},
"w": 4
}
],
"columns": 1,
"version": 1
}
EOT
workspace_id = squaredup_workspace.application_workspace.id
display_name = "Sample Dashboard"
}

resource "squaredup_dashboard_share" "sample_dashboard_share" {
dashboard_id = squaredup_dashboard.sample_dashboard.id
workspace_id = squaredup_workspace.application_workspace.id
require_authentication = true
enable_link = true
}
85 changes: 85 additions & 0 deletions internal/provider/client_open_access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package provider

import (
"encoding/json"
"net/http"
"strings"
)

func (c *SquaredUpClient) CreateOpenAccess(openAccess OpenAccess) (*OpenAccess, error) {
rb, err := json.Marshal(openAccess)
if err != nil {
return nil, err
}

req, err := http.NewRequest("POST", c.baseURL+"/api/openaccess/shares", strings.NewReader(string(rb)))
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

newOpenAccess := OpenAccess{}
err = json.Unmarshal(body, &newOpenAccess)
if err != nil {
return nil, err
}

return &newOpenAccess, nil
}

func (c *SquaredUpClient) GetOpenAccess(openAcessId string) (*OpenAccess, error) {
req, err := http.NewRequest("GET", c.baseURL+"/api/openaccess/shares/"+openAcessId, nil)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

openAccess := OpenAccess{}
err = json.Unmarshal(body, &openAccess)
if err != nil {
return nil, err
}

return &openAccess, nil
}

func (c *SquaredUpClient) UpdateOpenAccess(openAcessId string, openAccess OpenAccess) error {
rb, err := json.Marshal(openAccess)
if err != nil {
return err
}

req, err := http.NewRequest("PUT", c.baseURL+"/api/openaccess/shares/"+openAcessId, strings.NewReader(string(rb)))
if err != nil {
return err
}

_, err = c.doRequest(req)
if err != nil {
return err
}

return nil
}

func (c *SquaredUpClient) DeleteOpenAccess(openAcessId string) error {
req, err := http.NewRequest("DELETE", c.baseURL+"/api/openaccess/shares/"+openAcessId, nil)
if err != nil {
return err
}

_, err = c.doRequest(req)
if err != nil {
return err
}

return nil
}
13 changes: 13 additions & 0 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,16 @@ type GremlinQueryResult struct {
TenantId []string `json:"__tenantId"`
ConfigId []string `json:"__configId"`
}

type OpenAccess struct {
LastUpdated string `json:"lastUpdated,omitempty"`
ID string `json:"id,omitempty"`
TargetID string `json:"targetId"`
WorkspaceID string `json:"workspaceId"`
Properties OpenAccessProperties `json:"properties"`
}

type OpenAccessProperties struct {
Enabled bool `json:"enabled"`
RequireAuthentication bool `json:"requireAuthentication"`
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ func (p *squaredupProvider) Resources(_ context.Context) []func() resource.Resou
SquaredupDataSourceResource,
SquaredupWorkspaceResource,
SquaredUpDashboardResource,
SquaredUpOpenAccessResource,
}
}
Loading
Loading