-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth, backend): seed operator tenant (#3156)
* feat(auth): migration to seed operator tenant * feat(backend): migration to seed operator tenant * chore(localenv): add env vars for operator tenant * test(backend): set operator env variables in jest config * test(auth): set operator env variables in jest config * test(auth, backend): load env vars into jest environment script * feat(auth,backend): update migrations with error messages * test(integration): adding operator tenant vars * chore(backend, localenv): replace OPERATOR_TENANT_SECRET with existing API_SECRET
- Loading branch information
Showing
13 changed files
with
112 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/auth/migrations/20241205153036_seed_operator_tenant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
|
||
const OPERATOR_TENANT_ID = process.env['OPERATOR_TENANT_ID'] | ||
const IDENTITY_SERVER_URL = process.env['IDENTITY_SERVER_URL'] | ||
const IDENTITY_SERVER_SECRET = process.env['IDENTITY_SERVER_SECRET'] | ||
|
||
exports.up = function (knex) { | ||
if (!OPERATOR_TENANT_ID) { | ||
throw new Error( | ||
'Could not seed operator tenant. Please configure OPERATOR_TENANT_ID environment variables' | ||
) | ||
} | ||
|
||
const seed = { | ||
id: OPERATOR_TENANT_ID | ||
} | ||
|
||
if (IDENTITY_SERVER_URL) { | ||
seed['idpConsentUrl'] = IDENTITY_SERVER_URL | ||
} | ||
|
||
if (IDENTITY_SERVER_SECRET) { | ||
seed['idpSecret'] = IDENTITY_SERVER_SECRET | ||
} | ||
|
||
return knex.raw(` | ||
INSERT INTO "tenants" (${Object.keys(seed) | ||
.map((key) => `"${key}"`) | ||
.join(', ')}) | ||
VALUES (${Object.values(seed) | ||
.map((key) => `'${key}'`) | ||
.join(', ')}) | ||
`) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.raw(` | ||
TRUNCATE "tenants" | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
process.env.LOG_LEVEL = 'silent' | ||
process.env.INSTANCE_NAME = 'Rafiki' | ||
process.env.KEY_ID = 'myKey' | ||
process.env.OPEN_PAYMENTS_URL = 'http://127.0.0.1:3000' | ||
process.env.ILP_CONNECTOR_URL = 'http://127.0.0.1:3002' | ||
process.env.ILP_ADDRESS = 'test.rafiki' | ||
process.env.AUTH_SERVER_GRANT_URL = 'http://127.0.0.1:3006' | ||
process.env.AUTH_SERVER_INTROSPECTION_URL = 'http://127.0.0.1:3007/' | ||
process.env.WEBHOOK_URL = 'http://127.0.0.1:4001/webhook' | ||
process.env.STREAM_SECRET = '2/PxuRFV9PAp0yJlnAifJ+1OxujjjI16lN+DBnLNRLA=' | ||
process.env.USE_TIGERBEETLE = false | ||
process.env.ENABLE_TELEMETRY = false | ||
process.env.AUTH_ADMIN_API_URL = 'http://127.0.0.1:3003/graphql' | ||
process.env.AUTH_ADMIN_API_SECRET = 'test-secret' | ||
process.env.OPERATOR_TENANT_ID = 'cf5fd7d3-1eb1-4041-8e43-ba45747e9e5d' | ||
process.env.API_SECRET = 'KQEXlZO65jUJXakXnLxGO7dk387mt71G9tZ42rULSNU=' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/backend/migrations/20241205153035_seed_operator_tenant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
|
||
const OPERATOR_TENANT_ID = process.env['OPERATOR_TENANT_ID'] | ||
const OPERATOR_API_SECRET = process.env['API_SECRET'] | ||
|
||
exports.up = function (knex) { | ||
if (!OPERATOR_TENANT_ID || !OPERATOR_API_SECRET) { | ||
throw new Error( | ||
'Could not seed operator tenant. Please configure OPERATOR_TENANT_ID and API_SECRET environment variables' | ||
) | ||
} | ||
|
||
return knex.raw(` | ||
INSERT INTO "tenants" ("id", "apiSecret") | ||
VALUES ('${OPERATOR_TENANT_ID}', '${OPERATOR_API_SECRET}') | ||
`) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.raw(` | ||
TRUNCATE "tenants" | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters