Skip to content

Commit d91ef45

Browse files
committed
[BUG] Addressing Version Check Issue
Fixes #221 ChangeLog: - Removed Dependency of config for version info - Updating documentation for context - Refactoring and removing api calls that are no longer needed
1 parent e86e5c6 commit d91ef45

22 files changed

+115
-104
lines changed

Taskfile.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dotenv: ['.env']
1414
tasks:
1515
default:
1616
cmds:
17-
- task: build
17+
- task: build_all
1818
install_tools:
1919
desc: "Install required Dev tools by GDG"
2020
cmds:
@@ -53,6 +53,11 @@ tasks:
5353
desc: "Build linux binary"
5454
cmds:
5555
- env GOOS='linux' GOARCH='amd64' go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}_linux cmd/gdg/main.go
56+
build_all:
57+
desc: "Buiding All binaries"
58+
cmds:
59+
- task: build
60+
- task: build_generate
5661
build:
5762
desc: "Buiding {{ .BIN_NAME }} {{ .VERSION }}"
5863
cmds:

cli/backup/backup.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ limited to clear/delete, list, download and upload. Any other functionality wil
2121
return cd.CobraCommand.Help()
2222
},
2323
InitCFunc: func(cd *simplecobra.Commandeer, r *support.RootCommand) error {
24+
support.InitConfiguration(cd.CobraCommand)
2425
r.GrafanaSvc().InitOrganizations()
2526
return nil
2627
},

cli/commandeer.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func getNewRootCmd() *support.RootCommand {
3838
NameP: "gdg",
3939
CommandEntries: []simplecobra.Commander{
4040
newVersionCmd(),
41-
newContextCmd(),
4241
tools.NewToolsCommand(),
4342
backup.NewBackupCommand(),
4443
},

cli/support/init_cfg.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package support
2+
3+
import (
4+
"github.com/esnet/gdg/internal/config"
5+
appconfig "github.com/esnet/gdg/internal/log"
6+
"github.com/spf13/cobra"
7+
"os"
8+
)
9+
10+
// InitConfiguration Loads configuration, and setups fail over case
11+
func InitConfiguration(cmd *cobra.Command) {
12+
configOverride, _ := cmd.Flags().GetString("config")
13+
if DefaultConfig == "" {
14+
raw, err := os.ReadFile("config/importer-example.yml")
15+
if err == nil {
16+
DefaultConfig = string(raw)
17+
} else {
18+
DefaultConfig = ""
19+
}
20+
}
21+
22+
//Registers sub CommandsList
23+
config.InitConfig(configOverride, DefaultConfig)
24+
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, config.Config().IsDebug())
25+
26+
//Validate current configuration
27+
config.Config().GetDefaultGrafanaConfig().Validate()
28+
29+
}

cli/support/root.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"github.com/bep/simplecobra"
7-
"github.com/esnet/gdg/internal/config"
87
appconfig "github.com/esnet/gdg/internal/log"
98
"github.com/esnet/gdg/internal/service"
109
"github.com/jedib0t/go-pretty/v6/table"
@@ -63,22 +62,7 @@ func (c *RootCommand) PreRun(this, runner *simplecobra.Commandeer) error {
6362

6463
// initConfiguration Loads configuration, and setups fail over case
6564
func (c *RootCommand) initConfiguration() {
66-
cmd := c.initRunner.CobraCommand
67-
configOverride, _ := cmd.Flags().GetString("config")
68-
if DefaultConfig == "" {
69-
raw, err := os.ReadFile("config/importer-example.yml")
70-
if err == nil {
71-
DefaultConfig = string(raw)
72-
} else {
73-
DefaultConfig = ""
74-
}
75-
}
76-
//Registers sub CommandsList
77-
config.InitConfig(configOverride, DefaultConfig)
78-
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, config.Config().GetGDGConfig().Global.Debug)
79-
80-
//Validate current configuration
81-
config.Config().GetDefaultGrafanaConfig().Validate()
65+
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, false)
8266

8367
}
8468

cli/context.go cli/tools/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cli
1+
package tools
22

33
import (
44
"context"

cli/tools/tools.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ func NewToolsCommand() simplecobra.Commander {
1313
NameP: "tools",
1414
Short: description,
1515
Long: description,
16-
CommandsList: []simplecobra.Commander{newDevelCmd(), newUserCommand(), newAuthCmd(), newOrgCommand()},
16+
CommandsList: []simplecobra.Commander{newContextCmd(), newDevelCmd(), newUserCommand(), newAuthCmd(), newOrgCommand()},
1717
WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) {
1818
cmd.Aliases = []string{"t"}
1919
},
20+
InitCFunc: func(cd *simplecobra.Commandeer, r *support.RootCommand) error {
21+
support.InitConfiguration(cd.CobraCommand)
22+
return nil
23+
},
2024
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
2125
return cd.CobraCommand.Help()
2226
},

