Skip to content

Commit

Permalink
feat: add caller ip in action context.caller.request.ip
Browse files Browse the repository at this point in the history
  • Loading branch information
Enki Pontvianne committed Oct 18, 2024
1 parent dbae0cf commit b16a2ec
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/_example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
mssql:
image: mcr.microsoft.com/azure-sql-edge
container_name: forest_agent_example_mssql
user: root
ports:
- '1433:1433'
environment:
Expand Down
9 changes: 6 additions & 3 deletions packages/_example/src/forest/customizations/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ export default (collection: CardCustomizer) =>
collection
.addManyToOneRelation('customer', 'customer', { foreignKey: 'customer_id' })
.addAction('Create new card', {
scope: 'Global',
scope: 'Single',
execute: (context, resultBuilder) => {
return resultBuilder.success('ok');
},
form: [
{
type: 'Layout',
component: 'Page',
nextButtonLabel: 'go to next page',
previousButtonLabel: 'back',
elements: [
{
type: 'String',
Expand Down Expand Up @@ -59,8 +61,8 @@ export default (collection: CardCustomizer) =>
{
type: 'Layout',
component: 'Page',
nextButtonLabel: 'go to next page',
previousButtonLabel: 'go to previous page',
nextButtonLabel: 'go to next page (finalisation, setup of card properties)',
previousButtonLabel: 'return to previous page (selection of the card plan)',
elements: [
{
type: 'Layout',
Expand All @@ -77,6 +79,7 @@ export default (collection: CardCustomizer) =>
{
type: 'Layout',
component: 'Page',
previousButtonLabel: 'return to previous page (useless empty page)',
elements: [
{
type: 'Number',
Expand Down
3 changes: 2 additions & 1 deletion packages/agent/src/utils/query-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default class QueryStringParser {

static parseCaller(context: Context): Caller {
const timezone = context.request.query.timezone?.toString();
const { ip } = context.request;

if (!timezone) {
throw new ValidationError('Missing timezone');
Expand All @@ -140,7 +141,7 @@ export default class QueryStringParser {
QueryStringParser.VALID_TIMEZONES.add(timezone);
}

return { ...context.state.user, timezone, requestId: uuidv4() };
return { ...context.state.user, timezone, requestId: uuidv4(), request: { ip } };
}

static parsePagination(context: Context): Page {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class CacheDataSourceInterface {
firstName: 'Datasource',
lastName: 'Replica',
renderingId: 0,
request: { ip: '::1' },
role: 'system',
tags: {},
team: 'system',
Expand Down
1 change: 1 addition & 0 deletions packages/datasource-toolkit/src/interfaces/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Caller = {
team: string;
renderingId: number;
requestId: string;
request: { ip: string };
role: string;
tags: { [key: string]: string };
permissionLevel: 'admin' | 'developer' | 'editor' | 'user';
Expand Down
1 change: 1 addition & 0 deletions packages/datasource-toolkit/test/__factories__/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default Factory.define<Caller>(() => ({
lastName: 'domain',
renderingId: 1,
requestId: '00000000-0000-0000-0000-000000000000',
request: { ip: '::1' },
role: 'role',
tags: {},
team: 'team',
Expand Down

0 comments on commit b16a2ec

Please sign in to comment.