-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat(backend): request grant to query incoming payment receiver #779
Changes from all commits
ce5c135
6f7b31f
2988e54
3763cd6
da07fea
417e6a3
4a453a9
aa571e1
19fe828
291ec8c
f29d867
2e2a3a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
exports.up = function (knex) { | ||
return knex.schema.createTable('authServers', function (table) { | ||
table.uuid('id').notNullable().primary() | ||
table.string('url').notNullable().unique() | ||
table.timestamp('createdAt').defaultTo(knex.fn.now()) | ||
table.timestamp('updatedAt').defaultTo(knex.fn.now()) | ||
}) | ||
} | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.dropTableIfExists('authServers') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
exports.up = function (knex) { | ||
return knex.schema.createTable('grants', function (table) { | ||
table.uuid('id').notNullable().primary() | ||
table.uuid('authServerId').notNullable() | ||
table.foreign('authServerId').references('authServers.id') | ||
table.string('continueId').nullable() | ||
table.string('continueToken').nullable() | ||
table.string('accessToken').nullable().unique() | ||
table.string('accessType').notNullable() | ||
table.specificType('accessActions', 'text[]') | ||
|
||
table.timestamp('expiresAt').nullable() | ||
|
||
table.timestamp('createdAt').defaultTo(knex.fn.now()) | ||
table.timestamp('updatedAt').defaultTo(knex.fn.now()) | ||
|
||
table.unique(['authServerId', 'accessType', 'accessActions']) | ||
}) | ||
} | ||
Comment on lines
+1
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it sufficient to not store the entire access array of the grant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is for now since the RS is only requesting read-all incoming payment grants, and the new |
||
|
||
exports.down = function (knex) { | ||
return knex.schema.dropTableIfExists('grants') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BaseModel } from '../../shared/baseModel' | ||
|
||
export class AuthServer extends BaseModel { | ||
public static get tableName(): string { | ||
return 'authServers' | ||
} | ||
|
||
public url!: string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { IocContract } from '@adonisjs/fold' | ||
import { faker } from '@faker-js/faker' | ||
import { Knex } from 'knex' | ||
|
||
import { AuthServer } from './model' | ||
import { AuthServerService } from './service' | ||
import { initIocContainer } from '../../' | ||
import { AppServices } from '../../app' | ||
import { Config } from '../../config/app' | ||
import { createTestApp, TestContainer } from '../../tests/app' | ||
import { truncateTables } from '../../tests/tableManager' | ||
|
||
describe('Auth Server Service', (): void => { | ||
let deps: IocContract<AppServices> | ||
let appContainer: TestContainer | ||
let authServerService: AuthServerService | ||
let knex: Knex | ||
|
||
beforeAll(async (): Promise<void> => { | ||
deps = await initIocContainer(Config) | ||
appContainer = await createTestApp(deps) | ||
knex = await deps.use('knex') | ||
authServerService = await deps.use('authServerService') | ||
}) | ||
|
||
afterEach(async (): Promise<void> => { | ||
await truncateTables(knex) | ||
}) | ||
|
||
afterAll(async (): Promise<void> => { | ||
await appContainer.shutdown() | ||
}) | ||
|
||
describe('getOrCreate', (): void => { | ||
test('Auth server can be created or fetched', async (): Promise<void> => { | ||
const url = faker.internet.url() | ||
await expect( | ||
AuthServer.query(knex).findOne({ url }) | ||
).resolves.toBeUndefined() | ||
const authServer = await authServerService.getOrCreate(url) | ||
await expect(authServer).toMatchObject({ url }) | ||
await expect(AuthServer.query(knex).findOne({ url })).resolves.toEqual( | ||
authServer | ||
) | ||
await expect(authServerService.getOrCreate(url)).resolves.toEqual( | ||
authServer | ||
) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { UniqueViolationError } from 'objection' | ||
|
||
import { AuthServer } from './model' | ||
import { BaseService } from '../../shared/baseService' | ||
|
||
export interface AuthServerService { | ||
getOrCreate(url: string): Promise<AuthServer> | ||
} | ||
|
||
type ServiceDependencies = BaseService | ||
|
||
export async function createAuthServerService( | ||
deps_: ServiceDependencies | ||
): Promise<AuthServerService> { | ||
const deps: ServiceDependencies = { | ||
...deps_, | ||
logger: deps_.logger.child({ | ||
service: 'AuthServerService' | ||
}) | ||
} | ||
return { | ||
getOrCreate: (url) => getOrCreateAuthServer(deps, url) | ||
} | ||
} | ||
|
||
async function getOrCreateAuthServer( | ||
deps: ServiceDependencies, | ||
url: string | ||
): Promise<AuthServer> { | ||
try { | ||
return await AuthServer.query(deps.knex).insertAndFetch({ | ||
url | ||
}) | ||
} catch (err) { | ||
if (err instanceof UniqueViolationError) { | ||
return await AuthServer.query(deps.knex).findOne({ url }) | ||
} | ||
throw err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this after noticing 👇 while testing:
However, I am now sometimes getting the following when starting the localenv:
I wonder if that can be avoided by splitting these into separate/subsequent
docker compose
commands:rafiki/package.json
Lines 20 to 21 in 632bdfb