Skip to content

Commit

Permalink
Adding initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
safaci2000 committed Nov 16, 2023
1 parent 57e820e commit c71250e
Show file tree
Hide file tree
Showing 47 changed files with 13,439 additions and 1,499 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ public
resources
.idea
config/token*.yml
config/templates.yml
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The following remote backup locations are supported:

Please find the generated documentation [here](https://software.es.net/gdg/) and the code for updating the docs is available [here](https://github.com/esnet/gdg/blob/master/documentation/content/docs/usage_guide.md)

## Quickstart

![Quickstart screen](website/static/quickstart.gif)

## Release conventions.

GDG mostly follows the semver conventions with some minor modifications.
Expand All @@ -33,7 +37,3 @@ contexts. i.e. `gdg diff dashboards prod staging` is a major divergences from

For more info, please see the release notes and documentation both available [here](https://software.es.net/gdg/)

## Quickstart

![Quickstart screen](website/static/quickstart.gif)

5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ tasks:
cmds:
- echo "GOPATH=${GOPATH}"
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }} cmd/gdg/main.go
build_generate:
desc: "Buiding {{ .BIN_NAME }}-generate {{ .VERSION }}"
cmds:
- echo "GOPATH=${GOPATH}"
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}-generate cmd/gen/main.go
install:
desc: "installing {{ .BIN_NAME }} {{ .VERSION }}"
cmds:
Expand Down
8 changes: 4 additions & 4 deletions cli/backup/alertnotifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newClearAlertNotificationsCmd() simplecobra.Commander {
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})

slog.Info("Clearing all alert notification channels for context",
"context", config.Config().AppConfig.GetContext())
"context", config.Config().GetGDGConfig().GetContext())
deleted := rootCmd.GrafanaSvc().DeleteAllAlertNotifications()
for _, item := range deleted {
rootCmd.TableObj.AppendRow(table.Row{"alertnotification", item})
Expand Down Expand Up @@ -78,7 +78,7 @@ func newUploadAlertNotificationsCmd() simplecobra.Commander {
rootCmd.TableObj.AppendHeader(table.Row{"name", "id", "UID"})

slog.Info("Exporting alert notification channels for context",
"context", config.Config().AppConfig.GetContext())
"context", config.Config().GetGDGConfig().GetContext())
rootCmd.GrafanaSvc().UploadAlertNotifications()
items := rootCmd.GrafanaSvc().ListAlertNotifications()
for _, item := range items {
Expand Down Expand Up @@ -108,7 +108,7 @@ func newDownloadAlertNotificationsCmd() simplecobra.Commander {
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})

slog.Info("Downloading alert notification channels for context",
"context", config.Config().AppConfig.GetContext())
"context", config.Config().GetGDGConfig().GetContext())

