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 Dec 14, 2023
1 parent 7503ab7 commit dfb976d
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 127 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 @@ -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
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
12 changes: 6 additions & 6 deletions internal/service/mocks/AuthenticationApi.go

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

11 changes: 6 additions & 5 deletions internal/service/mocks/GrafanaService.go

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

12 changes: 6 additions & 6 deletions internal/service/mocks/ServiceAccountApi.go

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

10 changes: 5 additions & 5 deletions internal/service/serviceaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package service

import (
"fmt"
"github.com/esnet/gdg/internal/types"
"log/slog"

"github.com/esnet/gdg/internal/api"
"github.com/esnet/gdg/internal/tools"
"github.com/grafana/grafana-openapi-client-go/client/service_accounts"
"github.com/grafana/grafana-openapi-client-go/models"
Expand All @@ -13,7 +13,7 @@ import (
)

type ServiceAccountApi interface {
ListServiceAccounts() []*api.ServiceAccountDTOWithTokens
ListServiceAccounts() []*types.ServiceAccountDTOWithTokens
ListServiceAccountsTokens(id int64) ([]*models.TokenDTO, error)
DeleteAllServiceAccounts() []string
DeleteServiceAccountTokens(serviceId int64) []string
Expand Down Expand Up @@ -52,7 +52,7 @@ func (s *DashNGoImpl) CreateServiceAccountToken(serviceAccountId int64, name str
return token.GetPayload(), nil
}

func (s *DashNGoImpl) ListServiceAccounts() []*api.ServiceAccountDTOWithTokens {
func (s *DashNGoImpl) ListServiceAccounts() []*types.ServiceAccountDTOWithTokens {
p := service_accounts.NewSearchOrgServiceAccountsWithPagingParams()
p.Disabled = tools.PtrOf(false)
p.Perpage = tools.PtrOf(int64(5000))
Expand All @@ -62,8 +62,8 @@ func (s *DashNGoImpl) ListServiceAccounts() []*api.ServiceAccountDTOWithTokens {
log.Fatal("unable to retrieve service accounts")
}
data := resp.GetPayload()
result := lo.Map(data.ServiceAccounts, func(entity *models.ServiceAccountDTO, _ int) *api.ServiceAccountDTOWithTokens {
t := api.ServiceAccountDTOWithTokens{
result := lo.Map(data.ServiceAccounts, func(entity *models.ServiceAccountDTO, _ int) *types.ServiceAccountDTOWithTokens {
t := types.ServiceAccountDTOWithTokens{
ServiceAccount: entity,
}
return &t
Expand Down
2 changes: 1 addition & 1 deletion internal/api/models.go → internal/types/models.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package types

import "github.com/grafana/grafana-openapi-client-go/models"

Expand Down
2 changes: 1 addition & 1 deletion website/content/en/docs/gdg/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ The pattern for GDG's is as follows: `GDG_SECTION__SECTION__keyname`
For example if I want to set the context name to a different value I can use:

```sh
GDG_CONTEXT_NAME="testing" gdg ctx show ## Which will override the value from the context file.
GDG_CONTEXT_NAME="testing" gdg tools ctx show ## Which will override the value from the context file.
GDG_CONTEXTS__TESTING__URL="www.google.com" Will override the URL with the one provided.
```

Expand Down
2 changes: 1 addition & 1 deletion website/content/en/docs/gdg/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ weight: 13

You can create new context configuration using an interactive setup.
```
$ ./bin/gdg ctx new mycontext
$ ./bin/gdg tools ctx new mycontext
```

When creating a new context, you will be asked for authorization type, your default datasource and username/password, along with which folders you wish to manage under the context. You have three options:
Expand Down
2 changes: 1 addition & 1 deletion website/content/en/docs/gdg/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ You can verify the version by running `gdg version`.

## Configuration

You can then create a simple configuration using `gdg ctx new` which will do a best effort to guide to setup a basic config that will get you up and going or read the more detailed documentation that can be found [here](/gdg/docs/gdg/configuration/)
You can then create a simple configuration using `gdg tools ctx new` which will do a best effort to guide to setup a basic config that will get you up and going or read the more detailed documentation that can be found [here](/gdg/docs/gdg/configuration/)


**NOTE**: wizard doesn't currently support ALL features but it should help you get a head start.
Loading

0 comments on commit dfb976d

Please sign in to comment.