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

feat: SamlGroupLinks #144

Merged
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
10 changes: 5 additions & 5 deletions apis/groups/v1alpha1/group_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ type GroupObservation struct {

// SharedWithGroupsObservation is the observed state of a SharedWithGroups.
type SharedWithGroupsObservation struct {
GroupID *int `json:"groupId"`
GroupName *string `json:"groupName"`
GroupFullPath *string `json:"groupFullPath"`
GroupAccessLevel *int `json:"groupAccessLevel"`
ExpiresAt *metav1.Time `json:"expiresAt"`
GroupID *int `json:"groupId,omitempty"`
GroupName *string `json:"groupName,omitempty"`
GroupFullPath *string `json:"groupFullPath,omitempty"`
GroupAccessLevel *int `json:"groupAccessLevel,omitempty"`
ExpiresAt *metav1.Time `json:"expiresAt,omitempty"`
}

// A GroupSpec defines the desired state of a Gitlab Group.
Expand Down
28 changes: 28 additions & 0 deletions apis/groups/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,31 @@ func (mg *Group) ResolveReferences(ctx context.Context, c client.Reader) error {

return nil
}

// ResolveReferences of this SamlGroupLink
func (mg *SamlGroupLink) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// resolve spec.forProvider.groupIdRef
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: fromPtrValue(mg.Spec.ForProvider.GroupID),
Reference: mg.Spec.ForProvider.GroupIDRef,
Selector: mg.Spec.ForProvider.GroupIDSelector,
To: reference.To{Managed: &Group{}, List: &GroupList{}},
Extract: reference.ExternalName(),
})

if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

resolvedID, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedID
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
}
10 changes: 10 additions & 0 deletions apis/groups/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ var (
MemberKubernetesGroupVersionKind = SchemeGroupVersion.WithKind(MemberKind)
)

// SamlGroupLink type metadata
var (
SamlGroupLinkKind = reflect.TypeOf(SamlGroupLink{}).Name()
SamlGroupLinkGroupKind = schema.GroupKind{Group: KubernetesGroup, Kind: SamlGroupLinkKind}.String()
SamlGroupLinkKindAPIVersion = SamlGroupLinkKind + "." + SchemeGroupVersion.String()
SamlGroupLinkGroupVersionKind = SchemeGroupVersion.WithKind(SamlGroupLinkKind)
)

// Deploy Token type metadata
var (
DeployTokenKind = reflect.TypeOf(DeployToken{}).Name()
Expand Down Expand Up @@ -83,4 +91,6 @@ func init() {
SchemeBuilder.Register(&AccessToken{}, &AccessTokenList{})
SchemeBuilder.Register(&DeployToken{}, &DeployTokenList{})
SchemeBuilder.Register(&Variable{}, &VariableList{})
SchemeBuilder.Register(&SamlGroupLink{}, &SamlGroupLinkList{})

}
97 changes: 97 additions & 0 deletions apis/groups/v1alpha1/samlgrouplink_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
Copyright 2021 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// SamlGroupLinkParameters define the desired state of a Gitlab Group Saml Link
// https://docs.gitlab.com/ee/api/groups.html#saml-group-links
type SamlGroupLinkParameters struct {
// GroupID is the ID of the group to create the deploy token in.
// +optional
// +immutable
GroupID *int `json:"groupId,omitempty"`

// GroupIDRef is a reference to a group to retrieve its groupId
// +optional
// +immutable
GroupIDRef *xpv1.Reference `json:"groupIdRef,omitempty"`

// GroupIDSelector selects reference to a group to retrieve its groupId.
// +optional
GroupIDSelector *xpv1.Selector `json:"groupIdSelector,omitempty"`

// name is the name of the saml group to attach to the gitlab group
// +immutable
Name *string `json:"name"`

// accessLevel is the defined role for members of the SAML group
// +immutable
AccessLevel AccessLevelValue `json:"accessLevel"`

// memberRoleID is the defined member role assigned to members of the group
// +optional
// +immutable
MemberRoleID *int `json:"memberRoleId,omitempty"`
}

// SamlGroupLinkObservation represents a Group Saml Link.
type SamlGroupLinkObservation struct {
Name string `json:"name,omitempty"`
}

// A SamlGroupLinkSpec defines the desired state of a Gitlab SAML group sync.
type SamlGroupLinkSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider SamlGroupLinkParameters `json:"forProvider"`
}

// A SamlGroupLinkStatus represents the observed state of a Gitlab SAML group sync.
type SamlGroupLinkStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider SamlGroupLinkObservation `json:"atProvider,omitempty"`
}

// +kubebuilder:object:root=true

// A SamlGroupLink is a managed resource that represents a Gitlab saml group sync connection
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".status.atProvider.name"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,gitlab}
type SamlGroupLink struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SamlGroupLinkSpec `json:"spec"`
Status SamlGroupLinkStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// SamlGroupLinkList contains a list of group items
type SamlGroupLinkList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SamlGroupLink `json:"items"`
}
148 changes: 148 additions & 0 deletions apis/groups/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions apis/groups/v1alpha1/zz_generated.managed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading