diff --git a/api/v1/environments.go b/api/v1/environments.go index 3ef772a..7da0d1d 100644 --- a/api/v1/environments.go +++ b/api/v1/environments.go @@ -152,9 +152,36 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen } for _, env := range envs { + provider, err := providers.GetProvider(environment.Data.Provider) + if err != nil { + 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 + } + if err := stream.Send(&proto.EnvironmentFull{ Metadata: &proto.EnvironmentMetadata{ - Name: env, + Name: env.Data.Name, + Description: env.Data.Description, + }, + 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]), }, }); err != nil { return err diff --git a/internal/controllers/environments.go b/internal/controllers/environments.go index bdce948..1c20168 100644 --- a/internal/controllers/environments.go +++ b/internal/controllers/environments.go @@ -143,7 +143,7 @@ func (env *Environemnt) Delete(ctx context.Context) error { return nil } -func (env *Environemnt) ListEnvs(ctx context.Context) ([]string, error) { +func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) { env.Controller.GetClient() conf := &rest.Config{ Host: "https://kubernetes.default.svc.cluster.local:443", @@ -154,17 +154,27 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]string, error) { } clientset, err := kubernetes.NewForConfig(conf) if err != nil { - return []string{}, err + return nil, err } - secrets, err := clientset.CoreV1().ConfigMaps(env.UserID).List(ctx, metav1.ListOptions{LabelSelector: "kind=environment"}) + configmaps, err := clientset.CoreV1().ConfigMaps(env.UserID).List(ctx, metav1.ListOptions{LabelSelector: "kind=environment"}) if err != nil { - return []string{}, err + return nil, err } - result := []string{} - log.Println(secrets) - for _, env := range secrets.Items { - result = append(result, env.Name) + result := []*Environemnt{} + log.Println(configmaps) + for _, cm := range configmaps.Items { + i := &Environemnt{} + data := &EnvironemntData{ + Name: cm.GetName(), + } + i.Token = env.Token + i.UserID = env.UserID + i.Data = data + if err := i.Get(ctx); err != nil { + return nil, err + } + result = append(result, i) } return result, nil }