Skip to content

Commit 802f1d4

Browse files
authored
feat: plural cd settings agents path/to/yaml (#502)
* plural cd settings agents path/to/yaml * update only agent settings
1 parent c34749f commit 802f1d4

9 files changed

Lines changed: 108 additions & 6 deletions

File tree

cmd/plural/cd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (p *Plural) cdCommands() []cli.Command {
3131
p.cdRepositories(),
3232
p.cdPipelines(),
3333
p.cdNotifications(),
34+
p.cdSettings(),
3435
{
3536
Name: "install",
3637
Action: p.handleInstallDeploymentsOperator,

cmd/plural/cd_settings.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package plural
2+
3+
import (
4+
consoleclient "github.com/pluralsh/console-client-go"
5+
"github.com/pluralsh/plural-cli/pkg/utils"
6+
"github.com/urfave/cli"
7+
)
8+
9+
func (p *Plural) cdSettings() cli.Command {
10+
return cli.Command{
11+
Name: "settings",
12+
Subcommands: p.cdSettingsCommands(),
13+
Usage: "manage CD settings",
14+
}
15+
}
16+
17+
func (p *Plural) cdSettingsCommands() []cli.Command {
18+
return []cli.Command{
19+
{
20+
Name: "agents",
21+
ArgsUsage: "FILENAME",
22+
Action: latestVersion(requireArgs(p.handleUpdateAgents, []string{"FILENAME"})),
23+
Usage: "update agents settings",
24+
},
25+
}
26+
}
27+
28+
func (p *Plural) handleUpdateAgents(c *cli.Context) error {
29+
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
30+
return err
31+
}
32+
33+
filepath := c.Args().Get(0)
34+
content, err := utils.ReadFile(filepath)
35+
if err != nil {
36+
return err
37+
}
38+
attr := &consoleclient.DeploymentSettingsAttributes{
39+
AgentHelmValues: &content,
40+
}
41+
res, err := p.ConsoleClient.UpdateDeploymentSettings(*attr)
42+
if err != nil {
43+
return err
44+
}
45+
46+
utils.Success("%s settings updated successfully", res.UpdateDeploymentSettings.Name)
47+
return nil
48+
}

pkg/console/console.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type ConsoleClient interface {
4545
KickClusterService(serviceId, serviceName, clusterName *string) (*consoleclient.ServiceDeploymentExtended, error)
4646
ListNotificationSinks(after *string, first *int64) (*consoleclient.ListNotificationSinks_NotificationSinks, error)
4747
CreateNotificationSinks(attr consoleclient.NotificationSinkAttributes) (*consoleclient.NotificationSinkFragment, error)
48+
UpdateDeploymentSettings(attr consoleclient.DeploymentSettingsAttributes) (*consoleclient.UpdateDeploymentSettings, error)
4849
}
4950

5051
type authedTransport struct {

pkg/console/settings.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package console
2+
3+
import (
4+
"fmt"
5+
6+
gqlclient "github.com/pluralsh/console-client-go"
7+
"github.com/pluralsh/plural-cli/pkg/api"
8+
)
9+
10+
func (c *consoleClient) UpdateDeploymentSettings(attr gqlclient.DeploymentSettingsAttributes) (*gqlclient.UpdateDeploymentSettings, error) {
11+
resp, err := c.client.UpdateDeploymentSettings(c.ctx, attr)
12+
if err != nil {
13+
return nil, api.GetErrorResponse(err, "UpdateDeploymentSettings")
14+
}
15+
if resp == nil {
16+
return nil, fmt.Errorf("returned UpdateDeploymentSettings are nil")
17+
}
18+
19+
return resp, nil
20+
}

pkg/pr/updates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func applyUpdates(updates *UpdateSpec, ctx map[string]interface{}) error {
5353
}
5454

5555
func processRegexReplacements(replacements []RegexReplacement, ctx map[string]interface{}) error {
56-
if len(replacements) <= 0 {
56+
if len(replacements) == 0 {
5757
return nil
5858
}
5959

pkg/provider/linode.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//nolint
2-
31
package provider
42

53
import (
@@ -35,6 +33,7 @@ type LinodeProvider struct {
3533
writer manifest.Writer
3634
}
3735

36+
//nolint:all
3837
func getLinodeSurvey() (surveys []*survey.Question, err error) {
3938
client, err := linodeClient()
4039
if err != nil {
@@ -60,6 +59,7 @@ func getLinodeSurvey() (surveys []*survey.Question, err error) {
6059
return
6160
}
6261

62+
//nolint:all
6363
func mkLinode(conf config.Config) (provider *LinodeProvider, err error) {
6464
provider = &LinodeProvider{}
6565
s, err := getLinodeSurvey()
@@ -92,6 +92,7 @@ func mkLinode(conf config.Config) (provider *LinodeProvider, err error) {
9292
return
9393
}
9494

95+
//nolint:all
9596
func linodeFromManifest(man *manifest.ProjectManifest) (*LinodeProvider, error) {
9697
client, err := linodeClient()
9798
if err != nil {
@@ -106,6 +107,7 @@ func linodeFromManifest(man *manifest.ProjectManifest) (*LinodeProvider, error)
106107
}, nil
107108
}
108109

110+
//nolint:all
109111
func linodeClient() (*linodego.Client, error) {
110112
apiKey, ok := os.LookupEnv("LINODE_TOKEN")
111113
if !ok {

pkg/test/mocks/Client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/test/mocks/ConsoleClient.go

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/test/mocks/Kube.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)