Return the created env on create req
This commit is contained in:
parent
99ee44b431
commit
c49e885255
@ -113,16 +113,6 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*pr
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -132,8 +122,8 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*pr
|
||||
Spec: &proto.EnvironmentSpec{
|
||||
Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]),
|
||||
Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]),
|
||||
ServerLocation: proto.Location(proto.Location_value[location]),
|
||||
ServerType: proto.ServerType(proto.ServerType_value[serverType]),
|
||||
ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(environment.Data.Location)]),
|
||||
ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(environment.Data.ServerType)]),
|
||||
},
|
||||
Metadata: &proto.EnvironmentMetadata{
|
||||
Name: environment.Data.Name,
|
||||
@ -160,16 +150,6 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -183,8 +163,8 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen
|
||||
Spec: &proto.EnvironmentSpec{
|
||||
Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]),
|
||||
Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]),
|
||||
ServerLocation: proto.Location(proto.Location_value[location]),
|
||||
ServerType: proto.ServerType(proto.ServerType_value[serverType]),
|
||||
ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(environment.Data.Location)]),
|
||||
ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(environment.Data.ServerType)]),
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
|
@ -171,6 +171,7 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) {
|
||||
i.Token = env.Token
|
||||
i.UserID = env.UserID
|
||||
i.Data = data
|
||||
i.Controller = env.Controller
|
||||
if err := i.Get(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ type Providers interface {
|
||||
RawProviderName() string
|
||||
GetServerType(string) (string, error)
|
||||
GetServerLocation(string) (string, error)
|
||||
RawServerType(string) (string, error)
|
||||
RawServerLocation(string) (string, error)
|
||||
RawServerType(string) string
|
||||
RawServerLocation(string) string
|
||||
}
|
||||
|
||||
func GetProvider(provider string) (Providers, error) {
|
||||
|
@ -21,38 +21,37 @@ func (h *Hetzner) RawProviderName() string {
|
||||
}
|
||||
|
||||
// RawServerLocation implements Providers.
|
||||
func (h *Hetzner) RawServerLocation(location string) (string, error) {
|
||||
func (h *Hetzner) RawServerLocation(location string) string {
|
||||
switch location {
|
||||
case "ash":
|
||||
return proto.Location_LOCATION_HETZNER_ASHBURN.String(), nil
|
||||
return proto.Location_LOCATION_HETZNER_ASHBURN.String()
|
||||
case "hil":
|
||||
return proto.Location_LOCATION_HETZNER_HILLSBORO.String(), nil
|
||||
return proto.Location_LOCATION_HETZNER_HILLSBORO.String()
|
||||
case "fsn1":
|
||||
return proto.Location_LOCATION_HETZNER_FALKENSTEIN.String(), nil
|
||||
return proto.Location_LOCATION_HETZNER_FALKENSTEIN.String()
|
||||
case "nbg1":
|
||||
return proto.Location_LOCATION_HETZNER_NUREMBERG.String(), nil
|
||||
return proto.Location_LOCATION_HETZNER_NUREMBERG.String()
|
||||
case "hel1":
|
||||
return proto.Location_LOCATION_HETZNER_HELSINKI.String(), nil
|
||||
return proto.Location_LOCATION_HETZNER_HELSINKI.String()
|
||||
default:
|
||||
return "", fmt.Errorf("unknown location: %s", location)
|
||||
return proto.Location_LOCATION_UNSPECIFIED.String()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// RawServerType implements Providers.
|
||||
func (h *Hetzner) RawServerType(kind string) (string, error) {
|
||||
func (h *Hetzner) RawServerType(kind string) string {
|
||||
switch kind {
|
||||
case "cpx21":
|
||||
return proto.ServerType_SERVER_TYPE_STARTER.String(), nil
|
||||
return proto.ServerType_SERVER_TYPE_STARTER.String()
|
||||
case "cpx31":
|
||||
return proto.ServerType_SERVER_TYPE_REGULAR.String(), nil
|
||||
return proto.ServerType_SERVER_TYPE_REGULAR.String()
|
||||
case "cpx41":
|
||||
return proto.ServerType_SERVER_TYPE_PLUS.String(), nil
|
||||
return proto.ServerType_SERVER_TYPE_PLUS.String()
|
||||
case "cpx51":
|
||||
return proto.ServerType_SERVER_TYPE_PRO.String(), nil
|
||||
return proto.ServerType_SERVER_TYPE_PRO.String()
|
||||
default:
|
||||
err := fmt.Errorf("unknown server type: %s", kind)
|
||||
return "", err
|
||||
return proto.ServerType_SERVER_TYPE_UNSPECIFIED.String()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user