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

Removed Dependency of config for version info #228

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dotenv: ['.env']
tasks:
default:
cmds:
- task: build
- task: build_all
install_tools:
desc: "Install required Dev tools by GDG"
cmds:
Expand Down Expand Up @@ -53,6 +53,11 @@ tasks:
desc: "Build linux binary"
cmds:
- env GOOS='linux' GOARCH='amd64' go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}_linux cmd/gdg/main.go
build_all:
desc: "Buiding All binaries"
cmds:
- task: build
- task: build_generate
build:
desc: "Buiding {{ .BIN_NAME }} {{ .VERSION }}"
cmds:
Expand Down
1 change: 1 addition & 0 deletions cli/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limited to clear/delete, list, download and upload. Any other functionality wil
return cd.CobraCommand.Help()
},
InitCFunc: func(cd *simplecobra.Commandeer, r *support.RootCommand) error {
support.InitConfiguration(cd.CobraCommand)
r.GrafanaSvc().InitOrganizations()
return nil
},
Expand Down
1 change: 0 additions & 1 deletion cli/commandeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func getNewRootCmd() *support.RootCommand {
NameP: "gdg",
CommandEntries: []simplecobra.Commander{
newVersionCmd(),
newContextCmd(),
tools.NewToolsCommand(),
backup.NewBackupCommand(),
},
Expand Down
29 changes: 29 additions & 0 deletions cli/support/init_cfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package support

import (
"github.com/esnet/gdg/internal/config"
appconfig "github.com/esnet/gdg/internal/log"
"github.com/spf13/cobra"
"os"
)

// InitConfiguration Loads configuration, and setups fail over case
func InitConfiguration(cmd *cobra.Command) {
configOverride, _ := cmd.Flags().GetString("config")
if DefaultConfig == "" {
raw, err := os.ReadFile("config/importer-example.yml")
if err == nil {
DefaultConfig = string(raw)
} else {
DefaultConfig = ""
}
}

//Registers sub CommandsList
config.InitConfig(configOverride, DefaultConfig)
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, config.Config().IsDebug())

//Validate current configuration
config.Config().GetDefaultGrafanaConfig().Validate()

}
18 changes: 1 addition & 17 deletions cli/support/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"github.com/bep/simplecobra"
"github.com/esnet/gdg/internal/config"
appconfig "github.com/esnet/gdg/internal/log"
"github.com/esnet/gdg/internal/service"
"github.com/jedib0t/go-pretty/v6/table"
Expand Down Expand Up @@ -63,22 +62,7 @@ func (c *RootCommand) PreRun(this, runner *simplecobra.Commandeer) error {

// initConfiguration Loads configuration, and setups fail over case
func (c *RootCommand) initConfiguration() {
cmd := c.initRunner.CobraCommand
configOverride, _ := cmd.Flags().GetString("config")
if DefaultConfig == "" {
raw, err := os.ReadFile("config/importer-example.yml")
if err == nil {
DefaultConfig = string(raw)
} else {
DefaultConfig = ""
}
}
//Registers sub CommandsList
config.InitConfig(configOverride, DefaultConfig)
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, config.Config().GetGDGConfig().Global.Debug)

//Validate current configuration
config.Config().GetDefaultGrafanaConfig().Validate()
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, false)

}

Expand Down
2 changes: 1 addition & 1 deletion cli/context.go → cli/tools/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cli
package tools

