Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f44b6f

Browse files
committedNov 22, 2023
[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 560d874 commit 6f44b6f

35 files changed

+117
-141
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:
@@ -52,6 +52,11 @@ tasks:
5252
desc: "Build linux binary"
5353
cmds:
5454
- env GOOS='linux' GOARCH='amd64' go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}_linux cmd/gdg/main.go
55+
build_all:
56+
desc: "Buiding All binaries"
57+
cmds:
58+
- task: build
59+
- task: build_generate
5560
build:
5661
desc: "Buiding {{ .BIN_NAME }} {{ .VERSION }}"
5762
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/api/accessControl.go

-36
This file was deleted.

‎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

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
128128
p.SetBuiltinRole(tools.PtrOf(entry.BuiltInRole))
129129
}
130130
_, err = s.client.DatasourcePermissions.AddPermission(p, s.getAuth())
131-
//err = s.extended.AddConnectionPermission(p)
132131
if err != nil {
133132
slog.Error("Failed to update folder permissions")
134133
} else {

‎internal/service/mocks/AlertNotificationsApi.go

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

‎internal/service/mocks/AuthenticationApi.go

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

‎internal/service/mocks/ConnectionPermissions.go

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

‎internal/service/mocks/ConnectionsApi.go

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

‎internal/service/mocks/DashboardsApi.go

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

‎internal/service/mocks/Filter.go

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

‎internal/service/mocks/FoldersApi.go

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

‎internal/service/mocks/GrafanaService.go

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

‎internal/service/mocks/LibraryElementsApi.go

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

‎internal/service/mocks/OrganizationsApi.go

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

‎internal/service/mocks/ServiceAccountApi.go

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

‎internal/service/mocks/Storage.go

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

‎internal/service/mocks/TeamsApi.go

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

‎internal/service/mocks/TokenApi.go

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

0 commit comments

Comments
 (0)
Please sign in to comment.