github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/cloud/awssession/session.go (about) 1 // Copyright 2018 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 awssession provides a simple way to obtain AWS session.Session 6 // using GRAIL tickets. 7 package awssession 8 9 import ( 10 "time" 11 12 "github.com/aws/aws-sdk-go/aws" 13 "github.com/aws/aws-sdk-go/aws/credentials" 14 "github.com/aws/aws-sdk-go/aws/session" 15 "v.io/v23/context" 16 ) 17 18 const ( 19 region = "us-west-2" 20 defaultTimeout = 10 * time.Second 21 ) 22 23 // NewWithTicket creates an AWS session using a GRAIL ticket. The returned 24 // session uses a Provider with a timeout of 10 seconds. The region will be set 25 // to 'us-west-2' and can be overridden by passing an appropriate *aws.Config. 26 func NewWithTicket(ctx *context.T, ticketPath string, cfgs ...*aws.Config) (*session.Session, error) { 27 cfg := NewConfigWithTicket(ctx, ticketPath) 28 cfgs = append([]*aws.Config{cfg}, cfgs...) 29 return session.NewSession(cfgs...) 30 } 31 32 // NewConfigWithTicket creates an AWS configuration using a GRAIL ticket. The 33 // returned configuration uses a Provider with a timeout of 10 seconds. The 34 // region will be set to 'us-west-2'. 35 func NewConfigWithTicket(ctx *context.T, ticketPath string) *aws.Config { 36 creds := credentials.NewCredentials(&Provider{ 37 Ctx: ctx, 38 Timeout: defaultTimeout, 39 TicketPath: ticketPath, 40 }) 41 return aws.NewConfig().WithCredentials(creds).WithRegion(region) 42 }