forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.go
35 lines (27 loc) · 1014 Bytes
/
runtime.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
package requestinfo
import (
"context"
"github.com/piotrostr/atlas-app-toolkit/v2/gateway"
)
func FromContext(ctx context.Context) (RequestInfo, error) {
info := RequestInfo{}
var found bool
if info.Identifier.ApplicationName, found = gateway.Header(ctx, appNameMetaKey); !found {
return RequestInfo{}, ErrAppNameIsMissing
}
if info.Identifier.ResourceType, found = gateway.Header(ctx, resourceTypeMetaKey); !found {
return RequestInfo{}, ErrResourceTypeIsMissing
}
if info.Identifier.ResourceId, found = gateway.Header(ctx, resourceIdMetaKey); !found {
//In some cases ResourceId can be empty(ListOperation, CreateOperation)
}
//If we don't have operation Name in metadata or don't have such operation will set UnknownOperation type
var op string
if op, found = gateway.Header(ctx, operationTypeMetaKey); !found {
info.OperationType = UnknownOperation
}
if info.OperationType, found = operationNameToType[op]; !found {
info.OperationType = UnknownOperation
}
return info, nil
}