Skip to content

Commit 0af33db

Browse files
committed
wip: cs
Signed-off-by: Carolyn Van Slyck <[email protected]>
1 parent 84b6fd1 commit 0af33db

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

pkg/secrets/map.go

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (v ValueMapping) ToArrayEntry(key string) encoding.ArrayElement {
8181
}
8282
}
8383

84+
var _ encoding.ArrayElement = NamedValueMapping{}
85+
8486
// NamedValueMapping is the representation of a ValueMapping in an array,
8587
// We use it to unmarshal the yaml, and then convert it into our internal representation
8688
// where the ValueMapping is in a Go map instead of an array.

pkg/storage/credentialset.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"get.porter.sh/porter/pkg/cnab"
10-
"get.porter.sh/porter/pkg/encoding"
1110
"get.porter.sh/porter/pkg/schema"
1211
"get.porter.sh/porter/pkg/secrets"
1312
"get.porter.sh/porter/pkg/tracing"
@@ -51,15 +50,16 @@ type CredentialSetSpec struct {
5150
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" toml:"labels,omitempty"`
5251

5352
// Credentials is a list of credential resolution strategies.
54-
Credentials *CredentialSourceMap `json:"credentials" yaml:"credentials" toml:"credentials"`
53+
Credentials CredentialSourceMap `json:"credentials" yaml:"credentials" toml:"credentials"`
5554
}
5655

57-
type CredentialSourceMap = encoding.ArrayMap[CredentialSource, NamedCredentialSource]
58-
59-
// TODO(generics)
56+
type CredentialSourceMap = secrets.Map
6057
type CredentialSource = secrets.ValueMapping
6158
type NamedCredentialSource = secrets.NamedValueMapping
6259

60+
var MakeCredentialSourceMap = secrets.MakeMap
61+
var NewCredentialSourceMap = secrets.NewMap
62+
6363
// CredentialSetStatus contains additional status metadata that has been set by Porter.
6464
type CredentialSetStatus struct {
6565
// Created timestamp.
@@ -69,8 +69,6 @@ type CredentialSetStatus struct {
6969
Modified time.Time `json:"modified" yaml:"modified" toml:"modified"`
7070
}
7171

72-
var MakeCredentialSourceMap = encoding.MakeArrayMap[CredentialSource, NamedCredentialSource]
73-
7472
// NewCredentialSet creates a new CredentialSet with the required fields initialized.
7573
func NewCredentialSet(namespace string, name string) CredentialSet {
7674
now := time.Now()
@@ -80,7 +78,7 @@ func NewCredentialSet(namespace string, name string) CredentialSet {
8078
SchemaVersion: DefaultCredentialSetSchemaVersion,
8179
Name: name,
8280
Namespace: namespace,
83-
Credentials: &CredentialSourceMap{},
81+
Credentials: NewCredentialSourceMap(),
8482
},
8583
Status: CredentialSetStatus{
8684
Created: now,
@@ -145,16 +143,17 @@ func (s CredentialSet) SetStrategy(key string, source secrets.Source) {
145143
}
146144

147145
func (s CredentialSet) Set(key string, source CredentialSource) {
148-
if s.Credentials == nil {
149-
s.Credentials = &CredentialSourceMap{}
150-
}
151146
s.Credentials.Set(key, source)
152147
}
153148

154149
func (s CredentialSet) Get(key string) (CredentialSource, bool) {
155150
return s.Credentials.Get(key)
156151
}
157152

153+
func (s CredentialSet) Remove(key string) {
154+
s.Credentials.Remove(key)
155+
}
156+
158157
func (s CredentialSet) Len() int {
159158
return s.Credentials.Len()
160159
}

pkg/storage/credentialset_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func TestMarshal(t *testing.T) {
150150
SchemaVersion: "schemaVersion",
151151
Namespace: "namespace",
152152
Name: "name",
153-
Credentials: &CredentialSourceMap{},
153+
Credentials: NewCredentialSourceMap(),
154154
},
155155
Status: CredentialSetStatus{
156156
Created: now,

pkg/storage/migrations/migration.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,15 @@ func convertCredentialSet(namespace string, data []byte) (storage.CredentialSet,
512512
},
513513
}
514514

515-
destCreds := storage.MakeCredentialSourceMap(len(src.Credentials))
516-
dest.Credentials = &destCreds
515+
dest.Credentials = storage.MakeCredentialSourceMap(len(src.Credentials))
517516
for _, srcCred := range src.Credentials {
518517
destCred := storage.CredentialSource{
519518
Source: secrets.Source{
520519
Strategy: srcCred.Source.Key,
521520
Hint: srcCred.Source.Value,
522521
},
523522
}
524-
destCreds.Set(srcCred.Name, destCred)
523+
dest.Credentials.Set(srcCred.Name, destCred)
525524
}
526525

527526
return dest, nil

pkg/storage/parameterset.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ type ParameterSetSpec struct {
4848
}
4949

5050
type ParameterSourceMap = secrets.Map
51+
type ParameterSource = secrets.ValueMapping
52+
type NamedParameterSource = secrets.NamedValueMapping
5153

5254
var MakeParameterSourceMap = secrets.MakeMap
5355
var NewParameterSourceMap = secrets.NewMap
5456

55-
// TODO(generics)
56-
type ParameterSource = secrets.ValueMapping
57-
type NamedParameterSource = secrets.NamedValueMapping
58-
5957
// ParameterSetStatus contains additional status metadata that has been set by Porter.
6058
type ParameterSetStatus struct {
6159
// Created timestamp of the parameter set.
@@ -135,6 +133,10 @@ func (s ParameterSet) Iterate() map[string]ParameterSource {
135133
return s.Parameters.Items()
136134
}
137135

136+
func (s ParameterSet) IterateSorted() []NamedParameterSource {
137+
return s.Parameters.ItemsSorted()
138+
}
139+
138140
func (s ParameterSet) SetStrategy(key string, source secrets.Source) {
139141
s.Parameters.Set(key, ParameterSource{Source: source})
140142
}

0 commit comments

Comments
 (0)