Skip to content

Commit 5afd0d0

Browse files
feat(cli): Pass the platform url on decrypt, add the platform kas to the allowlist when fetching (#565)
* pass platform url in cli, add base platform kas by default * 🤖 🎨 Autoformat * set platform url for nano * pass the platform endpoint into opentdf obj * only add url if not already in registry
1 parent 598c39f commit 5afd0d0

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

cli/src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ export const handleArgs = (args: string[]) => {
622622
}
623623
const authProvider = await processAuth(argv);
624624
log('DEBUG', `Initialized auth provider ${JSON.stringify(authProvider)}`);
625+
const guessedPolicyEndpoint = guessPolicyUrl(argv);
625626
const client = new OpenTDF({
626627
authProvider,
627628
defaultCreateOptions: {
@@ -633,7 +634,8 @@ export const handleArgs = (args: string[]) => {
633634
noVerify: !!argv.noVerifyAssertions,
634635
},
635636
disableDPoP: !argv.dpop,
636-
policyEndpoint: guessPolicyUrl(argv),
637+
policyEndpoint: guessedPolicyEndpoint,
638+
platformUrl: guessedPolicyEndpoint,
637639
});
638640
try {
639641
log('SILLY', `Initialized client`);

lib/src/access.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,23 @@ export async function fetchKeyAccessServers(
190190
} catch (e) {
191191
throw new NetworkError(`unable to fetch kas list from [${req.url}]`, e);
192192
}
193-
if (response.ok) {
194-
const { keyAccessServers = [], pagination = {} } = await response.json();
195-
allServers.push(...keyAccessServers);
196-
nextOffset = pagination.nextOffset || 0;
193+
// if we get an error from the kas registry, throw an error
194+
if (!response.ok) {
195+
throw new ServiceError(
196+
`unable to fetch kas list from [${req.url}], status: ${response.status}`
197+
);
197198
}
199+
const { keyAccessServers = [], pagination = {} } = await response.json();
200+
allServers.push(...keyAccessServers);
201+
nextOffset = pagination.nextOffset || 0;
198202
} while (nextOffset > 0);
199203

200-
if (!allServers.length) {
201-
throw new ConfigurationError('There are no available KAS');
202-
}
203204
const serverUrls = allServers.map((server) => server.uri);
205+
// add base platform kas
206+
if (!serverUrls.includes(`${platformUrl}/kas`)) {
207+
serverUrls.push(`${platformUrl}/kas`);
208+
}
209+
204210
return new OriginAllowList(serverUrls, false);
205211
}
206212

lib/src/opentdf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class NanoTDFReader {
497497
) {
498498
if (
499499
!this.opts.ignoreAllowlist &&
500-
!this.outer.platformUrl &&
500+
!this.opts.platformUrl &&
501501
!this.opts.allowedKASEndpoints?.length
502502
) {
503503
throw new ConfigurationError('platformUrl is required when allowedKasEndpoints is empty');
@@ -529,7 +529,7 @@ class NanoTDFReader {
529529
dpopEnabled: this.outer.dpopEnabled,
530530
dpopKeys: this.outer.dpopKeys,
531531
kasEndpoint: this.opts.allowedKASEndpoints?.[0] || 'https://disallow.all.invalid',
532-
platformUrl: this.outer.platformUrl,
532+
platformUrl: this.opts.platformUrl || this.outer.platformUrl,
533533
});
534534
// TODO: The version number should be fetched from the API
535535
const version = '0.0.1';

0 commit comments

Comments
 (0)