Don't generate credentials secret getters and setters
We don't expect these to be consistent across all providers. Currently _most_ providers require a credentials secret. The AWS provider does not, because it supports using a different method (i.e. IRSA) that does not require a secret. In practice we don't use these getters and setters anywhere where we couldn't just type assert resource.ProviderConfig to the specific type we're dealing with. Signed-off-by: Nic Cope <negz@rk0n.org>
This commit is contained in:
parent
fb258cc0eb
commit
80bef4534c
|
|
@ -148,12 +148,10 @@ func GenerateProviderConfig(filename, header string, p *packages.Package) error
|
|||
receiver := "p"
|
||||
|
||||
methods := method.Set{
|
||||
"SetCredentialsSecretReference": method.NewSetCredentialsSecretReference(receiver, RuntimeImport),
|
||||
"GetCredentialsSecretReference": method.NewGetCredentialsSecretReference(receiver, RuntimeImport),
|
||||
"SetUsers": method.NewSetUsers(receiver),
|
||||
"GetUsers": method.NewGetUsers(receiver),
|
||||
"SetConditions": method.NewSetConditions(receiver, RuntimeImport),
|
||||
"GetCondition": method.NewGetCondition(receiver, RuntimeImport),
|
||||
"SetUsers": method.NewSetUsers(receiver),
|
||||
"GetUsers": method.NewGetUsers(receiver),
|
||||
"SetConditions": method.NewSetConditions(receiver, RuntimeImport),
|
||||
"GetCondition": method.NewGetCondition(receiver, RuntimeImport),
|
||||
}
|
||||
|
||||
err := generate.WriteMethods(p, methods, filepath.Join(filepath.Dir(p.GoFiles[0]), filename),
|
||||
|
|
|
|||
|
|
@ -72,9 +72,7 @@ func ProviderConfig() Object {
|
|||
return fields.Has(o,
|
||||
fields.IsTypeMeta().And(fields.IsEmbedded()),
|
||||
fields.IsObjectMeta().And(fields.IsEmbedded()),
|
||||
fields.IsSpec().And(fields.HasFieldThat(
|
||||
fields.IsProviderConfigSpec().And(fields.IsEmbedded()),
|
||||
)),
|
||||
fields.IsSpec(),
|
||||
fields.IsStatus().And(fields.HasFieldThat(
|
||||
fields.IsProviderConfigStatus().And(fields.IsEmbedded()),
|
||||
)),
|
||||
|
|
|
|||
|
|
@ -234,30 +234,6 @@ func NewGetDeletionPolicy(receiver, runtime string) New {
|
|||
}
|
||||
}
|
||||
|
||||
// NewGetCredentialsSecretReference returns a NewMethod that writes a
|
||||
// GetCredentialsSecretReference method for the supplied Object to the supplied
|
||||
// file.
|
||||
func NewGetCredentialsSecretReference(receiver, runtime string) New {
|
||||
return func(f *jen.File, o types.Object) {
|
||||
f.Commentf("GetCredentialsSecretReference of this %s.", o.Name())
|
||||
f.Func().Params(jen.Id(receiver).Op("*").Id(o.Name())).Id("GetCredentialsSecretReference").Params().Op("*").Qual(runtime, "SecretKeySelector").Block(
|
||||
jen.Return(jen.Id(receiver).Dot(fields.NameSpec).Dot("CredentialsSecretRef")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// NewSetCredentialsSecretReference returns a NewMethod that writes a
|
||||
// SetCredentialsSecretReference method for the supplied Object to the supplied
|
||||
// file.
|
||||
func NewSetCredentialsSecretReference(receiver, runtime string) New {
|
||||
return func(f *jen.File, o types.Object) {
|
||||
f.Commentf("SetCredentialsSecretReference of this %s.", o.Name())
|
||||
f.Func().Params(jen.Id(receiver).Op("*").Id(o.Name())).Id("SetCredentialsSecretReference").Params(jen.Id("r").Op("*").Qual(runtime, "SecretKeySelector")).Block(
|
||||
jen.Id(receiver).Dot(fields.NameSpec).Dot("CredentialsSecretRef").Op("=").Id("r"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// NewSetUsers returns a NewMethod that writes a SetUsers method for the
|
||||
// supplied Object to the supplied file.
|
||||
func NewSetUsers(receiver string) New {
|
||||
|
|
|
|||
|
|
@ -279,40 +279,6 @@ func (t *Type) GetDeletionPolicy() runtime.DeletionPolicy {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewSetCredentialsSecretReference(t *testing.T) {
|
||||
want := `package pkg
|
||||
|
||||
import runtime "example.org/runtime"
|
||||
|
||||
// SetCredentialsSecretReference of this Type.
|
||||
func (t *Type) SetCredentialsSecretReference(r *runtime.SecretKeySelector) {
|
||||
t.Spec.CredentialsSecretRef = r
|
||||
}
|
||||
`
|
||||
f := jen.NewFile("pkg")
|
||||
NewSetCredentialsSecretReference("t", "example.org/runtime")(f, MockObject{Named: "Type"})
|
||||
if diff := cmp.Diff(want, fmt.Sprintf("%#v", f)); diff != "" {
|
||||
t.Errorf("NewSetCredentialsSecretReference(): -want, +got\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewGetCredentialsSecretReference(t *testing.T) {
|
||||
want := `package pkg
|
||||
|
||||
import runtime "example.org/runtime"
|
||||
|
||||
// GetCredentialsSecretReference of this Type.
|
||||
func (t *Type) GetCredentialsSecretReference() *runtime.SecretKeySelector {
|
||||
return t.Spec.CredentialsSecretRef
|
||||
}
|
||||
`
|
||||
f := jen.NewFile("pkg")
|
||||
NewGetCredentialsSecretReference("t", "example.org/runtime")(f, MockObject{Named: "Type"})
|
||||
if diff := cmp.Diff(want, fmt.Sprintf("%#v", f)); diff != "" {
|
||||
t.Errorf("NewGetCredentialsSecretLocalReference(): -want, +got\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewSetUsers(t *testing.T) {
|
||||
want := `package pkg
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue