Add an ability to uninstall applications

This commit is contained in:
2024-05-13 13:43:26 +02:00
parent 1b31217ab3
commit aa13131b0d
2 changed files with 68 additions and 1 deletions

View File

@ -6,6 +6,8 @@ import (
"git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/applications"
"github.com/go-logr/logr"
"github.com/golang/protobuf/ptypes/empty"
"google.golang.org/protobuf/types/known/emptypb"
ctrl "sigs.k8s.io/controller-runtime"
)
@ -56,3 +58,27 @@ func (app *ApplicationServer) Create(ctx context.Context, in *proto.CreateOption
Spec: in.GetSpec(),
}, nil
}
func (app *ApplicationServer) Delete(ctx context.Context, in *proto.DeleteOptions) (*empty.Empty, error) {
log := app.logInstance
log.WithValues("user_id", in.GetOwnerId().GetUuid(), "app_id", in.GetId().GetUuid())
ctx = logr.NewContext(ctx, log)
data := &controllers.ApplicationData{
Name: in.Metadata.Name,
UUID: in.GetId().GetUuid(),
}
application := &controllers.Application{
UserID: in.GetOwnerId().GetUuid(),
Controller: app.controller,
Data: data,
Token: in.GetToken().GetToken(),
}
err := application.Delete(ctx)
if err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}