Skip to content

Commit 8ca8e13

Browse files
denikIsaac
andcommitted
direct: make secrets remote mapping happen in DoRead/DoCreate/DoUpdate
ResourceSecret's RemapState renamed effective_value/effective_owner to value/owner and dropped output-only fields. Move that into a shared remapSecretRemote helper applied wherever the remote is produced (DoRead/DoCreate/DoUpdate), so the remote is already mapped and RemapState becomes an identity no-op. Remove it; the adapter returns the remote unchanged. Plan remote_state now shows the mapped value/owner and omits output-only fields; the direct-only update-value golden is regenerated. Prep for replacing RemapState with the automatic copier. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent add11d6 commit 8ca8e13

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎bundle/direct/dresources/secret.go‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func (*ResourceSecret) PrepareState(input *resources.Secret) *catalog.Secret {
4545
}
4646
}
4747

48-
func (*ResourceSecret) RemapState(remote *catalog.Secret) *catalog.Secret {
48+
// remapSecretRemote maps a secret returned by the API to the config's shape: the resolved
49+
// value and owner come back under effective_*, so we surface them under value/owner, and
50+
// output-only fields are dropped. It runs wherever remote state is produced
51+
// (DoRead/DoCreate/DoUpdate), so no RemapState hook is needed.
52+
func remapSecretRemote(remote *catalog.Secret) *catalog.Secret {
4953
return &catalog.Secret{
5054
CatalogName: remote.CatalogName,
5155
SchemaName: remote.SchemaName,
@@ -66,14 +70,18 @@ func (*ResourceSecret) RemapState(remote *catalog.Secret) *catalog.Secret {
6670
}
6771
}
6872

69-
// DoRead fetches the secret by full name. IncludeValue is set so RemapState can
73+
// DoRead fetches the secret by full name. IncludeValue is set so remapSecretRemote can
7074
// recover the stored value from EffectiveValue.
7175
func (r *ResourceSecret) DoRead(ctx context.Context, id string) (*catalog.Secret, error) {
72-
return r.client.SecretsUc.GetSecret(ctx, catalog.GetSecretRequest{
76+
remote, err := r.client.SecretsUc.GetSecret(ctx, catalog.GetSecretRequest{
7377
FullName: id,
7478
IncludeValue: true,
7579
ForceSendFields: nil,
7680
})
81+
if err != nil {
82+
return nil, err
83+
}
84+
return remapSecretRemote(remote), nil
7785
}
7886

7987
// DoCreate creates a new UC secret.
@@ -84,7 +92,7 @@ func (r *ResourceSecret) DoCreate(ctx context.Context, state *catalog.Secret) (s
8492
if err != nil || response == nil {
8593
return "", nil, err
8694
}
87-
return response.FullName, response, nil
95+
return response.FullName, remapSecretRemote(response), nil
8896
}
8997

9098
// comment is force-sent on update so that clearing it in config clears it on the secret. The
@@ -106,7 +114,7 @@ func (r *ResourceSecret) DoUpdate(ctx context.Context, id string, state *catalog
106114
if err != nil {
107115
return nil, err
108116
}
109-
return response, nil
117+
return remapSecretRemote(response), nil
110118
}
111119

112120
// DoDelete deletes the secret.

0 commit comments

Comments
 (0)