Refactor providers data
This commit is contained in:
@ -2,8 +2,10 @@ package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/providers"
|
||||
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
@ -22,12 +24,36 @@ type EnvironmentsServer struct {
|
||||
|
||||
// Create an environment
|
||||
func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions) (*proto.EnvironmentFull, error) {
|
||||
provider, err := providers.GetProvider(in.GetSpec().GetProvider())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var location string
|
||||
switch in.GetSpec().GetProvider() {
|
||||
case proto.Provider_PROVIDER_HETZNER:
|
||||
location, err = provider.GetServerLocation(in.GetSpec().GetHetznerOptions().GetServerLocation().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown provider: %s", in.GetSpec().GetProvider())
|
||||
}
|
||||
|
||||
serverType, err := provider.GetServerType(in.Spec.HetznerOptions.ServerType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := &controllers.EnvironemntData{
|
||||
Name: in.GetMetadata().GetName(),
|
||||
Description: in.GetMetadata().GetDescription(),
|
||||
Provider: in.GetSpec().GetProvider(),
|
||||
Kubernetes: in.GetSpec().GetKubernetes().String(),
|
||||
Location: location,
|
||||
ServerType: serverType,
|
||||
}
|
||||
|
||||
environment := &controllers.Environemnt{
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: e.controller,
|
||||
@ -35,7 +61,7 @@ func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
err := environment.Create(ctx)
|
||||
err = environment.Create(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user