-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from squaredup/work/ss/dashboard-share
Support for Dashboard Sharing
- Loading branch information
Showing
8 changed files
with
631 additions
and
0 deletions.
There are no files selected for viewing
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,90 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "squaredup_dashboard_share Resource - terraform-provider-squaredup" | ||
subcategory: "" | ||
description: |- | ||
Enable sharing for a dashboard | ||
--- | ||
|
||
# squaredup_dashboard_share (Resource) | ||
|
||
Enable sharing 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 | ||
enabled = true | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `dashboard_id` (String) The ID of the dashboard to share | ||
- `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 | ||
|
||
- `enabled` (Boolean) If false, sharing of the dashboard is disabled | ||
|
||
### Read-Only | ||
|
||
- `dashboard_share_link` (String) Shareable link for the dashboard | ||
- `id` (String) The ID of the dashboard share | ||
- `last_updated` (String) The last time the Dashboard Share was updated | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# Dashboard share can be imported using the OA ID. | ||
terraform import squaredup_dashboard.example openacc-123 | ||
``` |
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,2 @@ | ||
# Dashboard share can be imported using the OA ID. | ||
terraform import squaredup_dashboard.example openacc-123 |
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 @@ | ||
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 | ||
enabled = true | ||
} |
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,85 @@ | ||
package provider | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func (c *SquaredUpClient) CreateSharedDashboard(dashboardShare DashboardShare) (*DashboardShare, error) { | ||
rb, err := json.Marshal(dashboardShare) | ||
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 | ||
} | ||
|
||
sharedDashboard := DashboardShare{} | ||
err = json.Unmarshal(body, &sharedDashboard) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &sharedDashboard, nil | ||
} | ||
|
||
func (c *SquaredUpClient) GetSharedDashboard(sharedDashboardId string) (*DashboardShare, error) { | ||
req, err := http.NewRequest("GET", c.baseURL+"/api/openaccess/shares/"+sharedDashboardId, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sharedDashboard := DashboardShare{} | ||
err = json.Unmarshal(body, &sharedDashboard) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &sharedDashboard, nil | ||
} | ||
|
||
func (c *SquaredUpClient) UpdateSharedDashboard(sharedDashboardId string, dashboardShare DashboardShare) error { | ||
rb, err := json.Marshal(dashboardShare) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req, err := http.NewRequest("PUT", c.baseURL+"/api/openaccess/shares/"+sharedDashboardId, strings.NewReader(string(rb))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *SquaredUpClient) DeleteSharedDashboard(sharedDashboardId string) error { | ||
req, err := http.NewRequest("DELETE", c.baseURL+"/api/openaccess/shares/"+sharedDashboardId, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return 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
Oops, something went wrong.