Update the env proto
Update the env proto
This commit is contained in:
parent
a23773d2ab
commit
0d20db4020
@ -2,12 +2,10 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
"git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||||
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,31 +20,41 @@ type EnvironmentsServer struct {
|
|||||||
controller ctrl.Manager
|
controller ctrl.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.EnvironmentData) (*proto.EnvironmentFull, error) {
|
// Create an environment
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions) (*proto.EnvironmentFull, error) {
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("metadata is not provided")
|
|
||||||
}
|
|
||||||
token, ok := md["token"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("token is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
uuid, ok := md["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("used id is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
data := &controllers.EnvironemntData{
|
data := &controllers.EnvironemntData{
|
||||||
Name: in.GetName(),
|
Name: in.GetName().GetName(),
|
||||||
Provider: in.GetProvider().String(),
|
Provider: in.GetData().GetProvider().String(),
|
||||||
Kubernetes: in.GetKubernetes().String(),
|
Kubernetes: in.GetData().GetKubernetes().String(),
|
||||||
}
|
}
|
||||||
environment := &controllers.Environemnt{
|
environment := &controllers.Environemnt{
|
||||||
UserID: uuid[0],
|
UserID: in.GetOwnerId().GetUuid(),
|
||||||
Controller: e.controller,
|
Controller: e.controller,
|
||||||
Data: data,
|
Data: data,
|
||||||
Token: token[0],
|
Token: in.GetToken().GetToken(),
|
||||||
|
}
|
||||||
|
|
||||||
|
err := environment.Create(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.UpdateOptions) (*proto.EnvironmentFull, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.DeleteOptions) (*empty.Empty, error) {
|
||||||
|
data := &controllers.EnvironemntData{
|
||||||
|
Name: in.GetName().GetName(),
|
||||||
|
}
|
||||||
|
|
||||||
|
environment := &controllers.Environemnt{
|
||||||
|
UserID: in.GetOwnerId().GetUuid(),
|
||||||
|
Controller: e.controller,
|
||||||
|
Data: data,
|
||||||
|
Token: in.GetToken().GetToken(),
|
||||||
}
|
}
|
||||||
err := environment.Create(ctx)
|
err := environment.Create(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -55,62 +63,16 @@ func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.EnvironmentDa
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.EnvironmentFull) (*proto.EnvironmentFull, error) {
|
func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*proto.EnvironmentFull, error) {
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.EnvironmentFull) (*empty.Empty, error) {
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("metadata is not provided")
|
|
||||||
}
|
|
||||||
token, ok := md["token"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("token is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
uuid, ok := md["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("used id is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
data := &controllers.EnvironemntData{
|
data := &controllers.EnvironemntData{
|
||||||
Name: in.Data.GetName(),
|
Name: in.GetName().GetName(),
|
||||||
Provider: in.Data.GetProvider().String(),
|
|
||||||
Kubernetes: in.Data.GetKubernetes().String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
environment := &controllers.Environemnt{
|
environment := &controllers.Environemnt{
|
||||||
UserID: uuid[0],
|
UserID: in.GetOwnerId().GetUuid(),
|
||||||
Controller: e.controller,
|
Controller: e.controller,
|
||||||
Data: data,
|
Data: data,
|
||||||
Token: token[0],
|
Token: in.GetToken().GetToken(),
|
||||||
}
|
|
||||||
err := environment.Create(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.EnvironmentId) (*proto.EnvironmentFull, error) {
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("metadata is not provided")
|
|
||||||
}
|
|
||||||
token, ok := md["token"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("token is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
uuid, ok := md["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("used id is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
environment := &controllers.Environemnt{
|
|
||||||
UserID: uuid[0],
|
|
||||||
Controller: e.controller,
|
|
||||||
Token: token[0],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := environment.Get(ctx); err != nil {
|
if err := environment.Get(ctx); err != nil {
|
||||||
@ -118,35 +80,19 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.EnvironmentId) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &proto.EnvironmentFull{
|
return &proto.EnvironmentFull{
|
||||||
Id: &proto.EnvironmentId{
|
Name: &proto.EnvironmentName{
|
||||||
Id: "test",
|
|
||||||
},
|
|
||||||
Data: &proto.EnvironmentData{
|
|
||||||
Name: environment.Data.Name,
|
Name: environment.Data.Name,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EnvironmentsServer) List(in *empty.Empty, stream proto.Environments_ListServer) error {
|
func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environments_ListServer) error {
|
||||||
md, ok := metadata.FromIncomingContext(stream.Context())
|
|
||||||
if !ok {
|
|
||||||
return errors.New("metadata is not provided")
|
|
||||||
}
|
|
||||||
token, ok := md["token"]
|
|
||||||
if !ok {
|
|
||||||
return errors.New("token is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
uuid, ok := md["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return errors.New("used id is not sent via metadata")
|
|
||||||
}
|
|
||||||
|
|
||||||
environment := &controllers.Environemnt{
|
environment := &controllers.Environemnt{
|
||||||
UserID: uuid[0],
|
UserID: in.GetOwnerId().GetUuid(),
|
||||||
Controller: e.controller,
|
Controller: e.controller,
|
||||||
Token: token[0],
|
Token: in.GetToken().GetToken(),
|
||||||
}
|
}
|
||||||
|
|
||||||
envs, err := environment.ListEnvs(stream.Context())
|
envs, err := environment.ListEnvs(stream.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -154,8 +100,7 @@ func (e *EnvironmentsServer) List(in *empty.Empty, stream proto.Environments_Lis
|
|||||||
|
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
if err := stream.Send(&proto.EnvironmentFull{
|
if err := stream.Send(&proto.EnvironmentFull{
|
||||||
Id: &proto.EnvironmentId{Id: "test"},
|
Name: &proto.EnvironmentName{
|
||||||
Data: &proto.EnvironmentData{
|
|
||||||
Name: env,
|
Name: env,
|
||||||
},
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
2
go.mod
2
go.mod
@ -67,7 +67,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.3
|
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.5
|
||||||
github.com/golang/protobuf v1.5.4
|
github.com/golang/protobuf v1.5.4
|
||||||
golang.org/x/net v0.22.0 // indirect
|
golang.org/x/net v0.22.0 // indirect
|
||||||
golang.org/x/sys v0.18.0 // indirect
|
golang.org/x/sys v0.18.0 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
|||||||
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.3 h1:c0q0nz9bT1TXUaMI7G+RII6mzZI1Tg0xWn2ToKekh4c=
|
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.5 h1:HETV0silTTK//EUGsSM71U1j5lzVjHThmvKXZXWtBLg=
|
||||||
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.3/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI=
|
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.5/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI=
|
||||||
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
|
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
|
||||||
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
||||||
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
|
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
|
||||||
|
Loading…
Reference in New Issue
Block a user