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