Skip to content

Commit

Permalink
Require API key
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarsti committed Sep 11, 2024
1 parent c64999c commit 1137055
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions cmd/lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,25 @@ func HandleRequest(req events.APIGatewayProxyRequest) (*events.APIGatewayProxyRe
return errorResponse(fmt.Errorf("unable to convert base64 to bytes: %w", err)), nil
}

// TODO: Re-enable requiring API key
// apiKey, err := getAPIKey(decodedBodyBytes, reqHeaders["content-type"], reqHeaders["api-key"])
// if err != nil {
// return errorResponse(fmt.Errorf("error getting api key: %w", err)), nil
// }
// // check if apiKey is valid
// log.Printf("api-key was: '%s'", apiKey)
// if apiKey == "" {
// err := fmt.Errorf("no api-key was provided")
// return errorResponse(err), nil
// }
// valid, err := dynamodb.VerifyAPIKey(apiKey)
// if err != nil {
// err := fmt.Errorf("verify api key: %w", err)
// return errorResponse(err), nil
// }
// if !valid {
// err := fmt.Errorf("API key '%s' is invalid, please email [email protected] to get a free api key", apiKey)
// return errorResponse(err), nil
// }
apiKey, err := getAPIKey(decodedBodyBytes, reqHeaders["content-type"], reqHeaders["api-key"])
if err != nil {
return errorResponse(fmt.Errorf("error getting api key: %w", err)), nil
}
// check if apiKey is valid
log.Printf("api-key was: '%s'", apiKey)
if apiKey == "" {
err := fmt.Errorf("no api-key was provided")
return errorResponse(err), nil
}
valid, err := dynamodb.VerifyAPIKey(apiKey)
if err != nil {
err := fmt.Errorf("verify api key: %w", err)
return errorResponse(err), nil
}
if !valid {
err := fmt.Errorf("API key '%s' is invalid, please email [email protected] to buy an api key", apiKey)
return errorResponse(err), nil
}

file, err := getFile(decodedBodyBytes, reqHeaders["content-type"])
if err != nil {
Expand Down

0 comments on commit 1137055

Please sign in to comment.