Skip to content

Commit

Permalink
feat: show canonical id in user status (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad authored Feb 20, 2025
1 parent 4cb8806 commit fa81bde
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
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

0 comments on commit fa81bde

Please sign in to comment.