Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "log"
- "os"
- "github.com/aws/aws-sdk-go/aws"
- "github.com/aws/aws-sdk-go/aws/awserr"
- "github.com/aws/aws-lambda-go/lambda"
- "github.com/aws/aws-sdk-go/aws/session"
- cidp "github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
- cidpif "github.com/aws/aws-sdk-go/service/cognitoidentityprovider/cognitoidentityprovideriface"
- util "github.com/sean/repo/internal/util"
- )
- type application struct {
- config configuration
- }
- type configuration struct {
- ClientPoolID string
- UserPoolID string
- idp cidpif.CognitoIdentityProviderAPI
- }
- func (app application) getUserPoolClientSecret() (string, error) {
- input := &cidp.DescribeUserPoolClientInput{
- UserPoolId: aws.String(app.config.UserPoolID),
- ClientId: aws.String(app.config.ClientPoolID),
- }
- resp, err := app.config.idp.DescribeUserPoolClient(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- log.Printf("[ERROR] %v", aerr.Error())
- } else {
- log.Printf("[ERROR] %v", err.Error())
- }
- return "", err
- }
- log.Println("[INFO] Obtained user pool client secret successfully")
- return *resp.UserPoolClient.ClientSecret, nil
- }
- func main() {
- config := configuration{
- ClientPoolID: os.Getenv("CLIENT_POOL_ID"),
- UserPoolID: os.Getenv("USER_POOL_ID"),
- idp: cidp.New(session.Must(session.NewSession())),
- }
- app := application{config: config}
- lambda.Start(app.handler) // handler() calls app.getUserPoolClientSecret
- }
Advertisement
Add Comment
Please, Sign In to add comment