@@ -3,7 +3,6 @@ package client
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
- "errors"
7
6
"fmt"
8
7
"net/http"
9
8
"os"
@@ -17,7 +16,6 @@ import (
17
16
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
18
17
"github.com/DefangLabs/defang/src/protos/io/defang/v1/defangv1connect"
19
18
"github.com/bufbuild/connect-go"
20
- compose "github.com/compose-spec/compose-go/v2/types"
21
19
"github.com/google/uuid"
22
20
"google.golang.org/protobuf/types/known/emptypb"
23
21
)
@@ -30,6 +28,8 @@ type GrpcClient struct {
30
28
Loader ProjectLoader
31
29
}
32
30
31
+ var _ FabricClient = & GrpcClient {}
32
+
33
33
func NewGrpcClient (host , accessToken string , tenantID types.TenantID , loader ProjectLoader ) * GrpcClient {
34
34
baseUrl := "http://"
35
35
if strings .HasSuffix (host , ":443" ) {
@@ -62,11 +62,6 @@ func getMsg[T any](resp *connect.Response[T], err error) (*T, error) {
62
62
return resp .Msg , nil
63
63
}
64
64
65
- func (g GrpcClient ) LoadProject () (* compose.Project , error ) {
66
- projectName , _ := g .LoadProjectName ()
67
- return g .Loader .LoadWithDefaultProjectName (projectName )
68
- }
69
-
70
65
func (g GrpcClient ) GetVersions (ctx context.Context ) (* defangv1.Version , error ) {
71
66
return getMsg (g .client .GetVersion (ctx , & connect.Request [emptypb.Empty ]{}))
72
67
}
@@ -81,53 +76,15 @@ func (g GrpcClient) RevokeToken(ctx context.Context) error {
81
76
return err
82
77
}
83
78
84
- func (g GrpcClient ) Update (ctx context.Context , req * defangv1.Service ) (* defangv1.ServiceInfo , error ) {
85
- return getMsg (g .client .Update (ctx , connect .NewRequest (req )))
86
- }
87
-
88
- func (g GrpcClient ) Deploy (ctx context.Context , req * defangv1.DeployRequest ) (* defangv1.DeployResponse , error ) {
89
- return getMsg (g .client .Deploy (ctx , connect .NewRequest (req )))
90
- }
91
-
92
- func (g GrpcClient ) GetService (ctx context.Context , req * defangv1.ServiceID ) (* defangv1.ServiceInfo , error ) {
93
- return getMsg (g .client .Get (ctx , connect .NewRequest (req )))
94
- }
95
-
96
- func (g GrpcClient ) Delete (ctx context.Context , req * defangv1.DeleteRequest ) (* defangv1.DeleteResponse , error ) {
97
- return getMsg (g .client .Delete (ctx , connect .NewRequest (req )))
98
- }
99
-
100
79
func (g GrpcClient ) Publish (ctx context.Context , req * defangv1.PublishRequest ) error {
101
80
_ , err := g .client .Publish (ctx , connect .NewRequest (req ))
102
81
return err
103
82
}
104
83
105
- func (g GrpcClient ) GetServices (ctx context.Context ) (* defangv1.ListServicesResponse , error ) {
106
- return getMsg (g .client .GetServices (ctx , & connect.Request [emptypb.Empty ]{}))
107
- }
108
-
109
84
func (g GrpcClient ) GenerateFiles (ctx context.Context , req * defangv1.GenerateFilesRequest ) (* defangv1.GenerateFilesResponse , error ) {
110
85
return getMsg (g .client .GenerateFiles (ctx , connect .NewRequest (req )))
111
86
}
112
87
113
- func (g GrpcClient ) PutConfig (ctx context.Context , req * defangv1.SecretValue ) error {
114
- _ , err := g .client .PutSecret (ctx , connect .NewRequest (req ))
115
- return err
116
- }
117
-
118
- func (g GrpcClient ) DeleteConfig (ctx context.Context , req * defangv1.Secrets ) error {
119
- _ , err := g .client .DeleteSecrets (ctx , connect .NewRequest (& defangv1.Secrets {Names : req .Names }))
120
- return err
121
- }
122
-
123
- func (g GrpcClient ) ListConfig (ctx context.Context ) (* defangv1.Secrets , error ) {
124
- return getMsg (g .client .ListSecrets (ctx , & connect.Request [emptypb.Empty ]{}))
125
- }
126
-
127
- func (g GrpcClient ) CreateUploadURL (ctx context.Context , req * defangv1.UploadURLRequest ) (* defangv1.UploadURLResponse , error ) {
128
- return getMsg (g .client .CreateUploadURL (ctx , connect .NewRequest (req )))
129
- }
130
-
131
88
func (g GrpcClient ) WhoAmI (ctx context.Context ) (* defangv1.WhoAmIResponse , error ) {
132
89
return getMsg (g .client .WhoAmI (ctx , & connect.Request [emptypb.Empty ]{}))
133
90
}
@@ -145,14 +102,6 @@ func (g GrpcClient) GetDelegateSubdomainZone(ctx context.Context) (*defangv1.Del
145
102
return getMsg (g .client .GetDelegateSubdomainZone (ctx , & connect.Request [emptypb.Empty ]{}))
146
103
}
147
104
148
- func (g * GrpcClient ) Tail (ctx context.Context , req * defangv1.TailRequest ) (ServerStream [defangv1.TailResponse ], error ) {
149
- return g .client .Tail (ctx , connect .NewRequest (req ))
150
- }
151
-
152
- func (g * GrpcClient ) BootstrapCommand (ctx context.Context , command string ) (types.ETag , error ) {
153
- return "" , errors .New ("the bootstrap command is not valid for the Defang provider" )
154
- }
155
-
156
105
func (g * GrpcClient ) AgreeToS (ctx context.Context ) error {
157
106
_ , err := g .client .SignEULA (ctx , & connect.Request [emptypb.Empty ]{})
158
107
return err
@@ -183,58 +132,3 @@ func (g *GrpcClient) CheckLoginAndToS(ctx context.Context) error {
183
132
_ , err := g .client .CheckToS (ctx , & connect.Request [emptypb.Empty ]{})
184
133
return err
185
134
}
186
-
187
- func (g * GrpcClient ) Destroy (ctx context.Context ) (types.ETag , error ) {
188
- // Get all the services in the project and delete them all at once
189
- project , err := g .GetServices (ctx )
190
- if err != nil {
191
- return "" , err
192
- }
193
- if len (project .Services ) == 0 {
194
- return "" , errors .New ("no services found" )
195
- }
196
- var names []string
197
- for _ , service := range project .Services {
198
- names = append (names , service .Service .Name )
199
- }
200
- resp , err := g .Delete (ctx , & defangv1.DeleteRequest {Names : names })
201
- if err != nil {
202
- return "" , err
203
- }
204
- return resp .Etag , nil
205
- }
206
-
207
- func (g * GrpcClient ) TearDown (ctx context.Context ) error {
208
- return errors .New ("the teardown command is not valid for the Defang provider" )
209
- }
210
-
211
- func (g * GrpcClient ) BootstrapList (context.Context ) ([]string , error ) {
212
- return nil , errors .New ("this command is not valid for the Defang provider" )
213
- }
214
-
215
- func (g * GrpcClient ) Restart (ctx context.Context , names ... string ) (types.ETag , error ) {
216
- // For now, we'll just get the service info and pass it back to Deploy as-is.
217
- services := make ([]* defangv1.Service , 0 , len (names ))
218
- for _ , name := range names {
219
- serviceInfo , err := g .GetService (ctx , & defangv1.ServiceID {Name : name })
220
- if err != nil {
221
- return "" , err
222
- }
223
- services = append (services , serviceInfo .Service )
224
- }
225
-
226
- dr , err := g .Deploy (ctx , & defangv1.DeployRequest {Services : services })
227
- if err != nil {
228
- return "" , err
229
- }
230
- return dr .Etag , nil
231
- }
232
-
233
- func (g GrpcClient ) ServiceDNS (name string ) string {
234
- whoami , _ := g .WhoAmI (context .TODO ())
235
- return whoami .Tenant + "-" + name
236
- }
237
-
238
- func (g GrpcClient ) LoadProjectName () (string , error ) {
239
- return string (g .tenantID ), nil
240
- }
0 commit comments