This commit is contained in:
51
pkg/builder/machine_user_builder.go
Normal file
51
pkg/builder/machine_user_builder.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
zitadelv1alpha1 "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/api/v1alpha1"
|
||||
metadata "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/pkg/builder/metadata"
|
||||
zitadelresourcesv1alpha1 "gitea.corredorconect.com/software-engineering/zitadel-resources-operator/api/v1alpha1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
)
|
||||
|
||||
type MachineUserOpts struct {
|
||||
Instance *zitadelv1alpha1.Instance
|
||||
Authorizations []zitadelresourcesv1alpha1.Authorization
|
||||
InternalPermissions []zitadelresourcesv1alpha1.InternalPermissions
|
||||
Username string
|
||||
}
|
||||
|
||||
func (b *Builder) BuildMachineUser(
|
||||
key types.NamespacedName,
|
||||
opts MachineUserOpts, owner metav1.Object) (*zitadelresourcesv1alpha1.MachineUser, error) {
|
||||
objMeta :=
|
||||
metadata.NewMetadataBuilder(key).
|
||||
Build()
|
||||
|
||||
mu := &zitadelresourcesv1alpha1.MachineUser{
|
||||
ObjectMeta: objMeta,
|
||||
Spec: zitadelresourcesv1alpha1.MachineUserSpec{
|
||||
OrganizationRef: zitadelresourcesv1alpha1.OrganizationRef{
|
||||
ObjectReference: corev1.ObjectReference{
|
||||
Kind: "Organization",
|
||||
Namespace: opts.Instance.Namespace,
|
||||
Name: opts.Instance.FirstOrgObjectName(),
|
||||
},
|
||||
},
|
||||
AccessTokenType: "ACCESS_TOKEN_TYPE_BEARER",
|
||||
Authorizations: opts.Authorizations,
|
||||
InternalPermissions: opts.InternalPermissions,
|
||||
Metadata: []map[string]string{},
|
||||
Username: opts.Username,
|
||||
},
|
||||
}
|
||||
|
||||
if err := controllerutil.SetControllerReference(owner, mu, b.scheme); err != nil {
|
||||
return nil, fmt.Errorf("error setting controller reference in Machine User manifest: %v", err)
|
||||
}
|
||||
return mu, nil
|
||||
}
|
||||
Reference in New Issue
Block a user