savedFiles := rootCmd.GrafanaSvc().DownloadAlertNotifications()
for _, file := range savedFiles {
Expand Down Expand Up @@ -136,7 +136,7 @@ func newListAlertNotificationsCmd() simplecobra.Commander {
alertnotifications := rootCmd.GrafanaSvc().ListAlertNotifications()

slog.Info("Listing alert notifications channels for context",
"context", config.Config().AppConfig.GetContext())
"context", config.Config().GetGDGConfig().GetContext())

if len(alertnotifications) == 0 {
slog.Info("No alert notifications found")
Expand Down
6 changes: 3 additions & 3 deletions cli/backup/connection_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newConnectionsPermissionListCmd() simplecobra.Commander {
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
connectionFilter, _ := cd.CobraCommand.Flags().GetString("connection")
filters := service.NewConnectionFilter(connectionFilter)
slog.Info("Listing Connection Permissions for context", "context", config.Config().GetAppConfig().GetContext())
slog.Info("Listing Connection Permissions for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"id", "uid", "name", "slug", "type", "default", "url"})
connections := rootCmd.GrafanaSvc().ListConnectionPermissions(filters)
_ = connections
Expand Down Expand Up @@ -82,7 +82,7 @@ func newConnectionsPermissionClearCmd() simplecobra.Commander {
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Clear all connections permissions")
tools.GetUserConfirmation(fmt.Sprintf("WARNING: this will clear all permission from all connections on: '%s' "+
"(Or all permission matching yoru --connection filter). Do you wish to continue (y/n) ", config.Config().GetAppConfig().ContextName,
"(Or all permission matching yoru --connection filter). Do you wish to continue (y/n) ", config.Config().GetGDGConfig().ContextName,
), "", true)
rootCmd.TableObj.AppendHeader(table.Row{"cleared connection permissions"})
connectionFilter, _ := cd.CobraCommand.Flags().GetString("connection")
Expand Down Expand Up @@ -114,7 +114,7 @@ func newConnectionsPermissionDownloadCmd() simplecobra.Commander {
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("import Connections for context",
"context", config.Config().GetAppConfig().GetContext())
"context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"filename"})
connectionFilter, _ := cd.CobraCommand.Flags().GetString("connection")
filters := service.NewConnectionFilter(connectionFilter)
Expand Down
4 changes: 2 additions & 2 deletions cli/backup/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func newDownloadConnectionsCmd() simplecobra.Commander {
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Importing connections for context",
"context", config.Config().GetAppConfig().GetContext())
"context", config.Config().GetGDGConfig().GetContext())
dashboardFilter, _ := cd.CobraCommand.Flags().GetString("connection")
filters := service.NewConnectionFilter(dashboardFilter)
savedFiles := rootCmd.GrafanaSvc().DownloadConnections(filters)
Expand All @@ -123,7 +123,7 @@ func newListConnectionsCmd() simplecobra.Commander {
dashboardFilter, _ := cd.CobraCommand.Flags().GetString("connection")
filters := service.NewConnectionFilter(dashboardFilter)
dsListing := rootCmd.GrafanaSvc().ListConnections(filters)
slog.Info("Listing connections for context", "context", config.Config().GetAppConfig().GetContext())
slog.Info("Listing connections for context", "context", config.Config().GetGDGConfig().GetContext())
if len(dsListing) == 0 {
slog.Info("No connections found")
} else {
Expand Down
4 changes: 2 additions & 2 deletions cli/backup/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func newDownloadDashboardsCmd() simplecobra.Commander {
filter := service.NewDashboardFilter(parseDashboardGlobalFlags(cd.CobraCommand)...)
savedFiles := rootCmd.GrafanaSvc().DownloadDashboards(filter)
slog.Info("Downloading dashboards for context",
"context", config.Config().GetAppConfig().GetContext())
"context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})
for _, file := range savedFiles {
rootCmd.TableObj.AppendRow(table.Row{"dashboard", file})
Expand All @@ -160,7 +160,7 @@ func newListDashboardsCmd() simplecobra.Commander {
filters := service.NewDashboardFilter(parseDashboardGlobalFlags(cd.CobraCommand)...)
boards := rootCmd.GrafanaSvc().ListDashboards(filters)

slog.Info("Listing dashboards for context", "context", config.Config().GetAppConfig().GetContext())
slog.Info("Listing dashboards for context", "context", config.Config().GetGDGConfig().GetContext())
for _, link := range boards {
url := fmt.Sprintf("%s%s", config.Config().GetDefaultGrafanaConfig().URL, link.URL)
rootCmd.TableObj.AppendRow(table.Row{link.ID, link.Title, link.Slug, link.FolderTitle,
Expand Down
4 changes: 2 additions & 2 deletions cli/backup/folder_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newFolderPermissionListCmd() simplecobra.Commander {
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
rowConfigAutoMerge := table.RowConfig{AutoMerge: true}

slog.Info("Listing Folders for context", "context", config.Config().GetAppConfig().GetContext())
slog.Info("Listing Folders for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"folder ID", "folderUid", "folder Name", "UserID", "Team Name", "Role", "Permission Name"}, rowConfigAutoMerge)
folders := rootCmd.GrafanaSvc().ListFolderPermissions(getFolderFilter())

Expand Down Expand Up @@ -71,7 +71,7 @@ func newFolderPermissionDownloadCmd() simplecobra.Commander {
cmd.Aliases = []string{"d"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Downloading Folder Permissions for context", "context", config.Config().GetAppConfig().GetContext())
slog.Info("Downloading Folder Permissions for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"filename"})
folders := rootCmd.GrafanaSvc().DownloadFolderPermissions(getFolderFilter())
slog.Info("Downloading folder permissions")
Expand Down
8 changes: 4 additions & 4 deletions cli/backup/folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newFolderClearCmd() simplecobra.Commander {
cmd.Aliases = []string{"c", "delete"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Deleting all Folders for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Deleting all Folders for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"title"})

folders := rootCmd.GrafanaSvc().DeleteAllFolders(getFolderFilter())
Expand All @@ -84,7 +84,7 @@ func newFolderListCmd() simplecobra.Commander {
cmd.Aliases = []string{"u"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Listing Folders for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing Folders for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"id", "uid", "title"})
folders := rootCmd.GrafanaSvc().ListFolder(getFolderFilter())

Expand All @@ -110,7 +110,7 @@ func newFolderDownloadCmd() simplecobra.Commander {
cmd.Aliases = []string{"d"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Listing Folders for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing Folders for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"file"})
folders := rootCmd.GrafanaSvc().DownloadFolders(getFolderFilter())
if len(folders) == 0 {
Expand All @@ -135,7 +135,7 @@ func newFolderUploadCmd() simplecobra.Commander {
cmd.Aliases = []string{"u"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Uploading Folders for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Uploading Folders for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"file"})
folders := rootCmd.GrafanaSvc().UploadFolders(getFolderFilter())
if len(folders) == 0 {
Expand Down
6 changes: 3 additions & 3 deletions cli/backup/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func newLibraryElementsListCmd() simplecobra.Commander {

elements := rootCmd.GrafanaSvc().ListLibraryElements(nil)

slog.Info("Listing library for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing library for context", "context", config.Config().GetGDGConfig().GetContext())
for _, link := range elements {
rootCmd.TableObj.AppendRow(table.Row{link.ID, link.UID, link.Meta.FolderName, link.Name, link.Type})

Expand All @@ -101,7 +101,7 @@ func newLibraryElementsDownloadCmd() simplecobra.Commander {
cmd.Aliases = []string{"d"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Downloading library for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Downloading library for context", "context", config.Config().GetGDGConfig().GetContext())
savedFiles := rootCmd.GrafanaSvc().DownloadLibraryElements(nil)
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})
for _, file := range savedFiles {
Expand Down Expand Up @@ -156,7 +156,7 @@ func newLibraryElementsListConnectionsCmd() simplecobra.Commander {

libElmentUid := args[0]
elements := rootCmd.GrafanaSvc().ListLibraryElementsConnections(nil, libElmentUid)
slog.Info("Listing library connections for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing library connections for context", "context", config.Config().GetGDGConfig().GetContext())
for _, link := range elements {
dash := link.Dashboard.(map[string]interface{})
rootCmd.TableObj.AppendRow(table.Row{dash["id"].(json.Number), dash["uid"].(string), link.Meta.Slug, dash["title"].(string), link.Meta.FolderTitle})
Expand Down
6 changes: 3 additions & 3 deletions cli/backup/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newOrganizationsListCmd() simplecobra.Commander {
cmd.Aliases = []string{"l"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Listing organizations for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing organizations for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"id", "org"})
listOrganizations := rootCmd.GrafanaSvc().ListOrganizations()
sort.Slice(listOrganizations, func(a, b int) bool {
Expand Down Expand Up @@ -71,7 +71,7 @@ func newOrganizationsDownloadCmd() simplecobra.Commander {
cmd.Aliases = []string{"d"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Downloading organizations for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Downloading organizations for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"file"})
listOrganizations := rootCmd.GrafanaSvc().DownloadOrganizations()
if len(listOrganizations) == 0 {
Expand All @@ -97,7 +97,7 @@ func newOrganizationsUploadCmd() simplecobra.Commander {
cmd.Aliases = []string{"u"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Uploading Folders for context: '%s'", "context", config.Config().AppConfig.GetContext())
slog.Info("Uploading Folders for context: '%s'", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"file"})
folders := rootCmd.GrafanaSvc().UploadOrganizations()
if len(folders) == 0 {
Expand Down
8 changes: 4 additions & 4 deletions cli/backup/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newTeamsListCmd() simplecobra.Commander {
cmd.Aliases = []string{"l"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Listing teams for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing teams for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"id", "name", "email", "orgID", "memberCount", "memberID", "member Permission"})
filter := api.NewTeamFilter(parseTeamGlobalFlags(cd.CobraCommand)...)
teams := rootCmd.GrafanaSvc().ListTeams(filter)
Expand Down Expand Up @@ -89,7 +89,7 @@ func newTeamsDownloadCmd() simplecobra.Commander {
cmd.Aliases = []string{"d"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Importing Teams for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Importing Teams for context", "context", config.Config().GetGDGConfig().GetContext())
filter := api.NewTeamFilter(parseTeamGlobalFlags(cd.CobraCommand)...)
savedFiles := rootCmd.GrafanaSvc().DownloadTeams(filter)
if len(savedFiles) == 0 {
Expand Down Expand Up @@ -119,7 +119,7 @@ func newTeamsUploadCmd() simplecobra.Commander {
cmd.Aliases = []string{"u"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Exporting Teams for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Exporting Teams for context", "context", config.Config().GetGDGConfig().GetContext())
filter := api.NewTeamFilter(parseTeamGlobalFlags(cd.CobraCommand)...)
savedFiles := rootCmd.GrafanaSvc().UploadTeams(filter)
if len(savedFiles) == 0 {
Expand Down Expand Up @@ -150,7 +150,7 @@ func newTeamsClearCmd() simplecobra.Commander {
cmd.Aliases = []string{"c"}
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
slog.Info("Deleting teams for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Deleting teams for context", "context", config.Config().GetGDGConfig().GetContext())
filter := api.NewTeamFilter(parseTeamGlobalFlags(cd.CobraCommand)...)
rootCmd.TableObj.AppendHeader(table.Row{"type", "team ID", "team Name"})
teams, err := rootCmd.GrafanaSvc().DeleteTeam(filter)
Expand Down
8 changes: 4 additions & 4 deletions cli/backup/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newUsersListCmd() simplecobra.Commander {
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
authLabel, _ := cd.CobraCommand.Flags().GetString("authlabel")
slog.Info("Listing users for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Listing users for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"id", "login", "name", "email", "admin", "disabled", "default Password", "authLabels"})
users := rootCmd.GrafanaSvc().ListUsers(service.NewUserFilter(authLabel))
if len(users) == 0 {
Expand Down Expand Up @@ -79,7 +79,7 @@ func newUsersDownloadCmd() simplecobra.Commander {
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
authLabel, _ := cd.CobraCommand.Flags().GetString("authlabel")
savedFiles := rootCmd.GrafanaSvc().DownloadUsers(service.NewUserFilter(authLabel))
slog.Info("Importing Users for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Importing Users for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})
if len(savedFiles) == 0 {
slog.Info("No users found")
Expand All @@ -104,7 +104,7 @@ func newUsersUploadCmd() simplecobra.Commander {
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
authLabel, _ := cd.CobraCommand.Flags().GetString("authlabel")
slog.Info("Uploading Users to context", "context", config.Config().AppConfig.GetContext())
slog.Info("Uploading Users to context", "context", config.Config().GetGDGConfig().GetContext())
savedFiles := rootCmd.GrafanaSvc().UploadUsers(service.NewUserFilter(authLabel))
rootCmd.TableObj.AppendHeader(table.Row{"id", "login", "name", "email", "grafanaAdmin", "disabled", "default Password", "authLabels"})
if len(savedFiles) == 0 {
Expand Down Expand Up @@ -136,7 +136,7 @@ func newUsersClearCmd() simplecobra.Commander {
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
authLabel, _ := cd.CobraCommand.Flags().GetString("authlabel")
savedFiles := rootCmd.GrafanaSvc().DeleteAllUsers(service.NewUserFilter(authLabel))
slog.Info("Delete Users for context", "context", config.Config().AppConfig.GetContext())
slog.Info("Delete Users for context", "context", config.Config().GetGDGConfig().GetContext())
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})
if len(savedFiles) == 0 {
slog.Info("No users found")
Expand Down
Loading

0 comments on commit c71250e

Please sign in to comment.