Skip to content

Commit

Permalink
fix: add ConfigService to GetRelationsCommand for dynamic base path c…
Browse files Browse the repository at this point in the history
…onfiguration
  • Loading branch information
getlarge committed Oct 8, 2024
1 parent ebe9230 commit 258a6a1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/keto-cli/src/app/get-relations.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import {
IRelationTuple,
} from '@getlarge/keto-relations-parser';
import { Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Configuration, Relationship } from '@ory/client';
import { Command, CommandRunner, Option } from 'nest-commander';

import { OryKetoEnvironmentVariables } from './environment-variables';

interface CommandOptions
extends Pick<Configuration, 'basePath' | 'accessToken'> {
namespace: string;
Expand All @@ -22,7 +25,11 @@ export class GetRelationsCommand extends CommandRunner {
readonly logger = new Logger(GetRelationsCommand.name);

constructor(
private readonly oryRelationshipsService: OryRelationshipsService
private readonly oryRelationshipsService: OryRelationshipsService,
private readonly configService: ConfigService<
OryKetoEnvironmentVariables,
true
>
) {
super();
}
Expand All @@ -36,6 +43,10 @@ export class GetRelationsCommand extends CommandRunner {
subjectObject,
subjectRelation,
} = options;
/**
* Use the correct base path since the SDK assign the GET /relation-tuples endpoint to the admin API
*/
options.basePath ??= this.configService.get('ORY_KETO_PUBLIC_URL');
if (options.basePath || options.accessToken) {
this.oryRelationshipsService.config = new Configuration({
...this.oryRelationshipsService.config,
Expand Down

0 comments on commit 258a6a1

Please sign in to comment.