cli/version.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ import (
77
"github.com/esnet/gdg/cli/support"
88
"github.com/esnet/gdg/internal/version"
99
"github.com/spf13/cobra"
10-
"os"
10+
"log/slog"
1111
)
1212

1313
func newVersionCmd() simplecobra.Commander {
1414
return &support.SimpleCommand{
1515
NameP: "version",
1616
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, r *support.RootCommand, args []string) error {
17-
stdout := os.Stdout
18-
fmt.Fprintf(stdout, "Build Date: %s\n", version.BuildDate)
19-
fmt.Fprintf(stdout, "Git Commit: %s\n", version.GitCommit)
20-
fmt.Fprintf(stdout, "Version: %s\n", version.Version)
21-
fmt.Fprintf(stdout, "Go Version: %s\n", version.GoVersion)
22-
fmt.Fprintf(stdout, "OS / Arch: %s\n", version.OsArch)
17+
slog.Info(fmt.Sprintf("Build Date: %s", version.BuildDate))
18+
slog.Info(fmt.Sprintf("Git Commit: %s", version.GitCommit))
19+
slog.Info(fmt.Sprintf("Version: %s", version.Version))
20+
slog.Info(fmt.Sprintf("Go Version: %s", version.GoVersion))
21+
slog.Info(fmt.Sprintf("OS / Arch: %s", version.OsArch))
2322
return nil
2423
},
2524
WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) {

cmd/gdg/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
_ "embed"
54
"github.com/esnet/gdg/cli"
65
"github.com/esnet/gdg/cli/support"
76
"log"

internal/config/config.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (app *GDGAppConfiguration) GetContextMap() map[string]interface{} {
171171
}
172172

173173
var (
174-
configData *Configuration
174+
configData = new(Configuration)
175175
configSearchPaths = []string{"config", ".", "../config", "../../config", "/etc/gdg"}
176176
)
177177

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

197197
// IsDebug returns true if debug mode is enabled
198198
func (s *Configuration) IsDebug() bool {
199-
return s.GetViperConfig(ViperGdgConfig).GetBool("global.debug")
199+
if val := s.GetViperConfig(ViperGdgConfig); val != nil {
200+
return val.GetBool("global.debug")
201+
}
202+
return false
200203
}
201204

202205
// IgnoreSSL returns true if SSL errors should be ignored

internal/service/connection_permissions.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ package service
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
7+
"log/slog"
8+
"path/filepath"
9+
"strings"
10+
611
"github.com/esnet/gdg/internal/config"
712
"github.com/esnet/gdg/internal/service/filters"
813
"github.com/esnet/gdg/internal/tools"
914
"github.com/gosimple/slug"
1015
"github.com/grafana/grafana-openapi-client-go/client/datasource_permissions"
1116
"github.com/grafana/grafana-openapi-client-go/models"
12-
"log"
13-
"log/slog"
14-
"path/filepath"
15-
"strings"
1617
)
1718

1819
type ConnectionPermissions interface {
19-
//Permissions Enterprise only
20+
// Permissions Enterprise only
2021
ListConnectionPermissions(filter filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO
2122
DownloadConnectionPermissions(filter filters.Filter) []string
2223
UploadConnectionPermissions(filter filters.Filter) []string
@@ -100,15 +101,15 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
100101
slog.Warn("Failed to Decode payload for file", "filename", fileLocation)
101102
continue
102103
}
103-
//Get current permissions
104+
// Get current permissions
104105
permissions, err := s.getConnectionPermission(newEntries.DatasourceID)
105106
if err != nil {
106107
slog.Error("connection permission could not be retrieved, cannot update permissions")
107108
continue
108109
}
109110

110111
success := true
111-
//Delete datasource Permissions
112+
// Delete datasource Permissions
112113
for _, p := range permissions.GetPayload().Permissions {
113114
success = s.deleteConnectionPermission(p.ID, newEntries.DatasourceID)
114115
}
@@ -128,7 +129,6 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
128129
p.SetBuiltinRole(tools.PtrOf(entry.BuiltInRole))
129130
}
130131
_, err = s.GetClient().DatasourcePermissions.AddPermission(p)
131-
//err = s.extended.AddConnectionPermission(p)
132132
if err != nil {
133133
slog.Error("Failed to update folder permissions")
134134
} else {

internal/service/mocks/AuthenticationApi.go

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/mocks/GrafanaService.go

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/mocks/ServiceAccountApi.go

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)