Return the created env on create req

This commit is contained in:
Nikolai Rodionov 2024-04-30 10:20:46 +02:00
parent 99ee44b431
commit c49e885255
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
4 changed files with 20 additions and 40 deletions

View File

@ -113,16 +113,6 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*pr
return nil, err return nil, err
} }
serverType, err := provider.RawServerType(environment.Data.ServerType)
if err != nil {
return nil, err
}
location, err := provider.RawServerLocation(environment.Data.Location)
if err != nil {
return nil, err
}
k8s, err := kubernetes.GetKubernetes(environment.Data.Kubernetes) k8s, err := kubernetes.GetKubernetes(environment.Data.Kubernetes)
if err != nil { if err != nil {
return nil, err return nil, err
@ -132,8 +122,8 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*pr
Spec: &proto.EnvironmentSpec{ Spec: &proto.EnvironmentSpec{
Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]), Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]),
Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]), Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]),
ServerLocation: proto.Location(proto.Location_value[location]), ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(environment.Data.Location)]),
ServerType: proto.ServerType(proto.ServerType_value[serverType]), ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(environment.Data.ServerType)]),
}, },
Metadata: &proto.EnvironmentMetadata{ Metadata: &proto.EnvironmentMetadata{
Name: environment.Data.Name, Name: environment.Data.Name,
@ -160,16 +150,6 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen
return err return err
} }
serverType, err := provider.RawServerType(environment.Data.ServerType)
if err != nil {
return err
}
location, err := provider.RawServerLocation(environment.Data.Location)
if err != nil {
return err
}
k8s, err := kubernetes.GetKubernetes(environment.Data.Kubernetes) k8s, err := kubernetes.GetKubernetes(environment.Data.Kubernetes)
if err != nil { if err != nil {
return err return err
@ -183,8 +163,8 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen
Spec: &proto.EnvironmentSpec{ Spec: &proto.EnvironmentSpec{
Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]), Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]),
Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]), Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]),
ServerLocation: proto.Location(proto.Location_value[location]), ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(environment.Data.Location)]),
ServerType: proto.ServerType(proto.ServerType_value[serverType]), ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(environment.Data.ServerType)]),
}, },
}); err != nil { }); err != nil {
return err return err

View File

@ -171,6 +171,7 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) {
i.Token = env.Token i.Token = env.Token
i.UserID = env.UserID i.UserID = env.UserID
i.Data = data i.Data = data
i.Controller = env.Controller
if err := i.Get(ctx); err != nil { if err := i.Get(ctx); err != nil {
return nil, err return nil, err
} }

View File

@ -11,8 +11,8 @@ type Providers interface {
RawProviderName() string RawProviderName() string
GetServerType(string) (string, error) GetServerType(string) (string, error)
GetServerLocation(string) (string, error) GetServerLocation(string) (string, error)
RawServerType(string) (string, error) RawServerType(string) string
RawServerLocation(string) (string, error) RawServerLocation(string) string
} }
func GetProvider(provider string) (Providers, error) { func GetProvider(provider string) (Providers, error) {

View File

@ -21,38 +21,37 @@ func (h *Hetzner) RawProviderName() string {
} }
// RawServerLocation implements Providers. // RawServerLocation implements Providers.
func (h *Hetzner) RawServerLocation(location string) (string, error) { func (h *Hetzner) RawServerLocation(location string) string {
switch location { switch location {
case "ash": case "ash":
return proto.Location_LOCATION_HETZNER_ASHBURN.String(), nil return proto.Location_LOCATION_HETZNER_ASHBURN.String()
case "hil": case "hil":
return proto.Location_LOCATION_HETZNER_HILLSBORO.String(), nil return proto.Location_LOCATION_HETZNER_HILLSBORO.String()
case "fsn1": case "fsn1":
return proto.Location_LOCATION_HETZNER_FALKENSTEIN.String(), nil return proto.Location_LOCATION_HETZNER_FALKENSTEIN.String()
case "nbg1": case "nbg1":
return proto.Location_LOCATION_HETZNER_NUREMBERG.String(), nil return proto.Location_LOCATION_HETZNER_NUREMBERG.String()
case "hel1": case "hel1":
return proto.Location_LOCATION_HETZNER_HELSINKI.String(), nil return proto.Location_LOCATION_HETZNER_HELSINKI.String()
default: default:
return "", fmt.Errorf("unknown location: %s", location) return proto.Location_LOCATION_UNSPECIFIED.String()
} }
} }
// RawServerType implements Providers. // RawServerType implements Providers.
func (h *Hetzner) RawServerType(kind string) (string, error) { func (h *Hetzner) RawServerType(kind string) string {
switch kind { switch kind {
case "cpx21": case "cpx21":
return proto.ServerType_SERVER_TYPE_STARTER.String(), nil return proto.ServerType_SERVER_TYPE_STARTER.String()
case "cpx31": case "cpx31":
return proto.ServerType_SERVER_TYPE_REGULAR.String(), nil return proto.ServerType_SERVER_TYPE_REGULAR.String()
case "cpx41": case "cpx41":
return proto.ServerType_SERVER_TYPE_PLUS.String(), nil return proto.ServerType_SERVER_TYPE_PLUS.String()
case "cpx51": case "cpx51":
return proto.ServerType_SERVER_TYPE_PRO.String(), nil return proto.ServerType_SERVER_TYPE_PRO.String()
default: default:
err := fmt.Errorf("unknown server type: %s", kind) return proto.ServerType_SERVER_TYPE_UNSPECIFIED.String()
return "", err
} }
} }