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: show canonical id in user status #153

Merged
merged 2 commits into from
Feb 20, 2025
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
1 change: 1 addition & 0 deletions apis/user/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type UserParameters struct {

// UserObservation are the observable fields of a User.
type UserObservation struct {
CanonicalID string `json:"canonicalId,omitempty"`
}

// A UserSpec defines the desired state of a User.
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, nil
}

_, err := c.cloudianService.GetUser(ctx, cloudian.GroupUserID{
user, err := c.cloudianService.GetUser(ctx, cloudian.GroupUserID{
GroupID: group,
UserID: externalName})
if errors.Is(err, cloudian.ErrNotFound) {
Expand All @@ -167,6 +167,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, errors.Wrap(err, errGetUser)
}

cr.Status.AtProvider.CanonicalID = user.CanonicalID
cr.SetConditions(xpv1.Available())

return managed.ExternalObservation{
Expand Down
1 change: 1 addition & 0 deletions internal/sdk/cloudian/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type GroupUserID struct {
type User struct {
GroupUserID `json:",inline"`
UserType UserType `json:"userType"`
CanonicalID string `json:"canonicalUserId,omitempty"`
}

// SecurityInfo is the Cloudian API's term for secure credentials
Expand Down
4 changes: 2 additions & 2 deletions internal/sdk/cloudian/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func TestClient_GetUser(t *testing.T) {
status int
wantErr error
}{
{name: "Exists", user: User{GroupUserID: GroupUserID{UserID: strconv.Itoa(http.StatusOK)}}},
{name: "Not found", user: User{GroupUserID: GroupUserID{UserID: strconv.Itoa(http.StatusNoContent)}}, wantErr: ErrNotFound},
{name: "Exists", user: User{GroupUserID: GroupUserID{UserID: strconv.Itoa(http.StatusOK)}, CanonicalID: "123"}},
{name: "Not found", user: User{GroupUserID: GroupUserID{UserID: strconv.Itoa(http.StatusNoContent)}, CanonicalID: "123"}, wantErr: ErrNotFound},
}

client, testServer := mockBy(func(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 3 additions & 0 deletions package/crds/user.cloudian.crossplane.io_users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ spec:
properties:
atProvider:
description: UserObservation are the observable fields of a User.
properties:
canonicalId:
type: string
type: object
conditions:
description: Conditions of the resource.
Expand Down
Loading