forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credentials.go
40 lines (30 loc) · 1001 Bytes
/
credentials.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package handler
import (
"encoding/json"
"fmt"
"net/http"
log "github.com/sirupsen/logrus"
"github.com/rymurr/aws-lambda-runtime-interface-emulator/lambda/core"
)
type credentialsHandler struct {
credentialsService core.CredentialsService
}
func (h *credentialsHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
token := request.Header.Get("Authorization")
credentials, err := h.credentialsService.GetCredentials(token)
if err != nil {
errorMsg := "cannot get credentials for the provided token"
log.WithError(err).Error(errorMsg)
http.Error(writer, errorMsg, http.StatusNotFound)
return
}
jsonResponse, _ := json.Marshal(*credentials)
fmt.Fprint(writer, string(jsonResponse))
}
func NewCredentialsHandler(credentialsService core.CredentialsService) http.Handler {
return &credentialsHandler{
credentialsService: credentialsService,
}
}