Skip to content

Commit

Permalink
Switch to bundle API for validation (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-ma authored Jul 11, 2024
1 parent d2d2a41 commit 57af404
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 54 deletions.
13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"title": "Download"
},
{
"command": "orab.add.validate",
"title": "RAB: Validate"
"command": "orab.bundle.validate",
"title": "RAB: Validate RAB Bundle"
},
{
"command": "orab.add.version-check",
Expand Down Expand Up @@ -159,10 +159,6 @@
"command": "orab.bundle.delete",
"when": "false"
},
{
"command": "orab.add.validate",
"when": "false"
},
{
"command": "orab.add.version-check",
"when": "false"
Expand Down Expand Up @@ -209,11 +205,6 @@
}
],
"explorer/context": [
{
"when": "resourceFilename =~ /\\.add\\.json$/",
"command": "orab.add.validate",
"group": "orab"
},
{
"when": "resourceFilename =~ /\\.add\\.json$/",
"command": "orab.add.version-check",
Expand Down
20 changes: 20 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,26 @@ export namespace bundle {
}
}

export async function validate(bundle: Buffer): Promise<DefinitionValidationResponse> {

let url = `${apiRootPath}/${resource}/validate`;
log.debug(`Calling '${url}'`);
try {
let res = await callAPI(async () => (await getClient()).post(url, bundle, {
headers: {
'Content-Type': 'application/zip',

Check warning on line 310 in src/api.ts

View workflow job for this annotation

GitHub Actions / package

Object Literal Property name `Content-Type` must match one of the following formats: camelCase
},
}) as Promise<AxiosResponse<DefinitionValidationResponse>>);
logInfoServer(res?.data);
return res.data;
} catch (err) {
if (err instanceof AxiosError && err.response?.status !== 404) {
logInfoServer(err.response?.data);
}
throw new RABError(`Failed to call 'POST ${url}'`, err);
}
}

}

/**
Expand Down
41 changes: 0 additions & 41 deletions src/commands/validate-add.ts

This file was deleted.

44 changes: 44 additions & 0 deletions src/commands/validate-rab-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright © 2022-2024, Oracle and/or its affiliates.
* This software is licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/

import * as vscode from 'vscode';


import * as api from '../api';
import { log } from '../logger';
import { get as getProfileManager } from '../profile-manager-provider';
import { RABError, showErrorMessage, showInfoMessage, withProgress } from '../utils/ui-utils';
import { createRABBundle } from '../workspace-manager';

async function callback(file: vscode.Uri, context: vscode.ExtensionContext): Promise<any> {

withProgress("Validating RAB bundle...", async () => {
log.info(`Validating RAB bundle...`);
let bundle;
try {
bundle = await createRABBundle();
} catch (err) {
showErrorMessage(err); return;
}

let profileName = (await getProfileManager().active())?.name;
log.info(`Using the publisher profile '${profileName}'`);

try {
let ret;
ret = await api.bundle.validate(bundle.content);
showInfoMessage(`Adapter '${bundle.id}' is ${ret.valid ? 'valid' : 'invalid'}.`);
} catch (err) {
showErrorMessage(new RABError('Cannot validate the bundle.', err));
}
});
}

export function register(context: vscode.ExtensionContext) {

context.subscriptions.push(
vscode.commands.registerCommand("orab.bundle.validate", callback)
);
}
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as addLocate from './commands/add-locate';
import * as downloadRABBundle from './commands/download-rab-bundle';
import * as registerRABBundle from './commands/register-rab-bundle';
import * as removeRABBundle from './commands/remove-rab-bundle';
import * as validateRABBundle from './commands/validate-rab-bundle';

import * as createRabBundle from './commands/create-rab-bundle';
import * as importRABBundle from './commands/import-rab-bundle';
Expand All @@ -21,7 +22,6 @@ import * as explorerOutlineTriggersNew from './commands/explorer-outline-trigger
import * as initWorkspace from './commands/init-workspace';
import * as insertSecurityPolicy from './commands/insert-security-policy';
import * as insertTestConnection from './commands/insert-test-connection';
import * as validateAdd from './commands/validate-add';
import * as versionCheck from './commands/version-check';

import * as addListProvider from './providers/add-list-provider';
Expand All @@ -41,9 +41,9 @@ async function registerCommands(context: vscode.ExtensionContext) {
insertSecurityPolicy.register(context);
insertTestConnection.register(context);
registerRABBundle.register(context);
validateAdd.register(context);
versionCheck.register(context);
createRabBundle.register(context);
validateRABBundle.register(context);
importRABBundle.register(context);
}

Expand Down

0 comments on commit 57af404

Please sign in to comment.