5
5
"net/http"
6
6
7
7
"github.com/dgrijalva/jwt-go"
8
+ "github.com/netlify/git-gateway/conf"
8
9
"github.com/netlify/git-gateway/models"
9
10
)
10
11
@@ -30,40 +31,41 @@ func (a *API) loadJWSSignatureHeader(w http.ResponseWriter, r *http.Request) (co
30
31
31
32
func (a * API ) loadInstanceConfig (w http.ResponseWriter , r * http.Request ) (context.Context , error ) {
32
33
ctx := r .Context ()
33
- config := getConfig (ctx )
34
-
35
34
signature := getSignature (ctx )
36
35
if signature == "" {
37
36
return nil , badRequestError ("Operator signature missing" )
38
37
}
39
38
39
+ var config * conf.Configuration
40
+ var instanceID string
41
+
40
42
claims := NetlifyMicroserviceClaims {}
41
43
p := jwt.Parser {ValidMethods : []string {jwt .SigningMethodHS256 .Name }}
42
44
_ , err := p .ParseWithClaims (signature , & claims , func (token * jwt.Token ) (interface {}, error ) {
43
- return []byte (config .JWT .Secret ), nil
44
- })
45
- if err != nil {
46
- return nil , badRequestError ("Operator microservice signature is invalid: %v" , err )
47
- }
45
+ instanceID = claims .InstanceID
46
+ if instanceID == "" {
47
+ return nil , badRequestError ("Instance ID is missing" )
48
+ }
48
49
49
- instanceID := claims .InstanceID
50
- if instanceID == "" {
51
- return nil , badRequestError ("Instance ID is missing" )
52
- }
50
+ logEntrySetField (r , "instance_id" , instanceID )
51
+ logEntrySetField (r , "netlify_id" , claims .NetlifyID )
52
+ instance , err := a .db .GetInstance (instanceID )
53
+ if err != nil {
54
+ if models .IsNotFoundError (err ) {
55
+ return nil , notFoundError ("Unable to locate site configuration" )
56
+ }
57
+ return nil , internalServerError ("Database error loading instance" ).WithInternalError (err )
58
+ }
53
59
54
- logEntrySetField (r , "instance_id" , instanceID )
55
- logEntrySetField (r , "netlify_id" , claims .NetlifyID )
56
- instance , err := a .db .GetInstance (instanceID )
57
- if err != nil {
58
- if models .IsNotFoundError (err ) {
59
- return nil , notFoundError ("Unable to locate site configuration" )
60
+ config , err = instance .Config ()
61
+ if err != nil {
62
+ return nil , internalServerError ("Error loading environment config" ).WithInternalError (err )
60
63
}
61
- return nil , internalServerError ("Database error loading instance" ).WithInternalError (err )
62
- }
63
64
64
- config , err := instance .Config ()
65
+ return []byte (config .JWT .Secret ), nil
66
+ })
65
67
if err != nil {
66
- return nil , internalServerError ( "Error loading environment config" ). WithInternalError ( err )
68
+ return nil , badRequestError ( "Operator microservice signature is invalid: %v" , err )
67
69
}
68
70
69
71
ctx = withNetlifyID (ctx , claims .NetlifyID )
0 commit comments