github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/config/awsticket/awsticket.go (about)

     1  // Copyright 2019 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package awsticket
     6  
     7  import (
     8  	"time"
     9  
    10  	"github.com/aws/aws-sdk-go/aws"
    11  	"github.com/aws/aws-sdk-go/aws/credentials"
    12  	"github.com/aws/aws-sdk-go/aws/session"
    13  	"github.com/Schaudge/grailbase/cloud/awssession"
    14  	"github.com/Schaudge/grailbase/config"
    15  	"github.com/Schaudge/grailbase/vcontext"
    16  )
    17  
    18  func init() {
    19  	config.Register("aws/ticket", func(constr *config.Constructor[*session.Session]) {
    20  		var (
    21  			region = constr.String("region", "us-west-2", "the default AWS region for the session")
    22  			path   = constr.String("path", "tickets/eng/dev/aws", "path to AWS ticket")
    23  		)
    24  		constr.Doc = "configure an AWS session from a GRAIL ticket server path"
    25  		constr.New = func() (*session.Session, error) {
    26  			return session.NewSession(&aws.Config{
    27  				Credentials: credentials.NewCredentials(&awssession.Provider{
    28  					Ctx:        vcontext.Background(),
    29  					Timeout:    10 * time.Second,
    30  					TicketPath: *path,
    31  				}),
    32  				Region: region,
    33  			})
    34  		}
    35  	})
    36  }