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

refactor: deprecate old vals based secret store #609

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions pkg/cmd/apply/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,12 @@ func Apply(
changes *opsmodels.Changes,
out io.Writer,
) error {
// Validate secret stores
project := changes.Project()
if !project.SecretStores.IsValid() {
return fmt.Errorf("no secret store is provided")
}

// Construct the apply operation
ac := &operation.ApplyOperation{
Operation: opsmodels.Operation{
Stack: changes.Stack(),
StateStorage: storage,
MsgCh: make(chan opsmodels.Message),
SecretStores: project.SecretStores,
IgnoreFields: o.IgnoreFields,
},
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/cmd/preview/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@ func Preview(
) (*opsmodels.Changes, error) {
log.Info("Start compute preview changes ...")

// Validate secret stores
if !project.SecretStores.IsValid() {
return nil, fmt.Errorf("no secret store is provided")
}

// Construct the preview operation
pc := &operation.PreviewOperation{
Operation: opsmodels.Operation{
Expand All @@ -245,7 +240,6 @@ func Preview(
StateStorage: storage,
IgnoreFields: o.IgnoreFields,
ChangeOrder: &opsmodels.ChangeOrder{StepKeys: []string{}, ChangeSteps: map[string]*opsmodels.ChangeStep{}},
SecretStores: project.SecretStores,
},
}

Expand Down
1 change: 0 additions & 1 deletion pkg/engine/operation/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (ao *ApplyOperation) Apply(request *ApplyRequest) (rsp *ApplyResponse, st s
MsgCh: o.MsgCh,
ResultState: resultState,
Lock: &sync.Mutex{},
SecretStores: o.SecretStores,
},
}

Expand Down
33 changes: 9 additions & 24 deletions pkg/engine/operation/graph/resource_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"kusionstack.io/kusion/pkg/util"
"kusionstack.io/kusion/pkg/util/diff"
jsonutil "kusionstack.io/kusion/pkg/util/json"
"kusionstack.io/kusion/pkg/vals"
)

type ResourceNode struct {
Expand All @@ -39,13 +38,13 @@ func (rn *ResourceNode) PreExecute(o *opsmodels.Operation) status.Status {
case opsmodels.ApplyPreview:
// first time apply. Do not replace implicit dependency ref
if len(o.PriorStateResourceIndex) == 0 {
_, replaced, s = ReplaceSecretRef(value, o.SecretStores)
_, replaced, s = ReplaceSecretRef(value)
} else {
_, replaced, s = ReplaceRef(value, o.CtxResourceIndex, OptionalImplicitReplaceFun, o.SecretStores, vals.ParseSecretRef)
_, replaced, s = ReplaceRef(value, o.CtxResourceIndex, OptionalImplicitReplaceFun)
}
case opsmodels.Apply:
// replace secret ref and implicit ref
_, replaced, s = ReplaceRef(value, o.CtxResourceIndex, MustImplicitReplaceFun, o.SecretStores, vals.ParseSecretRef)
_, replaced, s = ReplaceRef(value, o.CtxResourceIndex, MustImplicitReplaceFun)
default:
return nil
}
Expand Down Expand Up @@ -296,8 +295,8 @@ func updateChangeOrder(ops *opsmodels.Operation, rn *ResourceNode, plan, live in
order.ChangeSteps[rn.ID] = opsmodels.NewChangeStep(rn.ID, rn.Action, plan, live)
}

func ReplaceSecretRef(v reflect.Value, ss *vals.SecretStores) ([]string, reflect.Value, status.Status) {
return ReplaceRef(v, nil, nil, ss, vals.ParseSecretRef)
func ReplaceSecretRef(v reflect.Value) ([]string, reflect.Value, status.Status) {
return ReplaceRef(v, nil, nil)
}

var MustImplicitReplaceFun = func(resourceIndex map[string]*models.Resource, refPath string) (reflect.Value, status.Status) {
Expand Down Expand Up @@ -352,15 +351,13 @@ func ReplaceImplicitRef(
resourceIndex map[string]*models.Resource,
replaceFun func(map[string]*models.Resource, string) (reflect.Value, status.Status),
) ([]string, reflect.Value, status.Status) {
return ReplaceRef(v, resourceIndex, replaceFun, nil, nil)
return ReplaceRef(v, resourceIndex, replaceFun)
}

func ReplaceRef(
v reflect.Value,
resourceIndex map[string]*models.Resource,
repImplDepFunc func(map[string]*models.Resource, string) (reflect.Value, status.Status),
ss *vals.SecretStores,
repSecretFunc func(string, string, *vals.SecretStores) (string, error),
) ([]string, reflect.Value, status.Status) {
var result []string
if !v.IsValid() {
Expand All @@ -372,7 +369,7 @@ func ReplaceRef(
if v.IsNil() {
return nil, v, nil
}
return ReplaceRef(v.Elem(), resourceIndex, repImplDepFunc, ss, repSecretFunc)
return ReplaceRef(v.Elem(), resourceIndex, repImplDepFunc)
case reflect.String:
vStr := v.String()
if repImplDepFunc != nil {
Expand All @@ -391,18 +388,6 @@ func ReplaceRef(
v = tv
}
}

if ss != nil && repSecretFunc != nil {
if prefix, ok := vals.IsSecured(vStr); ok {
tStr, err := repSecretFunc(prefix, vStr, ss)
if err != nil {
return nil, v, status.NewErrorStatus(err)
}
tv := reflect.New(v.Type()).Elem()
tv.SetString(tStr)
v = tv
}
}
case reflect.Slice, reflect.Array:
if v.Len() == 0 {
return nil, v, nil
Expand All @@ -411,7 +396,7 @@ func ReplaceRef(
vs := reflect.MakeSlice(v.Type(), 0, 0)

for i := 0; i < v.Len(); i++ {
ref, tv, s := ReplaceRef(v.Index(i), resourceIndex, repImplDepFunc, ss, repSecretFunc)
ref, tv, s := ReplaceRef(v.Index(i), resourceIndex, repImplDepFunc)
if status.IsErr(s) {
return nil, tv, s
}
Expand All @@ -429,7 +414,7 @@ func ReplaceRef(

iter := v.MapRange()
for iter.Next() {
ref, tv, s := ReplaceRef(iter.Value(), resourceIndex, repImplDepFunc, ss, repSecretFunc)
ref, tv, s := ReplaceRef(iter.Value(), resourceIndex, repImplDepFunc)
if status.IsErr(s) {
return nil, tv, s
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/engine/operation/models/operation_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"kusionstack.io/kusion/pkg/projectstack"
"kusionstack.io/kusion/pkg/util"
jsonutil "kusionstack.io/kusion/pkg/util/json"
"kusionstack.io/kusion/pkg/vals"
)

// Operation is the base model for all operations
Expand Down Expand Up @@ -54,9 +53,6 @@ type Operation struct {

// ResultState is the final State build by this operation, and this State will be saved in the StateStorage
ResultState *states.State

// SecretStores contains all available secret stores
SecretStores *vals.SecretStores
}

type Message struct {
Expand Down
1 change: 0 additions & 1 deletion pkg/engine/operation/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (po *PreviewOperation) Preview(request *PreviewRequest) (rsp *PreviewRespon
Stack: o.Stack,
ResultState: resultState,
Lock: &sync.Mutex{},
SecretStores: o.SecretStores,
},
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/projectstack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"kusionstack.io/kusion/pkg/engine/backend"
"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/vals"
)

var (
Expand Down Expand Up @@ -64,9 +63,6 @@ type ProjectConfiguration struct {

// Prometheus configs
Prometheus *PrometheusConfig `json:"prometheus,omitempty" yaml:"prometheus,omitempty"`

// Secret stores
SecretStores *vals.SecretStores `json:"secret_stores,omitempty" yaml:"secret_stores,omitempty"`
}

type Project struct {
Expand Down
4 changes: 0 additions & 4 deletions pkg/vals/doc.go

This file was deleted.

41 changes: 0 additions & 41 deletions pkg/vals/secret_stores.go

This file was deleted.

93 changes: 0 additions & 93 deletions pkg/vals/vals.go

This file was deleted.

Loading