-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrequest.go
102 lines (85 loc) · 3.41 KB
/
request.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package kmip
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import (
"time"
"github.com/pkg/errors"
)
// Request is a Request Message Structure
type Request struct {
Tag `kmip:"REQUEST_MESSAGE"`
Header RequestHeader `kmip:"REQUEST_HEADER,required"`
BatchItems []RequestBatchItem `kmip:"REQUEST_BATCH_ITEM,required"`
}
// RequestHeader is a Request Header Structure
type RequestHeader struct {
Tag `kmip:"REQUEST_HEADER"`
Version ProtocolVersion `kmip:"PROTOCOL_VERSION,required"`
MaxResponseSize int32 `kmip:"MAXIMUM_RESPONSE_SIZE"`
ClientCorrelationValue string `kmip:"CLIENT_CORRELATION_VALUE"`
ServerCorrelationValue string `kmip:"SERVER_CORRELATION_VALUE"`
AsynchronousIndicator bool `kmip:"ASYNCHRONOUS_INDICATOR"`
AttestationCapableIndicator bool `kmip:"ATTESTATION_CAPABLE_INDICATOR"`
AttestationType []Enum `kmip:"ATTESTATION_TYPE"`
Authentication Authentication `kmip:"AUTHENTICATION"`
BatchErrorContinuationOption Enum `kmip:"BATCH_ERROR_CONTINUATION_OPTION"`
BatchOrderOption bool `kmip:"BATCH_ORDER_OPTION"`
TimeStamp time.Time `kmip:"TIME_STAMP"`
BatchCount int32 `kmip:"BATCH_COUNT,required"`
}
// RequestBatchItem is a Request Batch Item Structure
type RequestBatchItem struct {
Tag `kmip:"REQUEST_BATCH_ITEM"`
Operation Enum `kmip:"OPERATION,required"`
UniqueID []byte `kmip:"UNIQUE_BATCH_ITEM_ID"`
RequestPayload interface{} `kmip:"REQUEST_PAYLOAD,required"`
MessageExtension MessageExtension `kmip:"MESSAGE_EXTENSION"`
}
// BuildFieldValue builds value for RequestPayload based on Operation
func (bi *RequestBatchItem) BuildFieldValue(name string) (v interface{}, err error) {
switch bi.Operation {
case OPERATION_CREATE:
v = &CreateRequest{}
case OPERATION_GET:
v = &GetRequest{}
case OPERATION_GET_ATTRIBUTES:
v = &GetAttributesRequest{}
case OPERATION_GET_ATTRIBUTE_LIST:
v = &GetAttributeListRequest{}
case OPERATION_DESTROY:
v = &DestroyRequest{}
case OPERATION_DISCOVER_VERSIONS:
v = &DiscoverVersionsRequest{}
case OPERATION_REGISTER:
v = &RegisterRequest{}
case OPERATION_ACTIVATE:
v = &ActivateRequest{}
case OPERATION_LOCATE:
v = &LocateRequest{}
case OPERATION_REVOKE:
v = &RevokeRequest{}
default:
err = errors.Errorf("unsupported operation: %v", bi.Operation)
}
return
}
// ProtocolVersion is a Protocol Version structure
type ProtocolVersion struct {
Tag `kmip:"PROTOCOL_VERSION"`
Major int32 `kmip:"PROTOCOL_VERSION_MAJOR"`
Minor int32 `kmip:"PROTOCOL_VERSION_MINOR"`
}
// MessageExtension is a Message Extension structure in a Batch Item
type MessageExtension struct {
Tag `kmip:"MESSAGE_EXTENSION"`
VendorIdentification string `kmip:"VENDOR_IDENTIFICATION,required"`
CriticalityIndicator bool `kmip:"CRITICALITY_INDICATOR,required"`
VendorExtension interface{} `kmip:"-,skip"`
}
// RevocationReason is a Revocation Reason structure
type RevocationReason struct {
Tag `kmip:"REVOCATION_REASON"`
RevocationReasonCode Enum `kmip:"REVOCATION_REASON_CODE"`
RevocationMessage string `kmip:"REVOCATION_REASON"`
}