Skip to content

Commit 7e289ba

Browse files
Merge pull request #877 from wasuradananjith/master
Bumping the REST API versions and update the license text
2 parents 912d329 + e5098fa commit 7e289ba

14 files changed

+124
-45
lines changed

import-export-cli/LICENSE.txt

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ github.com/pavel-v-chernykh/keystore-go/v4
3939

4040
github.com/renstrom/dedent MIT
4141

42+
github.com/savaki/jq Apache-2.0
43+
4244
github.com/spf13/cast MIT
4345

4446
github.com/spf13/cobra Apache-2.0

import-export-cli/impl/getKeys.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func subscribe(appId string, accessToken string) (string, error) {
404404
// @param accessToken : Access token to call the REST API
405405
// @return API, error
406406
func getApiOrProduct(apiId string, accessToken string) (*utils.APIData, error) {
407-
// Since apis/{api-id} supports retrieving details of both APIs and API Products, we can use it here.
407+
// First check whether this is an API
408408
apiEndpoint := utils.GetApiListEndpointOfEnv(keyGenEnv, utils.MainConfigFilePath) + "/" + apiId
409409
headers := make(map[string]string)
410410
headers[utils.HeaderAuthorization] = utils.HeaderValueAuthBearerPrefix + " " + accessToken
@@ -416,13 +416,26 @@ func getApiOrProduct(apiId string, accessToken string) (*utils.APIData, error) {
416416
err = json.Unmarshal(data, &apiData)
417417
return apiData, err
418418
} else {
419-
utils.Logf("Error: %s\n", resp.Error())
420-
utils.Logf("Body: %s\n", resp.Body())
421-
if resp.StatusCode() == http.StatusUnauthorized {
422-
// 401 Unauthorized
423-
return nil, fmt.Errorf("authorization failed while trying to retrieve the details of API or API Prodcut: " + apiId)
419+
// Second check whether this is an API Product
420+
apiProductEndpoint := utils.GetApiProductListEndpointOfEnv(keyGenEnv, utils.MainConfigFilePath) + "/" + apiId
421+
headers := make(map[string]string)
422+
headers[utils.HeaderAuthorization] = utils.HeaderValueAuthBearerPrefix + " " + accessToken
423+
resp, err := utils.InvokeGETRequest(apiProductEndpoint, headers)
424+
if resp.StatusCode() == http.StatusOK || resp.StatusCode() == http.StatusCreated {
425+
// 200 OK or 201 Created
426+
apiData := &utils.APIData{}
427+
data := []byte(resp.Body())
428+
err = json.Unmarshal(data, &apiData)
429+
return apiData, err
430+
} else {
431+
utils.Logf("Error: %s\n", resp.Error())
432+
utils.Logf("Body: %s\n", resp.Body())
433+
if resp.StatusCode() == http.StatusUnauthorized {
434+
// 401 Unauthorized
435+
return nil, fmt.Errorf("authorization failed while trying to retrieve the details of API or API Prodcut: " + apiId)
436+
}
437+
return nil, errors.New("Request didn't respond 200 OK for retrieving API or API Product details. Status: " + resp.Status())
424438
}
425-
return nil, errors.New("Request didn't respond 200 OK for retrieving API or API Product details. Status: " + resp.Status())
426439
}
427440
}
428441

import-export-cli/integration/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ indexing-delay: 1000
3737

3838
- *APIM DCR/REST API versions*
3939

40-
The DCR and REST API version of the APIM instances mentioned previously.
40+
The DCR and REST API versions (Admin, Devportal and Publisher) of the APIM instances mentioned previously.
4141

4242
```
4343
dcr-version: v0.17
44-
rest-api-version: v2
44+
admin-rest-api-version: v3
45+
devportal-rest-api-version: v2
46+
publisher-rest-api-version: v3
47+
devops-rest-api-version: v0
4548
```
4649

4750
- *apictl version*

import-export-cli/integration/apiProduct_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ func TestDeleteApiProductWithActiveSubscriptionsSuperTenantUser(t *testing.T) {
11971197
base.WaitForIndexing()
11981198

11991199
//Get keys for ApiProduct and keep subscription active
1200-
testutils.ValidateGetKeysWithoutCleanup(t, args, true)
1200+
testutils.ValidateGetKeysWithoutCleanup(t, args, false)
12011201

12021202
argsToDelete := &testutils.ApiProductImportExportTestArgs{
12031203
CtlUser: testutils.Credentials{Username: adminUsername, Password: adminPassword},

import-export-cli/integration/apim/apiDTO.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,20 @@ type RoleBindings struct {
231231

232232
// APIOperations : API Operations definition
233233
type APIOperations struct {
234-
ID string `json:"id"`
235-
Target string `json:"target"`
236-
Verb string `json:"verb"`
237-
AuthType string `json:"authType,omitempty"`
238-
ThrottlingPolicy string `json:"throttlingPolicy,omitempty"`
239-
Scopes []string `json:"scopes,omitempty"`
240-
UsedProductIds []string `json:"usedProductIds,omitempty"`
234+
ID string `json:"id" yaml:"id"`
235+
Target string `json:"target" yaml:"target"`
236+
Verb string `json:"verb" yaml:"verb"`
237+
AuthType string `json:"authType,omitempty" yaml:"authType,omitempty"`
238+
ThrottlingPolicy string `json:"throttlingPolicy,omitempty" yaml:"throttlingPolicy,omitempty"`
239+
Scopes []string `json:"scopes,omitempty" yaml:"scopes,omitempty"`
240+
UsedProductIds []string `json:"usedProductIds,omitempty" yaml:"usedProductIds,omitempty"`
241+
OperationPolicies OperationPolicies `json:"operationPolicies,omitempty" yaml:"operationPolicies,omitempty"`
242+
}
243+
244+
type OperationPolicies struct {
245+
Request interface{} `json:"request" yaml:"request"`
246+
Response interface{} `json:"response" yaml:"response"`
247+
Fault interface{} `json:"fault" yaml:"fault"`
241248
}
242249

243250
// AdvertiseInfo : Advertise only information

import-export-cli/integration/apim/apim.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ func (instance *Client) Login(username string, password string) {
110110
}
111111

112112
// Setup : Setup APIM Client config
113-
func (instance *Client) Setup(envName string, host string, offset int, dcrVersion, restAPIVersion, devopsRestAPIVersion string) {
113+
func (instance *Client) Setup(envName string, host string, offset int, dcrVersion, adminRestAPIVersion,
114+
devportalRestAPIVersion, publisherRestAPIVersion, devopsRestAPIVersion string) {
114115
base.Log("apim.Setup() - envName:", envName, ",host:", host, ",offset:", offset, ",dcrVersion:", dcrVersion,
115-
",restAPIVersion:", restAPIVersion)
116+
",adminRestAPIVersion:", adminRestAPIVersion, ",devportalRestAPIVersion:", devportalRestAPIVersion,
117+
",publisherRestAPIVersion:", publisherRestAPIVersion)
116118
instance.apimURL = getApimURL(host, offset)
117119
instance.dcrURL = getDCRURL(host, dcrVersion, offset)
118-
instance.devPortalRestURL = getDevPortalRestURL(host, restAPIVersion, offset)
119-
instance.publisherRestURL = getPublisherRestURL(host, restAPIVersion, offset)
120-
instance.adminRestURL = getAdminRestURL(host, restAPIVersion, offset)
120+
instance.devPortalRestURL = getDevPortalRestURL(host, devportalRestAPIVersion, offset)
121+
instance.publisherRestURL = getPublisherRestURL(host, publisherRestAPIVersion, offset)
122+
instance.adminRestURL = getAdminRestURL(host, adminRestAPIVersion, offset)
121123
instance.devopsRestURL = getDevOpsRestURL(host, devopsRestAPIVersion, offset)
122124
instance.portOffset = offset
123125
instance.tokenURL = getTokenURL(host, offset)
@@ -1903,35 +1905,41 @@ func (instance *Client) SetAPILogLevel(username, password, tenantDomain, apiId,
19031905
}
19041906

19051907
func generateSampleAPIOperations() []APIOperations {
1908+
19061909
op1 := APIOperations{}
19071910
op1.Target = "/order/{orderId}"
19081911
op1.Verb = "GET"
19091912
op1.ThrottlingPolicy = "Unlimited"
19101913
op1.AuthType = "Application & Application User"
1914+
op1.OperationPolicies = OperationPolicies{[]string{}, []string{}, []string{}}
19111915

19121916
op2 := APIOperations{}
19131917
op2.Target = "/order/{orderId}"
19141918
op2.Verb = "DELETE"
19151919
op2.ThrottlingPolicy = "Unlimited"
19161920
op2.AuthType = "Application & Application User"
1921+
op2.OperationPolicies = OperationPolicies{[]string{}, []string{}, []string{}}
19171922

19181923
op3 := APIOperations{}
19191924
op3.Target = "/order/{orderId}"
19201925
op3.Verb = "PUT"
19211926
op3.ThrottlingPolicy = "Unlimited"
19221927
op3.AuthType = "Application & Application User"
1928+
op3.OperationPolicies = OperationPolicies{[]string{}, []string{}, []string{}}
19231929

19241930
op4 := APIOperations{}
19251931
op4.Target = "/menu"
19261932
op4.Verb = "GET"
19271933
op4.ThrottlingPolicy = "Unlimited"
19281934
op4.AuthType = "Application & Application User"
1935+
op4.OperationPolicies = OperationPolicies{[]string{}, []string{}, []string{}}
19291936

19301937
op5 := APIOperations{}
19311938
op5.Target = "/order"
19321939
op5.Verb = "POST"
19331940
op5.ThrottlingPolicy = "Unlimited"
19341941
op5.AuthType = "Application & Application User"
1942+
op5.OperationPolicies = OperationPolicies{[]string{}, []string{}, []string{}}
19351943

19361944
return []APIOperations{op1, op2, op3, op4, op5}
19371945
}

import-export-cli/integration/config.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ indexing-delay: 1000
1515
max-invocation-attempts: 10
1616

1717
dcr-version: v0.17
18-
rest-api-version: v2
19-
devops-rest-api-version: v1
18+
admin-rest-api-version: v3
19+
devportal-rest-api-version: v2
20+
publisher-rest-api-version: v3
21+
devops-rest-api-version: v0
2022
apictl-version: 4.1.0
2123

import-export-cli/integration/integration_test.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ import (
3333
)
3434

3535
type YamlConfig struct {
36-
Environments []Environment `yaml:"environments"`
37-
IndexingDelay int `yaml:"indexing-delay"`
38-
MaxInvocationAttempts int `yaml:"max-invocation-attempts"`
39-
DCRVersion string `yaml:"dcr-version"`
40-
RESTAPIVersion string `yaml:"rest-api-version"`
41-
DevOpsRESTAPIVersion string `yaml:"devops-rest-api-version"`
42-
APICTLVersion string `yaml:"apictl-version"`
36+
Environments []Environment `yaml:"environments"`
37+
IndexingDelay int `yaml:"indexing-delay"`
38+
MaxInvocationAttempts int `yaml:"max-invocation-attempts"`
39+
DCRVersion string `yaml:"dcr-version"`
40+
AdminRESTAPIVersion string `yaml:"admin-rest-api-version"`
41+
DevportalRESTAPIVersion string `yaml:"devportal-rest-api-version"`
42+
PublisherRESTAPIVersion string `yaml:"publisher-rest-api-version"`
43+
DevOpsRESTAPIVersion string `yaml:"devops-rest-api-version"`
44+
APICTLVersion string `yaml:"apictl-version"`
4345
}
4446

4547
type Environment struct {
@@ -136,7 +138,8 @@ func TestMain(m *testing.M) {
136138

137139
for _, env := range envs {
138140
client := apim.Client{}
139-
client.Setup(env.Name, env.Host, env.Offset, yamlConfig.DCRVersion, yamlConfig.RESTAPIVersion, yamlConfig.DevOpsRESTAPIVersion)
141+
client.Setup(env.Name, env.Host, env.Offset, yamlConfig.DCRVersion, yamlConfig.AdminRESTAPIVersion,
142+
yamlConfig.DevportalRESTAPIVersion, yamlConfig.PublisherRESTAPIVersion, yamlConfig.DevOpsRESTAPIVersion)
140143
apimClients[env.Name] = &client
141144
}
142145

@@ -179,7 +182,9 @@ func readConfigs() {
179182
base.Log("indexing delay:", yamlConfig.IndexingDelay)
180183
base.Log("max invocation attempts", yamlConfig.MaxInvocationAttempts)
181184
base.Log("dcr version:", yamlConfig.DCRVersion)
182-
base.Log("rest api Version:", yamlConfig.RESTAPIVersion)
185+
base.Log("admin rest api Version:", yamlConfig.AdminRESTAPIVersion)
186+
base.Log("devportal rest api Version:", yamlConfig.DevportalRESTAPIVersion)
187+
base.Log("publisher rest api Version:", yamlConfig.PublisherRESTAPIVersion)
183188
base.Log("apictl version:", yamlConfig.APICTLVersion)
184189

185190
if len(envs) != 2 {

import-export-cli/integration/testdata/sample-api.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ data: # Contains the meta data of the API
8282
- Content-Type
8383
- SOAPAction
8484
- apikey
85-
- testKey
85+
- Internal-Key
8686
accessControlAllowMethods: # Allowed methods as a list
8787
- GET
8888
- PUT
@@ -119,6 +119,10 @@ data: # Contains the meta data of the API
119119
throttlingPolicy: Unlimited
120120
scopes: []
121121
usedProductIds: []
122+
operationPolicies:
123+
request: []
124+
response: []
125+
fault: []
122126
-
123127
id: ""
124128
target: /menu
@@ -127,6 +131,10 @@ data: # Contains the meta data of the API
127131
throttlingPolicy: Unlimited
128132
scopes: []
129133
usedProductIds: []
134+
operationPolicies:
135+
request: []
136+
response: []
137+
fault: []
130138
-
131139
id: ""
132140
target: /order/{orderId}
@@ -135,6 +143,10 @@ data: # Contains the meta data of the API
135143
throttlingPolicy: Unlimited
136144
scopes: []
137145
usedProductIds: []
146+
operationPolicies:
147+
request: []
148+
response: []
149+
fault: []
138150
-
139151
id: ""
140152
target: /order/{orderId}
@@ -143,6 +155,10 @@ data: # Contains the meta data of the API
143155
throttlingPolicy: Unlimited
144156
scopes: []
145157
usedProductIds: []
158+
operationPolicies:
159+
request: []
160+
response: []
161+
fault: []
146162
-
147163
id: ""
148164
target: /order/{orderId}
@@ -151,6 +167,10 @@ data: # Contains the meta data of the API
151167
throttlingPolicy: Unlimited
152168
scopes: []
153169
usedProductIds: []
170+
operationPolicies:
171+
request: []
172+
response: []
173+
fault: []
154174
categories: [] # List of API Categories that the API belongs to
155175
keyManagers: # List of key manager endpoints
156176
- all

import-export-cli/integration/testdata/sample-revisioned-api.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ data: # Contains the meta data of the API
8282
- Content-Type
8383
- SOAPAction
8484
- apikey
85-
- testKey
85+
- Internal-Key
8686
accessControlAllowMethods: # Allowed methods as a list
8787
- GET
8888
- PUT
@@ -119,6 +119,10 @@ data: # Contains the meta data of the API
119119
throttlingPolicy: Unlimited
120120
scopes: []
121121
usedProductIds: []
122+
operationPolicies:
123+
request: []
124+
response: []
125+
fault: []
122126
-
123127
id: ""
124128
target: /menu
@@ -127,6 +131,10 @@ data: # Contains the meta data of the API
127131
throttlingPolicy: Unlimited
128132
scopes: []
129133
usedProductIds: []
134+
operationPolicies:
135+
request: []
136+
response: []
137+
fault: []
130138
-
131139
id: ""
132140
target: /order/{orderId}
@@ -135,6 +143,10 @@ data: # Contains the meta data of the API
135143
throttlingPolicy: Unlimited
136144
scopes: []
137145
usedProductIds: []
146+
operationPolicies:
147+
request: []
148+
response: []
149+
fault: []
138150
-
139151
id: ""
140152
target: /order/{orderId}
@@ -143,6 +155,10 @@ data: # Contains the meta data of the API
143155
throttlingPolicy: Unlimited
144156
scopes: []
145157
usedProductIds: []
158+
operationPolicies:
159+
request: []
160+
response: []
161+
fault: []
146162
-
147163
id: ""
148164
target: /order/{orderId}
@@ -151,6 +167,10 @@ data: # Contains the meta data of the API
151167
throttlingPolicy: Unlimited
152168
scopes: []
153169
usedProductIds: []
170+
operationPolicies:
171+
request: []
172+
response: []
173+
fault: []
154174
categories: [] # List of API Categories that the API belongs to
155175
keyManagers: # List of key manager endpoints
156176
- all

import-export-cli/utils/constants.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,18 @@ const DeploymentCertificatesDirectory = "certificates"
9696
var DefaultExportDirPath = filepath.Join(ConfigDirPath, DefaultExportDirName)
9797
var DefaultCertDirPath = filepath.Join(ConfigDirPath, CertificatesDirName)
9898

99-
const defaultApiApplicationImportExportSuffix = "api/am/admin/v2"
100-
const defaultPublisherApiImportExportSuffix = "api/am/publisher/v2"
101-
const defaultApiListEndpointSuffix = "api/am/publisher/v2/apis"
102-
const defaultApiProductListEndpointSuffix = "api/am/publisher/v2/api-products"
103-
const defaultUnifiedSearchEndpointSuffix = "api/am/publisher/v2/search"
104-
const defaultAdminApplicationListEndpointSuffix = "api/am/admin/v2/applications"
99+
const defaultApiApplicationImportExportSuffix = "api/am/admin/v3"
100+
const defaultPublisherApiImportExportSuffix = "api/am/publisher/v3"
101+
const defaultApiListEndpointSuffix = "api/am/publisher/v3/apis"
102+
const defaultApiProductListEndpointSuffix = "api/am/publisher/v3/api-products"
103+
const defaultUnifiedSearchEndpointSuffix = "api/am/publisher/v3/search"
104+
const defaultAdminApplicationListEndpointSuffix = "api/am/admin/v3/applications"
105105
const defaultDevPortalApplicationListEndpointSuffix = "api/am/devportal/v2/applications"
106106
const defaultDevPortalThrottlingPoliciesEndpointSuffix = "api/am/devportal/v2/throttling-policies"
107107
const defaultClientRegistrationEndpointSuffix = "client-registration/v0.17/register"
108108
const defaultTokenEndPoint = "oauth2/token"
109109
const defaultRevokeEndpointSuffix = "oauth2/revoke"
110-
const defaultAPILoggingBaseEndpoint = "api/am/devops/v1/tenant-logs"
111-
const defaultAPILoggingListEndpoint = "apis?logging-enabled=false"
110+
const defaultAPILoggingBaseEndpoint = "api/am/devops/v0/tenant-logs"
112111
const defaultAPILoggingApisEndpoint = "apis"
113112

114113
const DefaultEnvironmentName = "default"

import-export-cli/utils/envManagementUtils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ func GetAPILoggingListEndpointOfEnv(env, tenantDomain, filePath string) string {
287287
envEndpoints, _ := GetEndpointsOfEnvironment(env, filePath)
288288
if !(envEndpoints.PublisherEndpoint == "" || envEndpoints == nil) {
289289
envEndpoints.PublisherEndpoint = AppendSlashToString(envEndpoints.PublisherEndpoint)
290-
return envEndpoints.PublisherEndpoint + defaultAPILoggingBaseEndpoint + "/" + tenantDomain + "/" + defaultAPILoggingListEndpoint
290+
return envEndpoints.PublisherEndpoint + defaultAPILoggingBaseEndpoint + "/" + tenantDomain + "/" + defaultAPILoggingApisEndpoint
291291
} else {
292292
apiManagerEndpoint := GetApiManagerEndpointOfEnv(env, filePath)
293293
apiManagerEndpoint = AppendSlashToString(apiManagerEndpoint)
294-
return apiManagerEndpoint + defaultAPILoggingBaseEndpoint + "/" + tenantDomain + "/" + defaultAPILoggingListEndpoint
294+
return apiManagerEndpoint + defaultAPILoggingBaseEndpoint + "/" + tenantDomain + "/" + defaultAPILoggingApisEndpoint
295295
}
296296
}
297297

0 commit comments

Comments
 (0)