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

Add Identity Deletion #35

Merged
merged 1 commit into from
Jul 17, 2024
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
4 changes: 2 additions & 2 deletions charts/region/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn's Region Controller

type: application

version: v0.1.22
appVersion: v0.1.22
version: v0.1.23
appVersion: v0.1.23

icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/dark-on-light/icon.png

Expand Down
32 changes: 29 additions & 3 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"github.com/unikorn-cloud/region/pkg/server/util"

kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -63,9 +64,10 @@

func New(client client.Client, namespace string, options *Options, identity *identityclient.Client) (*Handler, error) {
h := &Handler{
client: client,
options: options,
identity: identity,
client: client,
namespace: namespace,
options: options,
identity: identity,

Check warning on line 70 in pkg/handler/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/handler/handler.go#L67-L70

Added lines #L67 - L70 were not covered by tests
}

return h, nil
Expand Down Expand Up @@ -343,6 +345,30 @@
util.WriteJSONResponse(w, r, http.StatusCreated, convertIdentity(identity, cloudconfig))
}

func (h *Handler) DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter, identityID openapi.IdentityIDParameter) {
if err := rbac.AllowProjectScope(r.Context(), "identities", identityapi.Delete, organizationID, projectID); err != nil {
errors.HandleError(w, r, err)
return
}

Check warning on line 352 in pkg/handler/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/handler/handler.go#L348-L352

Added lines #L348 - L352 were not covered by tests

resource := &unikornv1.Identity{
ObjectMeta: metav1.ObjectMeta{
Name: identityID,
Namespace: h.namespace,
},
}

if err := h.client.Delete(r.Context(), resource); err != nil {
if kerrors.IsNotFound(err) {
errors.HandleError(w, r, errors.HTTPNotFound().WithError(err))
return
}

Check warning on line 365 in pkg/handler/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/handler/handler.go#L354-L365

Added lines #L354 - L365 were not covered by tests

errors.HandleError(w, r, errors.OAuth2ServerError("failed to delete identity").WithError(err))
return

Check warning on line 368 in pkg/handler/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/handler/handler.go#L367-L368

Added lines #L367 - L368 were not covered by tests
}
}

func convertPhysicalNetwork(in *unikornv1.PhysicalNetwork) *openapi.PhysicalNetworkRead {
out := &openapi.PhysicalNetworkRead{
Metadata: conversion.ProjectScopedResourceReadMetadata(in, coreapi.ResourceProvisioningStatusProvisioned),
Expand Down
155 changes: 155 additions & 0 deletions pkg/openapi/client.go

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

57 changes: 57 additions & 0 deletions pkg/openapi/router.go

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

Loading
Loading