Guest User

Untitled

a guest
Jan 15th, 2021
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.48 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "log"
  6.     "os"
  7.  
  8.     "github.com/aws/aws-sdk-go/aws"
  9.     "github.com/aws/aws-sdk-go/aws/awserr"
  10.     "github.com/aws/aws-lambda-go/lambda"
  11.     "github.com/aws/aws-sdk-go/aws/session"
  12.     cidp "github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
  13.     cidpif "github.com/aws/aws-sdk-go/service/cognitoidentityprovider/cognitoidentityprovideriface"
  14.     util "github.com/sean/repo/internal/util"
  15. )
  16.  
  17. type application struct {
  18.     config configuration
  19. }
  20.  
  21. type configuration struct {
  22.     ClientPoolID string
  23.     UserPoolID   string
  24.     idp          cidpif.CognitoIdentityProviderAPI
  25. }
  26.  
  27. func (app application) getUserPoolClientSecret() (string, error) {
  28.     input := &cidp.DescribeUserPoolClientInput{
  29.         UserPoolId: aws.String(app.config.UserPoolID),
  30.         ClientId:   aws.String(app.config.ClientPoolID),
  31.     }
  32.  
  33.     resp, err := app.config.idp.DescribeUserPoolClient(input)
  34.     if err != nil {
  35.         if aerr, ok := err.(awserr.Error); ok {
  36.             log.Printf("[ERROR] %v", aerr.Error())
  37.         } else {
  38.             log.Printf("[ERROR] %v", err.Error())
  39.         }
  40.         return "", err
  41.     }
  42.     log.Println("[INFO] Obtained user pool client secret successfully")
  43.     return *resp.UserPoolClient.ClientSecret, nil
  44. }
  45.  
  46. func main() {
  47.     config := configuration{
  48.         ClientPoolID: os.Getenv("CLIENT_POOL_ID"),
  49.         UserPoolID:   os.Getenv("USER_POOL_ID"),
  50.         idp:          cidp.New(session.Must(session.NewSession())),
  51.     }
  52.  
  53.     app := application{config: config}
  54.  
  55.     lambda.Start(app.handler) // handler() calls app.getUserPoolClientSecret
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment