Skip to content

Commit

Permalink
wip: cs
Browse files Browse the repository at this point in the history
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
carolynvs committed Apr 26, 2023
1 parent 84b6fd1 commit 0af33db
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions pkg/secrets/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func (v ValueMapping) ToArrayEntry(key string) encoding.ArrayElement {
}
}

var _ encoding.ArrayElement = NamedValueMapping{}

// NamedValueMapping is the representation of a ValueMapping in an array,
// We use it to unmarshal the yaml, and then convert it into our internal representation
// where the ValueMapping is in a Go map instead of an array.
Expand Down
21 changes: 10 additions & 11 deletions pkg/storage/credentialset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"get.porter.sh/porter/pkg/cnab"
"get.porter.sh/porter/pkg/encoding"
"get.porter.sh/porter/pkg/schema"
"get.porter.sh/porter/pkg/secrets"
"get.porter.sh/porter/pkg/tracing"
Expand Down Expand Up @@ -51,15 +50,16 @@ type CredentialSetSpec struct {
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" toml:"labels,omitempty"`

// Credentials is a list of credential resolution strategies.
Credentials *CredentialSourceMap `json:"credentials" yaml:"credentials" toml:"credentials"`
Credentials CredentialSourceMap `json:"credentials" yaml:"credentials" toml:"credentials"`
}

type CredentialSourceMap = encoding.ArrayMap[CredentialSource, NamedCredentialSource]

// TODO(generics)
type CredentialSourceMap = secrets.Map
type CredentialSource = secrets.ValueMapping
type NamedCredentialSource = secrets.NamedValueMapping

var MakeCredentialSourceMap = secrets.MakeMap
var NewCredentialSourceMap = secrets.NewMap

// CredentialSetStatus contains additional status metadata that has been set by Porter.
type CredentialSetStatus struct {
// Created timestamp.
Expand All @@ -69,8 +69,6 @@ type CredentialSetStatus struct {
Modified time.Time `json:"modified" yaml:"modified" toml:"modified"`
}

var MakeCredentialSourceMap = encoding.MakeArrayMap[CredentialSource, NamedCredentialSource]

// NewCredentialSet creates a new CredentialSet with the required fields initialized.
func NewCredentialSet(namespace string, name string) CredentialSet {
now := time.Now()
Expand All @@ -80,7 +78,7 @@ func NewCredentialSet(namespace string, name string) CredentialSet {
SchemaVersion: DefaultCredentialSetSchemaVersion,
Name: name,
Namespace: namespace,
Credentials: &CredentialSourceMap{},
Credentials: NewCredentialSourceMap(),
},
Status: CredentialSetStatus{
Created: now,
Expand Down Expand Up @@ -145,16 +143,17 @@ func (s CredentialSet) SetStrategy(key string, source secrets.Source) {
}

func (s CredentialSet) Set(key string, source CredentialSource) {
if s.Credentials == nil {
s.Credentials = &CredentialSourceMap{}
}
s.Credentials.Set(key, source)
}

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

func (s CredentialSet) Remove(key string) {
s.Credentials.Remove(key)
}

func (s CredentialSet) Len() int {
return s.Credentials.Len()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/credentialset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestMarshal(t *testing.T) {
SchemaVersion: "schemaVersion",
Namespace: "namespace",
Name: "name",
Credentials: &CredentialSourceMap{},
Credentials: NewCredentialSourceMap(),
},
Status: CredentialSetStatus{
Created: now,
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,15 @@ func convertCredentialSet(namespace string, data []byte) (storage.CredentialSet,
},
}

destCreds := storage.MakeCredentialSourceMap(len(src.Credentials))
dest.Credentials = &destCreds
dest.Credentials = storage.MakeCredentialSourceMap(len(src.Credentials))
for _, srcCred := range src.Credentials {
destCred := storage.CredentialSource{
Source: secrets.Source{
Strategy: srcCred.Source.Key,
Hint: srcCred.Source.Value,
},
}
destCreds.Set(srcCred.Name, destCred)
dest.Credentials.Set(srcCred.Name, destCred)
}

return dest, nil
Expand Down
10 changes: 6 additions & 4 deletions pkg/storage/parameterset.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ type ParameterSetSpec struct {
}

type ParameterSourceMap = secrets.Map
type ParameterSource = secrets.ValueMapping
type NamedParameterSource = secrets.NamedValueMapping

var MakeParameterSourceMap = secrets.MakeMap
var NewParameterSourceMap = secrets.NewMap

// TODO(generics)
type ParameterSource = secrets.ValueMapping
type NamedParameterSource = secrets.NamedValueMapping

// ParameterSetStatus contains additional status metadata that has been set by Porter.
type ParameterSetStatus struct {
// Created timestamp of the parameter set.
Expand Down Expand Up @@ -135,6 +133,10 @@ func (s ParameterSet) Iterate() map[string]ParameterSource {
return s.Parameters.Items()
}

func (s ParameterSet) IterateSorted() []NamedParameterSource {
return s.Parameters.ItemsSorted()
}

func (s ParameterSet) SetStrategy(key string, source secrets.Source) {
s.Parameters.Set(key, ParameterSource{Source: source})
}
Expand Down

0 comments on commit 0af33db

Please sign in to comment.