diff --git a/base/aws.go b/base/aws.go index 7a5f392..e887bc2 100644 --- a/base/aws.go +++ b/base/aws.go @@ -1,15 +1,16 @@ package base import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" ) -func GetSession(region string) (sess *session.Session, err error) { - if sess, err = session.NewSession(&aws.Config{ - Region: aws.String(region), - }); err != nil { - return nil, err +func GetAWSConfig(ctx context.Context, region string) (aws.Config, error) { + cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region)) + if err != nil { + return aws.Config{}, err } - return sess, nil + return cfg, nil } diff --git a/base/cloudwatchlogs.go b/base/cloudwatchlogs.go index 56b25b8..c8c2544 100644 --- a/base/cloudwatchlogs.go +++ b/base/cloudwatchlogs.go @@ -1,28 +1,33 @@ package base import ( + "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/cloudwatchlogs" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs" + "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types" ) func GetLatestCloudwatchLogs(region string, logGroupName string) ([]string, error) { - sess, err := session.NewSession(&aws.Config{ - Region: aws.String(region), - }) + ctx := context.Background() + cfg, err := GetAWSConfig(ctx, region) if err != nil { return nil, err } - svc := cloudwatchlogs.New(sess) + svc := cloudwatchlogs.NewFromConfig(cfg) - streamsIn := new(cloudwatchlogs.DescribeLogStreamsInput).SetDescending( - true).SetLimit(1).SetLogGroupName(logGroupName).SetOrderBy("LastEventTime") - if err = streamsIn.Validate(); err != nil { - return nil, err + descending := true + limit := int32(1) + orderBy := types.OrderByLastEventTime + streamsIn := &cloudwatchlogs.DescribeLogStreamsInput{ + Descending: &descending, + Limit: &limit, + LogGroupName: aws.String(logGroupName), + OrderBy: orderBy, } - streamsOut, err := svc.DescribeLogStreams(streamsIn) + + streamsOut, err := svc.DescribeLogStreams(ctx, streamsIn) if err != nil { return nil, err } @@ -36,19 +41,19 @@ func GetLatestCloudwatchLogs(region string, logGroupName string) ([]string, erro return nil, fmt.Errorf("Unable to find valid stream %+v", streamsOut.LogStreams[0]) } - eventIn := new(cloudwatchlogs.GetLogEventsInput).SetLogGroupName( - logGroupName).SetLogStreamName(*streamName) - if err := eventIn.Validate(); err != nil { - return nil, err + eventIn := &cloudwatchlogs.GetLogEventsInput{ + LogGroupName: aws.String(logGroupName), + LogStreamName: streamName, } - eventOut, err := svc.GetLogEvents(eventIn) + + eventOut, err := svc.GetLogEvents(ctx, eventIn) if err != nil { return nil, err } res := make([]string, 0, len(eventOut.Events)) for _, event := range eventOut.Events { - if event == nil || event.Message == nil || *event.Message == "" { + if event.Message == nil || *event.Message == "" { continue } res = append(res, *event.Message) diff --git a/base/email.go b/base/email.go index 6876f1b..16f2b7c 100644 --- a/base/email.go +++ b/base/email.go @@ -1,11 +1,12 @@ package base import ( + "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ses" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ses" + "github.com/aws/aws-sdk-go-v2/service/ses/types" ) type Emailer interface { @@ -23,7 +24,7 @@ type SESEmailer struct { *DebugOutput sender string region string - ses *ses.SES + ses *ses.Client } func NewSESEmailer(sender, region string, debugConfig *ChatDebugOutputConfig) *SESEmailer { @@ -34,15 +35,15 @@ func NewSESEmailer(sender, region string, debugConfig *ChatDebugOutputConfig) *S } } -func (e *SESEmailer) getClient() *ses.SES { - var err error +func (e *SESEmailer) getClient() *ses.Client { if e.ses == nil { e.Debug("SESEmailer: getting SES client: region: %s", e.region) - var auth *session.Session - if auth, err = GetSession(e.region); err != nil { + ctx := context.Background() + cfg, err := GetAWSConfig(ctx, e.region) + if err != nil { panic(fmt.Sprintf("unable to authenticate to AWS SES: %s", err.Error())) } - e.ses = ses.New(auth) + e.ses = ses.NewFromConfig(cfg) e.Debug("SESEmailer: SES client created") } return e.ses @@ -50,17 +51,18 @@ func (e *SESEmailer) getClient() *ses.SES { func (e *SESEmailer) Send(address, subject, message string) error { cli := e.getClient() - _, err := cli.SendEmail(&ses.SendEmailInput{ + ctx := context.Background() + _, err := cli.SendEmail(ctx, &ses.SendEmailInput{ Source: aws.String(e.sender), - Destination: &ses.Destination{ - ToAddresses: aws.StringSlice([]string{address}), + Destination: &types.Destination{ + ToAddresses: []string{address}, }, - Message: &ses.Message{ - Subject: &ses.Content{ + Message: &types.Message{ + Subject: &types.Content{ Data: aws.String(subject), }, - Body: &ses.Body{ - Html: &ses.Content{ + Body: &types.Body{ + Html: &types.Content{ Data: aws.String(message), }, }, diff --git a/go.mod b/go.mod index e481ef1..a8d9fe3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,10 @@ go 1.24.0 toolchain go1.25.5 require ( - github.com/aws/aws-sdk-go v1.55.7 + github.com/aws/aws-sdk-go-v2 v1.41.0 + github.com/aws/aws-sdk-go-v2/config v1.32.5 + github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2 + github.com/aws/aws-sdk-go-v2/service/ses v1.34.17 github.com/bradleyfalzon/ghinstallation/v2 v2.17.0 github.com/go-sql-driver/mysql v1.9.3 github.com/google/go-github/v31 v31.0.0 @@ -24,6 +27,19 @@ require ( require ( filippo.io/edwards25519 v1.1.0 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.19.5 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16 // indirect + github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.30.7 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 // indirect + github.com/aws/smithy-go v1.24.0 // indirect github.com/go-pkgz/expirable-cache v0.1.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.2 // indirect github.com/google/go-github/v75 v75.0.0 // indirect @@ -39,7 +55,6 @@ require ( github.com/googleapis/gax-go/v2 v2.0.5 // indirect github.com/hashicorp/go-cleanhttp v0.5.1 // indirect github.com/hashicorp/go-retryablehttp v0.6.4 // indirect - github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/go.sum b/go.sum index bf7563c..75ad235 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,40 @@ cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSR filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE= -github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/aws/aws-sdk-go-v2 v1.41.0 h1:tNvqh1s+v0vFYdA1xq0aOJH+Y5cRyZ5upu6roPgPKd4= +github.com/aws/aws-sdk-go-v2 v1.41.0/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 h1:489krEF9xIGkOaaX3CE/Be2uWjiXrkCH6gUX+bZA/BU= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4/go.mod h1:IOAPF6oT9KCsceNTvvYMNHy0+kMF8akOjeDvPENWxp4= +github.com/aws/aws-sdk-go-v2/config v1.32.5 h1:pz3duhAfUgnxbtVhIK39PGF/AHYyrzGEyRD9Og0QrE8= +github.com/aws/aws-sdk-go-v2/config v1.32.5/go.mod h1:xmDjzSUs/d0BB7ClzYPAZMmgQdrodNjPPhd6bGASwoE= +github.com/aws/aws-sdk-go-v2/credentials v1.19.5 h1:xMo63RlqP3ZZydpJDMBsH9uJ10hgHYfQFIk1cHDXrR4= +github.com/aws/aws-sdk-go-v2/credentials v1.19.5/go.mod h1:hhbH6oRcou+LpXfA/0vPElh/e0M3aFeOblE1sssAAEk= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 h1:80+uETIWS1BqjnN9uJ0dBUaETh+P1XwFy5vwHwK5r9k= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16/go.mod h1:wOOsYuxYuB/7FlnVtzeBYRcjSRtQpAW0hCP7tIULMwo= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16 h1:rgGwPzb82iBYSvHMHXc8h9mRoOUBZIGFgKb9qniaZZc= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16/go.mod h1:L/UxsGeKpGoIj6DxfhOWHWQ/kGKcd4I1VncE4++IyKA= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16 h1:1jtGzuV7c82xnqOVfx2F0xmJcOw5374L7N6juGW6x6U= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16/go.mod h1:M2E5OQf+XLe+SZGmmpaI2yy+J326aFf6/+54PoxSANc= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc= +github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2 h1:U7ATBzpyD+A3IxzwKUL+meioIs3HO+/eyxghGTy6bkY= +github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2/go.mod h1:ESQxVIp7hs1MdsdEF4KITf65SfM3fh/EEiYi+s0S/pE= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 h1:0ryTNEdJbzUCEWkVXEXoqlXV72J5keC1GvILMOuD00E= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4/go.mod h1:HQ4qwNZh32C3CBeO6iJLQlgtMzqeG17ziAA/3KDJFow= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16 h1:oHjJHeUy0ImIV0bsrX0X91GkV5nJAyv1l1CC9lnO0TI= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16/go.mod h1:iRSNGgOYmiYwSCXxXaKb9HfOEj40+oTKn8pTxMlYkRM= +github.com/aws/aws-sdk-go-v2/service/ses v1.34.17 h1:XR7CtY988tck2Bhuy1JP4FsV8z0OAwjuh+gb7nAy8/M= +github.com/aws/aws-sdk-go-v2/service/ses v1.34.17/go.mod h1:2CspeTVldnJdRixX36SzTZuoIpjyKlfeXyB7/JB5KGk= +github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 h1:HpI7aMmJ+mm1wkSHIA2t5EaFFv5EFYXePW30p1EIrbQ= +github.com/aws/aws-sdk-go-v2/service/signin v1.0.4/go.mod h1:C5RdGMYGlfM0gYq/tifqgn4EbyX99V15P2V3R+VHbQU= +github.com/aws/aws-sdk-go-v2/service/sso v1.30.7 h1:eYnlt6QxnFINKzwxP5/Ucs1vkG7VT3Iezmvfgc2waUw= +github.com/aws/aws-sdk-go-v2/service/sso v1.30.7/go.mod h1:+fWt2UHSb4kS7Pu8y+BMBvJF0EWx+4H0hzNwtDNRTrg= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 h1:AHDr0DaHIAo8c9t1emrzAlVDFp+iMMKnPdYy6XO4MCE= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12/go.mod h1:GQ73XawFFiWxyWXMHWfhiomvP3tXtdNar/fi8z18sx0= +github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 h1:SciGFVNZ4mHdm7gpD1dgZYnCuVdX1s+lFTg4+4DOy70= +github.com/aws/aws-sdk-go-v2/service/sts v1.41.5/go.mod h1:iW40X4QBmUxdP+fZNOpfmkdMZqsovezbAeO+Ubiv2pk= +github.com/aws/smithy-go v1.24.0 h1:LpilSUItNPFr1eY85RYgTIg5eIEPtvFbskaFcmmIUnk= +github.com/aws/smithy-go v1.24.0/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0= github.com/bradleyfalzon/ghinstallation/v2 v2.17.0 h1:SmbUK/GxpAspRjSQbB6ARvH+ArzlNzTtHydNyXUQ6zg= github.com/bradleyfalzon/ghinstallation/v2 v2.17.0/go.mod h1:vuD/xvJT9Y+ZVZRv4HQ42cMyPFIYqpc7AbB4Gvt/DlY= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -61,10 +93,6 @@ github.com/hashicorp/go-retryablehttp v0.6.4 h1:BbgctKO892xEyOXnGiaAwIoSq1QZ/SS4 github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=