@@ -49,29 +49,50 @@ func (c Client) EnvironmentsByOrganization(ctx context.Context, userID, orgID st
49
49
// DialWsep dials an environments command execution interface
50
50
// See github.com/cdr/wsep for details
51
51
func (c Client ) DialWsep (ctx context.Context , env * Environment ) (* websocket.Conn , error ) {
52
- u := c .copyURL ()
53
- if c .BaseURL .Scheme == "https" {
54
- u .Scheme = "wss"
55
- } else {
56
- u .Scheme = "ws"
57
- }
58
- u .Path = "/proxy/environments/" + env .ID + "/wsep"
52
+ return c .dialWs (ctx , "/proxy/environments/" + env .ID + "/wsep" )
53
+ }
54
+
55
+ // CreateEnvironmentRequest is used to configure a new environment
56
+ type CreateEnvironmentRequest struct {
57
+ Name string `json:"name"`
58
+ ImageID string `json:"image_id"`
59
+ ImageTag string `json:"image_tag"`
60
+ CPUCores float32 `json:"cpu_cores"`
61
+ MemoryGB int `json:"memory_gb"`
62
+ DiskGB int `json:"disk_gb"`
63
+ GPUs int `json:"gpus"`
64
+ Services []string `json:"services"`
65
+ }
59
66
60
- ctx , cancel := context .WithTimeout (ctx , time .Second * 15 )
61
- defer cancel ()
67
+ // CreateEnvironment sends a request to create an environment.
68
+ func (c Client ) CreateEnvironment (ctx context.Context , orgID string , req CreateEnvironmentRequest ) (Environment , error ) {
69
+ var env Environment
70
+ err := c .requestBody (
71
+ ctx ,
72
+ http .MethodPost , "/api/orgs/" + orgID + "/environments" ,
73
+ req ,
74
+ & env ,
75
+ )
76
+ return env , err
77
+ }
62
78
63
- conn , resp , err := websocket .Dial (ctx , u .String (),
64
- & websocket.DialOptions {
65
- HTTPHeader : map [string ][]string {
66
- "Cookie" : {"session_token=" + c .Token },
67
- },
68
- },
79
+ // DialEnvironmentBuildLog opens a websocket connection for the environment build log messages
80
+ func (c Client ) DialEnvironmentBuildLog (ctx context.Context , envID string ) (* websocket.Conn , error ) {
81
+ return c .dialWs (ctx , "/api/environments/" + envID + "/watch-update" )
82
+ }
83
+
84
+ // DialEnvironmentStats opens a websocket connection for environment stats
85
+ func (c Client ) DialEnvironmentStats (ctx context.Context , envID string ) (* websocket.Conn , error ) {
86
+ return c .dialWs (ctx , "/api/environments/" + envID + "/watch-stats" )
87
+ }
88
+
89
+ // DeleteEnvironment deletes the environment.
90
+ func (c Client ) DeleteEnvironment (ctx context.Context , envID string ) error {
91
+ err := c .requestBody (
92
+ ctx ,
93
+ http .MethodDelete , "/api/environments/" + envID ,
94
+ nil ,
95
+ nil ,
69
96
)
70
- if err != nil {
71
- if resp != nil {
72
- return nil , bodyError (resp )
73
- }
74
- return nil , err
75
- }
76
- return conn , nil
97
+ return err
77
98
}
0 commit comments