@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "github.com/weka/go-cloud-lib/lib/weka"
6
7
"os"
7
8
"strconv"
8
9
"strings"
@@ -13,8 +14,10 @@ import (
13
14
"github.com/weka/aws-tf/modules/deploy_weka/lambdas/common"
14
15
"github.com/weka/aws-tf/modules/deploy_weka/lambdas/connectors"
15
16
lambdas "github.com/weka/aws-tf/modules/deploy_weka/lambdas/functions/fetch"
17
+ "github.com/weka/aws-tf/modules/deploy_weka/lambdas/functions/management"
16
18
"github.com/weka/aws-tf/modules/deploy_weka/lambdas/functions/terminate"
17
- "github.com/weka/aws-tf/modules/deploy_weka/lambdas/management"
19
+ "github.com/weka/aws-tf/modules/deploy_weka/lambdas/functions/weka_api"
20
+
18
21
"github.com/weka/go-cloud-lib/logging"
19
22
"github.com/weka/go-cloud-lib/scale_down"
20
23
@@ -315,55 +318,17 @@ func getClusterStatus(ctx context.Context, stateTable, stateTableHashKey, stateK
315
318
return clusterStatus , nil
316
319
}
317
320
318
- clusterName := os .Getenv ("CLUSTER_NAME" )
319
- if clusterName == "" {
320
- return protocol.ClusterStatus {}, fmt .Errorf ("CLUSTER_NAME is not set" )
321
- }
322
- ips , err := common .GetBackendsPrivateIps (clusterName , "backend" )
323
- if err != nil {
324
- return protocol.ClusterStatus {}, fmt .Errorf ("getClusterStatus > GetBackendsPrivateIps: %w" , err )
325
- }
326
- log .Info ().Msgf ("GetClusterStatus > Backend private IPs: %v" , ips )
327
-
328
- managementLambdaName := os .Getenv ("MANAGEMENT_LAMBDA" )
329
- if managementLambdaName == "" {
330
- return protocol.ClusterStatus {}, fmt .Errorf ("MANAGEMENT_LAMBDA is not set" )
331
- }
332
-
333
- useSecretManagerEndpoint , err := strconv .ParseBool (os .Getenv ("USE_SECRETMANAGER_ENDPOINT" ))
334
- if err != nil {
335
- log .Warn ().Msg ("Failed to parse USE_SECRETMANAGER_ENDPOINT, assuming false" )
336
- }
337
- var username , password string
338
- if ! useSecretManagerEndpoint {
339
- log .Info ().Msg ("Secret manager endpoint not in use, sending credentials in body" )
340
- usernameId := os .Getenv ("USERNAME_ID" )
341
- deploymentPasswordId := os .Getenv ("DEPLOYMENT_PASSWORD_ID" )
342
- adminPasswordId := os .Getenv ("ADMIN_PASSWORD_ID" )
343
- creds , err := common .GetDeploymentOrAdminUsernameAndPassword (usernameId , deploymentPasswordId , adminPasswordId )
344
- if err != nil {
345
- return protocol.ClusterStatus {}, fmt .Errorf ("getClusterStatus > GetDeploymentOrAdminUsernameAndPassword: %w" , err )
346
- }
347
-
348
- username = creds .Username
349
- password = creds .Password
350
- }
351
-
352
- managementRequest := management.ManagementRequest {
353
- Type : "status" ,
354
- WekaStatusRequest : management.WekaStatusRequest {
355
- BackendPrivateIps : ips ,
356
- Username : username ,
357
- Password : password , // empty string is interpreted as no credentials
358
- },
321
+ wekaApiRequest := management.WekaApiRequest {
322
+ Method : weka .JrpcStatus ,
359
323
}
360
324
var wekaStatus * protocol.WekaStatus
361
- wekaStatus , err = common . InvokeLambdaFunction [protocol.WekaStatus ](managementLambdaName , managementRequest )
325
+ wekaStatus , err = weka_api . MakeWekaApiRequest [protocol.WekaStatus ](ctx , & wekaApiRequest )
362
326
if err != nil {
363
- wrappedError := fmt .Errorf ("getClusterStatus > InvokeLambdaFunction : %w" , err )
327
+ wrappedError := fmt .Errorf ("getClusterStatus > MakeWekaApiRequest : %w" , err )
364
328
log .Error ().Err (wrappedError ).Send ()
365
329
wekaStatus = & protocol.WekaStatus {}
366
330
}
331
+
367
332
clusterStatus .WekaStatus = * wekaStatus
368
333
369
334
return clusterStatus , nil
@@ -423,30 +388,28 @@ func scaleDownHandler(ctx context.Context, info protocol.HostGroupInfoResponse)
423
388
return scale_down .ScaleDown (ctx , info )
424
389
}
425
390
426
- func managementHandler (ctx context.Context , req management.ManagementRequest ) (protocol.WekaStatus , error ) {
427
- switch req .Type {
428
- case "status" :
429
- useSecretManagerEndpoint , err := strconv .ParseBool (os .Getenv ("USE_SECRETMANAGER_ENDPOINT" ))
391
+ func managementHandler (ctx context.Context , req management.ManagementRequest ) (interface {}, error ) {
392
+ useSecretManagerEndpoint , err := strconv .ParseBool (os .Getenv ("USE_SECRETMANAGER_ENDPOINT" ))
393
+ if err != nil {
394
+ log .Warn ().Msg ("Failed to parse USE_SECRETMANAGER_ENDPOINT, assuming false" )
395
+ }
396
+ if useSecretManagerEndpoint && req .Password == "" {
397
+ usernameId := os .Getenv ("USERNAME_ID" )
398
+ deploymentPasswordId := os .Getenv ("DEPLOYMENT_PASSWORD_ID" )
399
+ adminPasswordId := os .Getenv ("ADMIN_PASSWORD_ID" )
400
+ creds , err := common .GetDeploymentOrAdminUsernameAndPassword (usernameId , deploymentPasswordId , adminPasswordId )
430
401
if err != nil {
431
- log .Warn ().Msg ("Failed to parse USE_SECRETMANAGER_ENDPOINT, assuming false" )
402
+ log .Error ().Err (err ).Send ()
403
+ return nil , err
432
404
}
433
- if useSecretManagerEndpoint && req .Password == "" {
434
- usernameId := os .Getenv ("USERNAME_ID" )
435
- deploymentPasswordId := os .Getenv ("DEPLOYMENT_PASSWORD_ID" )
436
- adminPasswordId := os .Getenv ("ADMIN_PASSWORD_ID" )
437
- creds , err := common .GetDeploymentOrAdminUsernameAndPassword (usernameId , deploymentPasswordId , adminPasswordId )
438
- if err != nil {
439
- log .Error ().Err (err ).Send ()
440
- return protocol.WekaStatus {}, err
441
- }
442
- req .Username = creds .Username
443
- req .Password = creds .Password
444
- }
445
- return management .GetWekaStatus (ctx , req .WekaStatusRequest )
446
- default :
447
- log .Error ().Msgf ("Invalid management type: %s" , req .Type )
448
- return protocol.WekaStatus {}, fmt .Errorf ("invalid management type: %s" , req .Type )
405
+ req .Username = creds .Username
406
+ req .Password = creds .Password
449
407
}
408
+ return management .CallJRPC (ctx , req )
409
+ }
410
+
411
+ func wekaApiHandler (ctx context.Context , req management.WekaApiRequest ) (interface {}, error ) {
412
+ return weka_api .MakeWekaApiRequest [interface {}](ctx , & req )
450
413
}
451
414
452
415
func main () {
@@ -473,6 +436,8 @@ func main() {
473
436
lambda .Start (transientHandler )
474
437
case "management" :
475
438
lambda .Start (managementHandler )
439
+ case "weka-api" :
440
+ lambda .Start (wekaApiHandler )
476
441
default :
477
442
lambda .Start (func () error { return fmt .Errorf ("unsupported lambda command" ) })
478
443
}
0 commit comments