/
servicebody.go
155 lines (139 loc) · 5.24 KB
/
servicebody.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package apic
import (
management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
"github.com/Axway/agent-sdk/pkg/apic/provisioning"
)
// APIKeyInfo -
type APIKeyInfo struct {
Name string
Location string
}
// ServiceBody - details about a service to create
type ServiceBody struct {
NameToPush string
APIName string
RestAPIID string
PrimaryKey string
URL string
Stage string
StageDescriptor string
StageDisplayName string
Description string
Version string
AuthPolicy string
authPolicies []string
apiKeyInfo []APIKeyInfo
scopes map[string]string
SpecDefinition []byte
Documentation []byte
Tags map[string]interface{}
Image string
ImageContentType string
CreatedBy string
ResourceContentType string
ResourceType string
SubscriptionName string
APIUpdateSeverity string
State string
Status string
ServiceAttributes map[string]string
RevisionAttributes map[string]string
InstanceAttributes map[string]string
ServiceAgentDetails map[string]interface{}
InstanceAgentDetails map[string]interface{}
RevisionAgentDetails map[string]interface{}
serviceContext serviceContext
Endpoints []EndpointDefinition
UnstructuredProps *UnstructuredProperties
TeamName string
teamID string
categoryTitles []string //Titles will be set via the service body builder
categoryNames []string //Names will be determined based the Title
credentialRequestPolicies []string
ardName string
uniqueARD bool
specHash string
specVersion string
accessRequestDefinition *management.AccessRequestDefinition
specHashes map[string]interface{} // map of hash values to revision names
requestDefinitionsAllowed bool // used to validate if the instance can have request definitions or not. Use case example - v7 unpublished, remove request definitions
dataplaneType DataplaneType
isDesignDataplane bool
referencedServiceName string
referencedInstanceName string
}
// SetAccessRequestDefinitionName - set the name of the access request definition for this service body
func (s *ServiceBody) SetAccessRequestDefinitionName(ardName string, isUnique bool) {
s.ardName = ardName
s.uniqueARD = isUnique
}
// GetAuthPolicies - returns the array of all auth policies in the ServiceBody
func (s *ServiceBody) GetAuthPolicies() []string {
return s.authPolicies
}
// GetAPIKeyInfo - returns the array of locations and argument names for the api key
func (s *ServiceBody) GetAPIKeyInfo() []APIKeyInfo {
return s.apiKeyInfo
}
// GetScopes - returns the array of scopes for this service instance
func (s *ServiceBody) GetScopes() map[string]string {
return s.scopes
}
// GetCredentialRequestDefinitions - returns the array of all credential request policies
func (s *ServiceBody) GetCredentialRequestDefinitions() []string {
if len(s.credentialRequestPolicies) > 0 {
return s.credentialRequestPolicies
}
for _, policy := range s.authPolicies {
if policy == Basic {
s.credentialRequestPolicies = append(s.credentialRequestPolicies, provisioning.BasicAuthCRD)
}
if policy == Apikey {
s.credentialRequestPolicies = append(s.credentialRequestPolicies, provisioning.APIKeyCRD)
}
if policy == Oauth {
s.credentialRequestPolicies = append(s.credentialRequestPolicies, []string{provisioning.OAuthPublicKeyCRD, provisioning.OAuthSecretCRD}...)
}
}
return s.credentialRequestPolicies
}
func (s *ServiceBody) setAccessRequestDefinition(accessRequestDefinition *management.AccessRequestDefinition) (*management.AccessRequestDefinition, error) {
s.accessRequestDefinition = accessRequestDefinition
return s.accessRequestDefinition, nil
}
// GetAccessRequestDefinition -
func (s *ServiceBody) GetAccessRequestDefinition() *management.AccessRequestDefinition {
return s.accessRequestDefinition
}
func (s *ServiceBody) createAccessRequestDefinition() error {
oauthScopes := make([]string, 0)
for scope := range s.GetScopes() {
oauthScopes = append(oauthScopes, scope)
}
if len(oauthScopes) > 0 {
// sort the strings for consistent specs
_, err := provisioning.NewAccessRequestBuilder(s.setAccessRequestDefinition).Register()
if err != nil {
return err
}
}
return nil
}
// GetSpecVersion - returns version parsed from the spec
func (s *ServiceBody) GetSpecVersion() string {
return s.specVersion
}
// GetDataplaneType - returns dataplane type
func (s *ServiceBody) GetDataplaneType() DataplaneType {
return s.dataplaneType
}
// IsDesignDataplane - returns true for design dataplane
func (s *ServiceBody) IsDesignDataplane() bool {
return s.isDesignDataplane
}
func (s *ServiceBody) GetReferencedServiceName() string {
return s.referencedServiceName
}
func (s *ServiceBody) GetReferenceInstanceName() string {
return s.referencedInstanceName
}