Skip to content

Commit 2a0bd3f

Browse files
Add support for prefix on password type (#378)
The prefix and suffix conditions currently only apply for string not password types, that should be modified
1 parent 5e549ff commit 2a0bd3f

4 files changed

Lines changed: 10 additions & 145 deletions

File tree

cmd/plural/deploy.go

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ func (p *Plural) doBuild(installation *api.Installation, force bool) error {
121121
fmt.Printf("Building workspace for %s\n", repoName)
122122

123123
if !wkspace.Configured(repoName) {
124-
return fmt.Errorf("You have not locally configured %s but have it registered as an installation in our api, either delete it with `plural apps uninstall %s` or install it locally via a bundle in `plural bundle list %s`", repoName, repoName, repoName)
124+
fmt.Printf("You have not locally configured %s but have it registered as an installation in our api, ", repoName)
125+
fmt.Printf("either delete it with `plural apps uninstall %s` or install it locally via a bundle in `plural bundle list %s`\n", repoName, repoName)
126+
return nil
125127
}
126128

127129
workspace, err := wkspace.New(p.Client, installation)
@@ -148,42 +150,6 @@ func (p *Plural) doBuild(installation *api.Installation, force bool) error {
148150
return err
149151
}
150152

151-
func (p *Plural) validate(c *cli.Context) error {
152-
p.InitPluralClient()
153-
if c.IsSet("only") {
154-
installation, err := p.GetInstallation(c.String("only"))
155-
if err != nil {
156-
return api.GetErrorResponse(err, "GetInstallation")
157-
}
158-
return p.doValidate(installation)
159-
}
160-
161-
installations, err := p.getSortedInstallations("")
162-
if err != nil {
163-
return err
164-
}
165-
166-
for _, installation := range installations {
167-
if err := p.doValidate(installation); err != nil {
168-
return err
169-
}
170-
}
171-
172-
utils.Success("Workspace providers are properly configured!\n")
173-
return nil
174-
}
175-
176-
func (p *Plural) doValidate(installation *api.Installation) error {
177-
p.InitPluralClient()
178-
utils.Highlight("Validating repository %s\n", installation.Repository.Name)
179-
workspace, err := wkspace.New(p.Client, installation)
180-
if err != nil {
181-
return err
182-
}
183-
184-
return workspace.Validate()
185-
}
186-
187153
func (p *Plural) info(c *cli.Context) error {
188154
p.InitPluralClient()
189155
repo := c.Args().Get(0)

cmd/plural/deploy_test.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"os"
55
"testing"
66

7-
"github.com/stretchr/testify/mock"
87
"gopkg.in/yaml.v2"
98

109
plural "github.com/pluralsh/plural/cmd/plural"
@@ -76,93 +75,3 @@ func TestBuildContext(t *testing.T) {
7675
})
7776
}
7877
}
79-
80-
func TestValidate(t *testing.T) {
81-
tests := []struct {
82-
name string
83-
args []string
84-
installations []*api.Installation
85-
charts []*api.ChartInstallation
86-
tfs []*api.TerraformInstallation
87-
pm manifest.ProjectManifest
88-
ctx manifest.Context
89-
expectedResponse string
90-
}{
91-
{
92-
name: `test "validate"`,
93-
args: []string{plural.ApplicationName, "validate"},
94-
installations: []*api.Installation{{
95-
Id: "abc",
96-
Repository: &api.Repository{
97-
Id: "abc",
98-
Name: "abc",
99-
},
100-
},
101-
{
102-
Id: "cde",
103-
Repository: &api.Repository{
104-
Id: "cde",
105-
Name: "cde",
106-
},
107-
},
108-
},
109-
pm: manifest.ProjectManifest{
110-
Cluster: "test",
111-
Bucket: "test",
112-
Project: "test",
113-
Provider: "kind",
114-
Region: "test",
115-
},
116-
ctx: manifest.Context{
117-
Bundles: []*manifest.Bundle{
118-
{
119-
Repository: "cde",
120-
Name: "cde",
121-
},
122-
{
123-
Repository: "abc",
124-
Name: "abc",
125-
},
126-
},
127-
},
128-
tfs: []*api.TerraformInstallation{},
129-
charts: []*api.ChartInstallation{},
130-
},
131-
}
132-
for _, test := range tests {
133-
t.Run(test.name, func(t *testing.T) {
134-
// create temp environment
135-
currentDir, err := os.Getwd()
136-
assert.NoError(t, err)
137-
dir, err := os.MkdirTemp("", "config")
138-
assert.NoError(t, err)
139-
defer func(path, currentDir string) {
140-
_ = os.RemoveAll(path)
141-
_ = os.Chdir(currentDir)
142-
}(dir, currentDir)
143-
144-
err = os.Chdir(dir)
145-
assert.NoError(t, err)
146-
147-
data, err := yaml.Marshal(test.pm)
148-
assert.NoError(t, err)
149-
err = os.WriteFile("workspace.yaml", data, os.FileMode(0755))
150-
assert.NoError(t, err)
151-
152-
data, err = yaml.Marshal(test.ctx)
153-
assert.NoError(t, err)
154-
err = os.WriteFile("context.yaml", data, os.FileMode(0755))
155-
assert.NoError(t, err)
156-
157-
client := mocks.NewClient(t)
158-
client.On("GetInstallations").Return(test.installations, nil)
159-
client.On("GetPackageInstallations", mock.AnythingOfType("string")).Return(test.charts, test.tfs, nil)
160-
app := plural.CreateNewApp(&plural.Plural{Client: client})
161-
app.HelpName = plural.ApplicationName
162-
os.Args = test.args
163-
resp, err := captureStdout(app, os.Args)
164-
assert.NoError(t, err)
165-
assert.Equal(t, test.expectedResponse, resp)
166-
})
167-
}
168-
}

cmd/plural/plural.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,6 @@ func (p *Plural) getCommands() []cli.Command {
182182
Action: latestVersion(apply),
183183
Category: "Publishing",
184184
},
185-
{
186-
Name: "validate",
187-
Aliases: []string{"v"},
188-
Usage: "validates your workspace",
189-
Flags: []cli.Flag{
190-
cli.StringFlag{
191-
Name: "only",
192-
Usage: "repository to (re)build",
193-
},
194-
},
195-
Action: latestVersion(p.validate),
196-
Category: "Workspace",
197-
},
198185
{
199186
Name: "topsort",
200187
Aliases: []string{"top"},

pkg/bundle/configuration.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ func evaluateCondition(ctx map[string]interface{}, cond *api.Condition, valueTyp
3939
return ok && !booled // it must be a false boolean value
4040
}
4141

42-
switch operationType {
43-
case OperationType{Operation: "PREFIX", Type: String}:
42+
if operationType.Operation == "PREFIX" {
4443
return strings.HasPrefix(val.(string), condValue)
45-
case OperationType{Operation: "SUFFIX", Type: String}:
46-
val := ctx[cond.Field]
44+
}
45+
46+
if operationType.Operation == "SUFFIX" {
4747
return strings.HasSuffix(val.(string), condValue)
48+
}
49+
50+
switch operationType {
4851
case OperationType{Operation: "EQ", Type: String}:
4952
return val == condValue
5053
case OperationType{Operation: "EQ", Type: Int}:

0 commit comments

Comments
 (0)