Add configuration flags & env variables
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0fb6e0b6e9
commit
52703cb28f
2 changed files with 51 additions and 26 deletions
28
main.go
28
main.go
|
@ -6,34 +6,26 @@ import (
|
|||
"log"
|
||||
"slices"
|
||||
|
||||
"git.ar21.de/yolokube/grafana-backuper/cfg"
|
||||
"git.ar21.de/yolokube/grafana-backuper/pkg/git"
|
||||
"git.ar21.de/yolokube/grafana-backuper/pkg/grafana"
|
||||
)
|
||||
|
||||
const (
|
||||
grafanaURL = "https://grafana.services.yolokube.de"
|
||||
grafanaAPIKey = ""
|
||||
gitBranch = "main"
|
||||
gitRepoURL = ""
|
||||
gitUsername = ""
|
||||
gitEmail = ""
|
||||
gitPassword = ""
|
||||
privateGPGKeyFile = ""
|
||||
)
|
||||
|
||||
func main() {
|
||||
appSettings := cfg.Parse()
|
||||
|
||||
ctx := context.Background()
|
||||
client, err := grafana.NewClient(grafanaURL, grafanaAPIKey, grafana.DefaultHTTPClient)
|
||||
client, err := grafana.NewClient(appSettings.GrafanaURL, appSettings.GrafanaToken, grafana.DefaultHTTPClient)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating the grafana client: %v", err)
|
||||
}
|
||||
|
||||
gitdata := git.NewPayload(privateGPGKeyFile)
|
||||
if err = gitdata.GetRepo(gitRepoURL, gitUsername, gitPassword); err != nil {
|
||||
gitdata := git.NewPayload(appSettings.GPGKey)
|
||||
if err = gitdata.GetRepo(appSettings.GitRepoURL, appSettings.GitUser, appSettings.GitPass); err != nil {
|
||||
log.Fatalf("Error cloning git repo: %v", err)
|
||||
}
|
||||
|
||||
gitdata.AddCommitter(gitUsername, gitEmail)
|
||||
gitdata.AddCommitter(appSettings.GitUser, appSettings.GitEmail)
|
||||
|
||||
dashboards, err := client.SearchDashboards(ctx, "", false)
|
||||
if err != nil {
|
||||
|
@ -60,7 +52,7 @@ func main() {
|
|||
for _, version := range versions {
|
||||
gitdata.UpdateVersion(version)
|
||||
|
||||
if gitdata.IsVersionCommitted(gitBranch) {
|
||||
if gitdata.IsVersionCommitted(appSettings.GitBranch) {
|
||||
fmt.Printf("%s/%s - %s: %s -> already committed\n", dashboardInfo.FolderTitle, dashboard.Title, version.CreatedBy, version.Message)
|
||||
continue
|
||||
}
|
||||
|
@ -85,8 +77,8 @@ func main() {
|
|||
log.Fatalf("Error creating commit for dashboard %s version %d: %v", dashboard.Title, info.Version, err)
|
||||
}
|
||||
|
||||
if err = gitdata.PushToRemote(gitUsername, gitPassword); err != nil {
|
||||
log.Fatalf("Error pushing to remote repo %s: %v", gitRepoURL, err)
|
||||
if err = gitdata.PushToRemote(appSettings.GitUser, appSettings.GitPass); err != nil {
|
||||
log.Fatalf("Error pushing to remote repo %s: %v", appSettings.GitRepoURL, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue