Skip to content

Commit 46b9a1e

Browse files
when strip servers is set calculate the hash with and without servers, when both change publish without servers
1 parent c7ab7bc commit 46b9a1e

5 files changed

Lines changed: 84 additions & 53 deletions

File tree

pkg/apic/servicebody.go

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,62 @@ type APIKeyInfo struct {
1414

1515
// ServiceBody - details about a service to create
1616
type ServiceBody struct {
17-
NameToPush string
18-
APIName string
19-
RestAPIID string
20-
PrimaryKey string
21-
URL string
22-
Stage string
23-
StageDescriptor string
24-
StageDisplayName string
25-
Description string
26-
Version string
27-
AuthPolicy string
28-
authPolicies []string
29-
apiKeyInfo []APIKeyInfo
30-
scopes map[string]string
31-
SpecDefinition []byte
32-
Documentation []byte
33-
Tags map[string]interface{}
34-
Image string
35-
ImageContentType string
36-
CreatedBy string
37-
ResourceContentType string
38-
ResourceType string
39-
SubscriptionName string
40-
APIUpdateSeverity string
41-
State string
42-
Status string
43-
ServiceAttributes map[string]string
44-
RevisionAttributes map[string]string
45-
InstanceAttributes map[string]string
46-
ServiceAgentDetails map[string]interface{}
47-
InstanceAgentDetails map[string]interface{}
48-
RevisionAgentDetails map[string]interface{}
49-
serviceContext serviceContext
50-
Endpoints []EndpointDefinition
51-
UnstructuredProps *UnstructuredProperties
52-
TeamName string
53-
teamID string
54-
credentialRequestPolicies []string
55-
ardName string
56-
uniqueARD bool
57-
ignoreSpecBasesCreds bool
58-
stripOASExtensions bool
59-
specHash string
60-
specVersion string
61-
accessRequestDefinition *management.AccessRequestDefinition
62-
specHashes map[string]interface{} // map of hash values to revision names
63-
requestDefinitionsAllowed bool // used to validate if the instance can have request definitions or not. Use case example - v7 unpublished, remove request definitions
64-
dataplaneType DataplaneType
65-
isDesignDataplane bool
66-
referencedServiceName string
67-
referencedInstanceName string
68-
logger log.FieldLogger
69-
instanceLifecycle *management.ApiServiceInstanceLifecycle
17+
NameToPush string
18+
APIName string
19+
RestAPIID string
20+
PrimaryKey string
21+
URL string
22+
Stage string
23+
StageDescriptor string
24+
StageDisplayName string
25+
Description string
26+
Version string
27+
AuthPolicy string
28+
authPolicies []string
29+
apiKeyInfo []APIKeyInfo
30+
scopes map[string]string
31+
SpecDefinition []byte
32+
Documentation []byte
33+
Tags map[string]interface{}
34+
Image string
35+
ImageContentType string
36+
CreatedBy string
37+
ResourceContentType string
38+
ResourceType string
39+
SubscriptionName string
40+
APIUpdateSeverity string
41+
State string
42+
Status string
43+
ServiceAttributes map[string]string
44+
RevisionAttributes map[string]string
45+
InstanceAttributes map[string]string
46+
ServiceAgentDetails map[string]interface{}
47+
InstanceAgentDetails map[string]interface{}
48+
RevisionAgentDetails map[string]interface{}
49+
serviceContext serviceContext
50+
Endpoints []EndpointDefinition
51+
UnstructuredProps *UnstructuredProperties
52+
TeamName string
53+
teamID string
54+
credentialRequestPolicies []string
55+
ardName string
56+
uniqueARD bool
57+
ignoreSpecBasesCreds bool
58+
stripOASExtensions bool
59+
stripOASServersBeforePublish bool
60+
specHash string
61+
specVersion string
62+
accessRequestDefinition *management.AccessRequestDefinition
63+
specHashes map[string]interface{} // map of hash values to revision names
64+
requestDefinitionsAllowed bool // used to validate if the instance can have request definitions or not. Use case example - v7 unpublished, remove request definitions
65+
dataplaneType DataplaneType
66+
isDesignDataplane bool
67+
referencedServiceName string
68+
referencedInstanceName string
69+
logger log.FieldLogger
70+
instanceLifecycle *management.ApiServiceInstanceLifecycle
71+
originalSpecDefinition []byte
72+
originalSpecHash string
7073
}
7174

7275
// SetAccessRequestDefinitionName - set the name of the access request definition for this service body

pkg/apic/servicebuilder.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type ServiceBuilder interface {
5656
SetAccessRequestDefinitionName(accessRequestDefName string, isUnique bool) ServiceBuilder
5757
SetIgnoreSpecBasedCreds(ignore bool) ServiceBuilder
5858
SetStripOASExtensions(strip bool) ServiceBuilder
59+
SetStripOASServersBeforePublish() ServiceBuilder
5960

6061
SetUnstructuredType(assetType string) ServiceBuilder
6162
SetUnstructuredContentType(contentType string) ServiceBuilder
@@ -379,6 +380,15 @@ func (b *serviceBodyBuilder) Build() (ServiceBody, error) {
379380
val.StripExtensions()
380381
}
381382

383+
if b.serviceBody.stripOASServersBeforePublish {
384+
b.serviceBody.originalSpecDefinition = b.serviceBody.SpecDefinition
385+
b.serviceBody.originalSpecHash = b.serviceBody.specHash
386+
val.stripEndpoints()
387+
b.serviceBody.SpecDefinition = val.GetSpecBytes()
388+
newHash, _ := util.ComputeHash(val.GetSpecBytes())
389+
b.serviceBody.specHash = fmt.Sprintf("%v", newHash)
390+
}
391+
382392
// only set ard name based on spec if not already set, use first auth we find
383393
if b.serviceBody.ardName != "" {
384394
return b.serviceBody, nil
@@ -426,6 +436,11 @@ func (b *serviceBodyBuilder) SetIgnoreSpecBasedCreds(ignore bool) ServiceBuilder
426436
return b
427437
}
428438

439+
func (b *serviceBodyBuilder) SetStripOASServersBeforePublish() ServiceBuilder {
440+
b.serviceBody.stripOASServersBeforePublish = true
441+
return b
442+
}
443+
429444
func (b *serviceBodyBuilder) SetStripOASExtensions(strip bool) ServiceBuilder {
430445
b.serviceBody.stripOASExtensions = strip
431446
return b

pkg/apic/specoas2processor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func (p *oas2SpecProcessor) GetEndpoints() ([]EndpointDefinition, error) {
7878
return endPoints, nil
7979
}
8080

81+
func (p *oas2SpecProcessor) stripEndpoints() {
82+
// strip the endpoints from the spec, these will be added based on the API Service EndpointDefinitions
83+
p.spec.BasePath = ""
84+
p.spec.Host = ""
85+
p.spec.Schemes = []string{}
86+
}
87+
8188
func (p *oas2SpecProcessor) ParseAuthInfo() {
8289
authPolicies := []string{}
8390
keyInfo := []APIKeyInfo{}

pkg/apic/specoas3processor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ func (p *oas3SpecProcessor) StripExtensions() {
280280
}
281281
}
282282

283+
func (p *oas3SpecProcessor) stripEndpoints() {
284+
// strip the endpoints from the spec, these will be added based on the API Service EndpointDefinitions
285+
p.spec.Servers = []*openapi3.Server{}
286+
}
287+
283288
func (p *oas3SpecProcessor) GetSpecBytes() []byte {
284289
s, _ := json.Marshal(p.spec)
285290
return s

pkg/apic/specparser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type OasSpecProcessor interface {
5757
GetSpecBytes() []byte
5858
GetResourceType() string
5959
GetVersion() string
60+
stripEndpoints()
6061
}
6162

6263
// SpecResourceParser -

0 commit comments

Comments
 (0)