Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ACNA-1756 - config schema changes for integration type apikey #568

Merged
merged 6 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@
"oauthsinglepageapp"
]
},
"jwt": { "$ref": "#/definitions/jwt" }
"jwt": { "$ref": "#/definitions/jwt" },
"api_key": { "$ref": "#/definitions/api_key" },
"oauth2": { "$ref": "#/definitions/oauth2" }
},
"required": [ "id", "name" ],
"if": { "properties": { "integration_type": { "const": "apikey" } } },
"then": { "properties": { "oauth2": { "$ref": "#/definitions/apikey" } } },
"else": { "properties": { "oauth2": { "$ref": "#/definitions/oauth2" } } },
"oneOf": [
{ "required": ["oauth2"] },
{ "required": ["jwt"] }
{ "required": ["jwt"] },
{ "required": ["api_key"] }
]
},
"service": {
Expand Down Expand Up @@ -174,12 +174,12 @@
},
"required": [ "client_id", "client_secret", "redirect_uri", "defaultRedirectUri" ]
},
"apikey": {
"api_key": {
"type": "object",
"properties": {
"client_id": { "type": "string" }
},
"required": [ "client_id" ]
"required": ["client_id"]
},
"jwt": {
"type": "object",
Expand Down
7 changes: 2 additions & 5 deletions src/lib/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,8 @@ function transformCredentials (credentials, imsOrgId) {
}

return credentials.reduce((acc, credential) => {
// the json schema enforces either jwt OR oauth2 keys in a credential
let value = credential.oauth2
if (!value) {
value = credential.jwt
}
// the json schema enforces for jwt OR oauth2 OR apiKey in a credential
const value = credential.oauth2 || credential.jwt || credential.api_key

const name = credential.name.replace(/ /gi, '_') // replace any spaces with underscores
acc[name] = value
Expand Down
4 changes: 2 additions & 2 deletions test/__fixtures__/existing.merged.aio
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"integration_type": "service"
},
{
"id": "17561139",
"name": "Projéct_C",
"id": "17656565",
"name": "Project_C",
"integration_type": "apikey"
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/__fixtures__/existing.merged.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AIO_ims_contexts_PröjectB_technical__account__email=XTXTXTXTXTX@techacct.adobe.
AIO_ims_contexts_PröjectB_technical__account__id=IDIDIDIDID@techacct.adobe.com
AIO_ims_contexts_PröjectB_meta__scopes=["ent_smartcontent_sdk","ent_adobeio_sdk"]
AIO_ims_contexts_PröjectB_ims__org__id=XOXOXOXOXOXOX@AdobeOrg
AIO_ims_contexts_Projéct__C_client__id=XYXYXYXYXYXYXYXYX
AIO_ims_contexts_Project__C_client__id=AKAKAKAKAKAKAKAKAKAKAKAK
AIO_ims_contexts_New__Test__Intégration__8_client__id=XRXRXRXRXRXRXRXRXR
AIO_ims_contexts_New__Test__Intégration__8_client__secret=XRXRXRXRXRXRXRXRXRX
AIO_ims_contexts_New__Test__Intégration__8_redirect__uri=["https://abc123/foo"]
Expand Down
4 changes: 2 additions & 2 deletions test/__fixtures__/valid.config.aio
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"integration_type": "service"
},
{
"id": "17561139",
"name": "Projéct_C",
"id": "17656565",
"name": "Project_C",
"integration_type": "apikey"
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/__fixtures__/valid.config.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AIO_ims_contexts_PröjectB_technical__account__email=XTXTXTXTXTX@techacct.adobe.
AIO_ims_contexts_PröjectB_technical__account__id=IDIDIDIDID@techacct.adobe.com
AIO_ims_contexts_PröjectB_meta__scopes=["ent_smartcontent_sdk","ent_adobeio_sdk"]
AIO_ims_contexts_PröjectB_ims__org__id=XOXOXOXOXOXOX@AdobeOrg
AIO_ims_contexts_Projéct__C_client__id=XYXYXYXYXYXYXYXYX
AIO_ims_contexts_Project__C_client__id=AKAKAKAKAKAKAKAKAKAKAKAK
AIO_ims_contexts_New__Test__Intégration__8_client__id=XRXRXRXRXRXRXRXRXR
AIO_ims_contexts_New__Test__Intégration__8_client__secret=XRXRXRXRXRXRXRXRXRX
AIO_ims_contexts_New__Test__Intégration__8_redirect__uri=["https://abc123/foo"]
Expand Down
8 changes: 4 additions & 4 deletions test/__fixtures__/valid.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
}
},
{
"id": "17561139",
"name": "Projéct C",
"id": "17656565",
"name": "Project C",
"integration_type": "apikey",
"oauth2": {
"client_id": "XYXYXYXYXYXYXYXYX"
"api_key": {
"client_id": "AKAKAKAKAKAKAKAKAKAKAKAK"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('validate failure', () => {
const validate = ajv.compile(schema)
const valid = validate(fixtureJson('invalid.config.json'))
// the 4 errors are the missing name properties, techacct migration to two new properties
// the rest 2 are missing client_id and failing keyword `then`
expect(validate.errors.length).toEqual(6)
// the rest 3 are missing client_id and failing keyword `then`
expect(validate.errors.length).toEqual(7)
expect(valid).toBeFalsy()
})