Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda_trigger: Remove deprecations #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions util/lambda_trigger/lambda_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
"regexp"
Expand Down Expand Up @@ -95,7 +96,7 @@ func getBrewVersion(product string, brewType string) (string, error) {
// This formula|cask may be new. We'll assume so.
return "", errBrewVersionNotFound
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand All @@ -113,7 +114,7 @@ func triggerGithubWorkflow(event *ReleaseEvent) error {
// Create dispatch event https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event
workflowEndpoint := "https://api.github.com/repos/hashicorp/homebrew-tap/dispatches"
postBody := fmt.Sprintf("{\"event_type\": \"version-updated\", \"client_payload\":{\"name\":\"%s\",\"version\":\"%s\",\"cask\":\"%t\"}}", event.Product, event.Version, event.Cask)
fmt.Printf("POSTing to Github: %s\n", postBody)
log.Printf("POSTing to Github: %s", postBody)

httpClient := &http.Client{}
req, err := http.NewRequest("POST", workflowEndpoint, bytes.NewBufferString(postBody))
Expand All @@ -127,16 +128,16 @@ func triggerGithubWorkflow(event *ReleaseEvent) error {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Printf("Github Response: %+v", body)
body, err := io.ReadAll(resp.Body)
log.Printf("Github Response: %+v", body)
return err
}

// HandleLambdaEvent handler function to trigger github workflow
func HandleLambdaEvent(snsEvent events.SNSEvent) error {
for _, record := range snsEvent.Records {
snsRecord := record.SNS
fmt.Printf("[%s %s] Message = %s \n", record.EventSource, snsRecord.Timestamp, snsRecord.Message)
log.Printf("[%s %s] Message = %s", record.EventSource, snsRecord.Timestamp, snsRecord.Message)
message := record.SNS.Message

// Parse message to ReleaseEvent type
Expand All @@ -151,7 +152,7 @@ func HandleLambdaEvent(snsEvent events.SNSEvent) error {
if err != nil || version == nil {
return err
}
fmt.Printf("Latest version is %s\n", *version)
log.Printf("Latest version is %s", *version)
event.Version = *version
oldVersion := ""
event.Cask = isCask(event.Product)
Expand All @@ -169,9 +170,9 @@ func HandleLambdaEvent(snsEvent events.SNSEvent) error {
}

if oldVersion != "" {
fmt.Printf("Current formula/cask version is %s\n", oldVersion)
log.Printf("Current formula/cask version is %s", oldVersion)
} else {
fmt.Printf("No previous version found, assuming new formula/cask\n")
log.Printf("No previous version found, assuming new formula/cask")
}

if event.Version == oldVersion {
Expand Down