This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for managed grafana (#859)
- Loading branch information
1 parent
27dc2af
commit 8e23ba5
Showing
1 changed file
with
61 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,61 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/managedgrafana" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type AMGWorkspace struct { | ||
svc *managedgrafana.ManagedGrafana | ||
id *string | ||
name *string | ||
} | ||
|
||
func init() { | ||
register("AMGWorkspace", ListAMGWorkspaces) | ||
} | ||
|
||
func ListAMGWorkspaces(sess *session.Session) ([]Resource, error) { | ||
svc := managedgrafana.New(sess) | ||
resources := []Resource{} | ||
|
||
var amgWorkspaces []*managedgrafana.WorkspaceSummary | ||
err := svc.ListWorkspacesPages( | ||
&managedgrafana.ListWorkspacesInput{}, | ||
func(page *managedgrafana.ListWorkspacesOutput, lastPage bool) bool { | ||
amgWorkspaces = append(amgWorkspaces, page.Workspaces...) | ||
return true | ||
}, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, ws := range amgWorkspaces { | ||
resources = append(resources, &AMGWorkspace{ | ||
svc: svc, | ||
id: ws.Id, | ||
name: ws.Name, | ||
}) | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *AMGWorkspace) Remove() error { | ||
_, err := f.svc.DeleteWorkspace(&managedgrafana.DeleteWorkspaceInput{ | ||
WorkspaceId: f.id, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *AMGWorkspace) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties. | ||
Set("WorkspaceId", f.id). | ||
Set("WorkspaceName", f.name) | ||
|
||
return properties | ||
} |