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

feat: db driven platform settings #554

Merged
merged 36 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8cbe1b2
wip: platform settings, errors from refactor
plyr4 Apr 3, 2024
7bdb79c
chore: delete legacy events fields:
plyr4 Apr 3, 2024
8001c15
chore: update secret validate switch
plyr4 Apr 3, 2024
ea0237e
chore: verbose test types
plyr4 Apr 3, 2024
e4705ca
chore: more valid events
plyr4 Apr 3, 2024
70c38a0
fix: use generated validevents list
plyr4 Apr 3, 2024
a80af93
fix: use generated validevents list
plyr4 Apr 3, 2024
6cd06f0
fix: pr validator
plyr4 Apr 3, 2024
1909d1b
chore: bump go.mod
plyr4 Apr 3, 2024
0b6c66b
chore: appease linter
plyr4 Apr 3, 2024
0e780e4
fix: bundling api worker types changes
plyr4 Apr 3, 2024
6692668
fix: use hardcoded unlisted event tags
plyr4 Apr 3, 2024
5e1e606
fix: remove debug
plyr4 Apr 3, 2024
e867117
fix: remove debug
plyr4 Apr 3, 2024
f2c7307
chore: appease linter
plyr4 Apr 3, 2024
628a091
chore: merge with upstream
plyr4 Apr 3, 2024
34a5697
chore: merge with main
plyr4 Apr 30, 2024
0acbebf
chore: remove validatevents
plyr4 Apr 30, 2024
9f770cb
chore: remove go mod replace
plyr4 Apr 30, 2024
a01afd2
feat: settings view and update with optionals
plyr4 May 3, 2024
21c6392
feat: tests
plyr4 May 3, 2024
0e35dc5
feat: more tests
plyr4 May 3, 2024
60cc758
chore: comments
plyr4 May 3, 2024
7302855
Merge branch 'main' of github.com:go-vela/cli into feat/platform-sett…
plyr4 May 13, 2024
6df02f8
feat: platform settings with file update
plyr4 May 13, 2024
7249022
chore: bump mod
plyr4 May 13, 2024
acb79ff
chore: cleanup and command examples
plyr4 May 13, 2024
2a43f71
enhance: add and drop flags for allowlists
plyr4 May 13, 2024
5204027
enhance: add and drop flags for queue routes
plyr4 May 13, 2024
c2c7978
chore: lint
plyr4 May 13, 2024
bf84804
fix: whitespace
plyr4 May 13, 2024
e8e04c7
fix: typos
plyr4 May 13, 2024
41988ff
fix: typo
plyr4 May 14, 2024
e4a0688
fix: rm alias in example
plyr4 May 14, 2024
5426ea3
fix: example quote recommendation
plyr4 May 14, 2024
a1bf687
fix: example quote recommendation
plyr4 May 14, 2024
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
2 changes: 1 addition & 1 deletion action/pipeline/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
t.Errorf("unable to create client: %v", err)
}

client.TemplateDepth = 1
client.SetTemplateDepth(1)

Check failure on line 180 in action/pipeline/validate_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] action/pipeline/validate_test.go#L180

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
Raw output
action/pipeline/validate_test.go:180:9: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
// SPDX-License-Identifier: Apache-2.0
plyr4 marked this conversation as resolved.
Show resolved Hide resolved

// setup tests
tests := []struct {
Expand Down
8 changes: 8 additions & 0 deletions action/settings/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

// The defined CLI settings actions for Vela.
//
// Usage:
//
// import "github.com/go-vela/cli/action/settings"
package settings
24 changes: 24 additions & 0 deletions action/settings/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0

package settings

// Config represents the configuration necessary
// to perform settings related requests with Vela.
type Config struct {
Action string
Compiler
Queue
RepoAllowlist *[]string
ScheduleAllowlist *[]string
Output string
}

type Compiler struct {
CloneImage *string
TemplateDepth *int
StarlarkExecLimit *uint64
}

type Queue struct {
Routes *[]string
}
67 changes: 67 additions & 0 deletions action/settings/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: Apache-2.0

package settings

import (
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/server/api/types/settings"

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / build (windows)

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / build (darwin)

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / build (linux)

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / build (darwin)

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / build (windows)

no required module provides package github.com/go-vela/server/api/types/settings; to add it:

Check failure on line 10 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / build (linux)

no required module provides package github.com/go-vela/server/api/types/settings; to add it:
)

// Update modifies settings based off the provided configuration.
func (c *Config) Update(client *vela.Client) error {
logrus.Debug("executing update for settings configuration")

// create the settings object
s := &settings.Platform{
Queue: &settings.Queue{
Routes: c.Queue.Routes,
},
Compiler: &settings.Compiler{
CloneImage: c.Compiler.CloneImage,
TemplateDepth: c.Compiler.TemplateDepth,
StarlarkExecLimit: c.Compiler.StarlarkExecLimit,
},
RepoAllowlist: c.RepoAllowlist,
ScheduleAllowlist: c.ScheduleAllowlist,
}

logrus.Trace("updating settings")

// send API call to modify settings
s_, _, err := client.Admin.Settings.Update(s)

Check failure on line 34 in action/settings/update.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] action/settings/update.go#L34

client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
Raw output
action/settings/update.go:34:29: client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
	s_, _, err := client.Admin.Settings.Update(s)
	                           ^
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

// handle the output based off the provided configuration
switch c.Output {
case output.DriverDump:
// output in dump format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Dump
return output.Dump(s_)
case output.DriverJSON:
// output in JSON format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON
return output.JSON(s_)
case output.DriverSpew:
// output in spew format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Spew
return output.Spew(s_)
case output.DriverYAML:
// output in YAML format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML
return output.YAML(s_)
default:
// output in stdout format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Stdout
return output.Stdout(s_)
}
}
88 changes: 88 additions & 0 deletions action/settings/update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: Apache-2.0