import (
"context"
Expand Down
6 changes: 5 additions & 1 deletion cli/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ func NewToolsCommand() simplecobra.Commander {
NameP: "tools",
Short: description,
Long: description,
CommandsList: []simplecobra.Commander{newDevelCmd(), newUserCommand(), newAuthCmd(), newOrgCommand()},
CommandsList: []simplecobra.Commander{newContextCmd(), newDevelCmd(), newUserCommand(), newAuthCmd(), newOrgCommand()},
WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) {
cmd.Aliases = []string{"t"}
},
InitCFunc: func(cd *simplecobra.Commandeer, r *support.RootCommand) error {
support.InitConfiguration(cd.CobraCommand)
return nil
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
return cd.CobraCommand.Help()
},
Expand Down
13 changes: 6 additions & 7 deletions cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import (
"github.com/esnet/gdg/cli/support"
"github.com/esnet/gdg/internal/version"
"github.com/spf13/cobra"
"os"
"log/slog"
)

func newVersionCmd() simplecobra.Commander {
return &support.SimpleCommand{
NameP: "version",
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, r *support.RootCommand, args []string) error {
stdout := os.Stdout
fmt.Fprintf(stdout, "Build Date: %s\n", version.BuildDate)
fmt.Fprintf(stdout, "Git Commit: %s\n", version.GitCommit)
fmt.Fprintf(stdout, "Version: %s\n", version.Version)
fmt.Fprintf(stdout, "Go Version: %s\n", version.GoVersion)
fmt.Fprintf(stdout, "OS / Arch: %s\n", version.OsArch)
slog.Info(fmt.Sprintf("Build Date: %s", version.BuildDate))
slog.Info(fmt.Sprintf("Git Commit: %s", version.GitCommit))
slog.Info(fmt.Sprintf("Version: %s", version.Version))
slog.Info(fmt.Sprintf("Go Version: %s", version.GoVersion))
slog.Info(fmt.Sprintf("OS / Arch: %s", version.OsArch))
return nil
},
WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) {
Expand Down
1 change: 0 additions & 1 deletion cmd/gdg/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
_ "embed"
"github.com/esnet/gdg/cli"
"github.com/esnet/gdg/cli/support"
"log"
Expand Down
7 changes: 5 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (app *GDGAppConfiguration) GetContextMap() map[string]interface{} {
}

var (
configData *Configuration
configData = new(Configuration)
configSearchPaths = []string{"config", ".", "../config", "../../config", "/etc/gdg"}
)

Expand All @@ -196,7 +196,10 @@ func (s *Configuration) GetContexts() map[string]*GrafanaConfig {

// IsDebug returns true if debug mode is enabled
func (s *Configuration) IsDebug() bool {
return s.GetViperConfig(ViperGdgConfig).GetBool("global.debug")
if val := s.GetViperConfig(ViperGdgConfig); val != nil {
return val.GetBool("global.debug")
}
return false
}

// IgnoreSSL returns true if SSL errors should be ignored
Expand Down
16 changes: 8 additions & 8 deletions internal/service/connection_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package service
import (
"encoding/json"
"fmt"
"log"
"log/slog"
"path/filepath"
"strings"

"github.com/esnet/gdg/internal/config"
"github.com/esnet/gdg/internal/service/filters"
"github.com/esnet/gdg/internal/tools"
"github.com/gosimple/slug"
"github.com/grafana/grafana-openapi-client-go/client/datasource_permissions"
"github.com/grafana/grafana-openapi-client-go/models"
"log"
"log/slog"
"path/filepath"
"strings"
)

type ConnectionPermissions interface {
//Permissions Enterprise only
// Permissions Enterprise only
ListConnectionPermissions(filter filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO
DownloadConnectionPermissions(filter filters.Filter) []string
UploadConnectionPermissions(filter filters.Filter) []string
Expand Down Expand Up @@ -100,15 +101,15 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
slog.Warn("Failed to Decode payload for file", "filename", fileLocation)
continue
}
//Get current permissions
// Get current permissions
permissions, err := s.getConnectionPermission(newEntries.DatasourceID)
if err != nil {
slog.Error("connection permission could not be retrieved, cannot update permissions")
continue
}

success := true
//Delete datasource Permissions
// Delete datasource Permissions
for _, p := range permissions.GetPayload().Permissions {
success = s.deleteConnectionPermission(p.ID, newEntries.DatasourceID)
}
Expand All @@ -128,7 +129,6 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
p.SetBuiltinRole(tools.PtrOf(entry.BuiltInRole))
}
_, err = s.GetClient().DatasourcePermissions.AddPermission(p)
//err = s.extended.AddConnectionPermission(p)
if err != nil {
slog.Error("Failed to update folder permissions")
} else {
Expand Down
16 changes: 8 additions & 8 deletions internal/service/mocks/AuthenticationApi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions internal/service/mocks/GrafanaService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions internal/service/mocks/ServiceAccountApi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading