Skip to content

Commit

Permalink
[BUG] Addressing Version Check Issue
Browse files Browse the repository at this point in the history
Fixes #221

ChangeLog:
  - Removed Dependency of config for version info
  - Updating documentation for context
  - Refactoring and removing api calls that are no longer needed
  • Loading branch information
safaci2000 committed Nov 22, 2023
1 parent c3b4941 commit 7c99e8b
Show file tree
Hide file tree
Showing 34 changed files with 117 additions and 140 deletions.
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 @@ -52,6 +52,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
36 changes: 0 additions & 36 deletions internal/api/accessControl.go

This file was deleted.

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
1 change: 0 additions & 1 deletion internal/service/connection_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
p.SetBuiltinRole(tools.PtrOf(entry.BuiltInRole))
}
_, err = s.client.DatasourcePermissions.AddPermission(p, s.getAuth())
//err = s.extended.AddConnectionPermission(p)
if err != nil {
slog.Error("Failed to update folder permissions")
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/mocks/AlertNotificationsApi.go

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

14 changes: 7 additions & 7 deletions internal/service/mocks/AuthenticationApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/ConnectionPermissions.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/ConnectionsApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/DashboardsApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/Filter.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/FoldersApi.go

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

13 changes: 7 additions & 6 deletions internal/service/mocks/GrafanaService.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/LibraryElementsApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/OrganizationsApi.go

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

14 changes: 7 additions & 7 deletions internal/service/mocks/ServiceAccountApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/Storage.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/TeamsApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/TokenApi.go

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

2 changes: 1 addition & 1 deletion internal/service/mocks/UsersApi.go

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

Loading

0 comments on commit 7c99e8b

Please sign in to comment.