package settings

import (
"net/http/httptest"
"testing"

"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/server/mock/server"
)

func TestSettings_Config_Update(t *testing.T) {
// setup test server
s := httptest.NewServer(server.FakeHandler())

// create a vela client
client, err := vela.NewClient(s.URL, "vela", nil)
if err != nil {
t.Errorf("unable to create client: %v", err)
}

// setup tests
tests := []struct {
failure bool
config *Config
}{
{
failure: false,
config: &Config{
Action: "update",
Output: "",
},
},
{
failure: false,
config: &Config{
Action: "update",
Output: "dump",
},
},
{
failure: false,
config: &Config{
Action: "update",
Output: "json",
},
},
{
failure: false,
config: &Config{
Action: "update",
Output: "spew",
},
},
{
failure: false,
config: &Config{
Action: "update",
Output: "yaml",
},
},
{
failure: true,
config: &Config{
Action: "update",
Output: "",
},
},
}

// run tests
for _, test := range tests {
err := test.config.Update(client)

if test.failure {
if err == nil {
t.Errorf("Update should have returned err")
}

continue
}

if err != nil {
t.Errorf("Update returned err: %v", err)
}
}
}
14 changes: 14 additions & 0 deletions action/settings/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0

package settings

import (
"github.com/sirupsen/logrus"
)

// Validate verifies the configuration provided.
func (c *Config) Validate() error {
logrus.Debug("validating settings configuration")

return nil
}
110 changes: 110 additions & 0 deletions action/settings/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// SPDX-License-Identifier: Apache-2.0

package settings

import (
"testing"
)

func TestSettings_Config_Validate(t *testing.T) {
// setup tests
tests := []struct {
failure bool
config *Config
}{
{
failure: false,
config: &Config{
Action: "add",
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "add",
Output: "",
},
},
{
failure: false,
config: &Config{
Action: "add",
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "add",
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "add",
Output: "",
},
},
{
failure: false,
config: &Config{
Action: "view",
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "view",
Output: "",
},
},
{
failure: false,
config: &Config{
Action: "get",
Output: "",
},
},
{
failure: false,
config: &Config{
Action: "update",
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "update",
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "update",
Output: "",
},
},
}

// run tests
for _, test := range tests {
err := test.config.Validate()

if test.failure {
if err == nil {
t.Errorf("Validate should have returned err")
}

continue
}

if err != nil {
t.Errorf("Validate returned err: %v", err)
}
}
}
53 changes: 53 additions & 0 deletions action/settings/view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: Apache-2.0

package settings

import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"
)

// View inspects settings based off the provided configuration.
func (c *Config) View(client *vela.Client) error {
logrus.Debug("executing view for settings configuration")

logrus.Trace("inspecting settings")

response, _, err := client.Admin.Settings.Get()

Check failure on line 20 in action/settings/view.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] action/settings/view.go#L20

client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
Raw output
action/settings/view.go:20:35: client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
	response, _, err := client.Admin.Settings.Get()
	                                 ^
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("unable to retrieve settings: %w", err)
}

// handle the output based off the provided configuration
switch c.Output {
case output.DriverDump:
// output in dump format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Dump
return output.Dump(response)
case output.DriverJSON:
// output in JSON format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON
return output.JSON(response)
case output.DriverSpew:
// output in spew format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Spew
return output.Spew(response)
case output.DriverYAML:
// output in YAML format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML
return output.YAML(response)
default:
// output in stdout format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Stdout
return output.Stdout(response)
}
}
Loading
Loading