Add a dummy get method
This commit is contained in:
parent
18936f7803
commit
a23773d2ab
@ -93,7 +93,38 @@ func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.EnvironmentFu
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.EnvironmentId) (*proto.EnvironmentFull, error) {
|
func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.EnvironmentId) (*proto.EnvironmentFull, error) {
|
||||||
return nil, nil
|
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 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &proto.EnvironmentFull{
|
||||||
|
Id: &proto.EnvironmentId{
|
||||||
|
Id: "test",
|
||||||
|
},
|
||||||
|
Data: &proto.EnvironmentData{
|
||||||
|
Name: environment.Data.Name,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EnvironmentsServer) List(in *empty.Empty, stream proto.Environments_ListServer) error {
|
func (e *EnvironmentsServer) List(in *empty.Empty, stream proto.Environments_ListServer) error {
|
||||||
|
1
go.mod
1
go.mod
@ -6,6 +6,7 @@ require (
|
|||||||
github.com/alecthomas/assert/v2 v2.6.0
|
github.com/alecthomas/assert/v2 v2.6.0
|
||||||
github.com/alecthomas/kong v0.9.0
|
github.com/alecthomas/kong v0.9.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/joho/godotenv v1.5.1
|
||||||
golang.org/x/crypto v0.21.0
|
golang.org/x/crypto v0.21.0
|
||||||
k8s.io/api v0.29.3
|
k8s.io/api v0.29.3
|
||||||
k8s.io/apimachinery v0.29.3
|
k8s.io/apimachinery v0.29.3
|
||||||
|
2
go.sum
2
go.sum
@ -58,6 +58,8 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
|
|||||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||||
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
|
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
|
||||||
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/kube"
|
"git.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/kube"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -166,3 +168,31 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (env *Environemnt) Get(ctx context.Context) error {
|
||||||
|
env.Controller.GetClient()
|
||||||
|
conf := &rest.Config{
|
||||||
|
Host: "https://kubernetes.default.svc.cluster.local:443",
|
||||||
|
BearerToken: env.Token,
|
||||||
|
TLSClientConfig: rest.TLSClientConfig{
|
||||||
|
Insecure: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
clientset, err := kubernetes.NewForConfig(conf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
envData, err := clientset.CoreV1().ConfigMaps(env.UserID).Get(ctx, env.Data.Name, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := godotenv.Unmarshal(envData.Data["vars"])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
env.Data.Provider = res["SP_PROVIDER"]
|
||||||
|
env.Data.Kubernetes = res["SP_KUBERNETES"]
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user