From 5619d2e75ed5baf4cef9ea29ee5eb6f8f6229371 Mon Sep 17 00:00:00 2001 From: Maxime Dufour Date: Tue, 16 Jan 2024 14:21:22 +0000 Subject: [PATCH] Add Dedicated Groups resource Signed-off-by: Maxime Dufour --- package-lock.json | 16 ++--- package.json | 4 +- src/cloud/dedicatedgroup.ts | 68 +++++++++++++++++++ .../simple/node.folder.dedicatedgroup.ts | 45 ++++++++++++ src/flat/node.profile.ts | 2 + src/flat/node.ts | 3 +- src/ui-test/treeview.ts | 3 +- src/virtual_filesystem/oscvirtualfs.ts | 4 +- 8 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 src/cloud/dedicatedgroup.ts create mode 100644 src/flat/folders/simple/node.folder.dedicatedgroup.ts diff --git a/package-lock.json b/package-lock.json index b98674a..38e2535 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@types/cytoscape": "^3.19.9", "@vscode/l10n": "^0.0.13", "cross-fetch": "^3.1.5", - "outscale-api": "^0.11.0", + "outscale-api": "^0.12.0", "rxjs": "^7.5.7", "true-myth": "^6.2.0" }, @@ -31,7 +31,7 @@ "eslint": "^8.14.0", "glob": "^8.0.1", "mocha": "^9.2.2", - "outscale-api": "^0.11.0", + "outscale-api": "^0.12.0", "ovsx": "^0.8.0", "sinon": "^14.0.1", "ts-mock-imports": "^1.3.8", @@ -3552,9 +3552,9 @@ } }, "node_modules/outscale-api": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/outscale-api/-/outscale-api-0.11.0.tgz", - "integrity": "sha512-dUfah/6ChkeU8feP5SgahaE0KmubyMafWRzMIqWH1JFP9kZV8opRhs+66NmPPENsBX/ymrllioT+PBf0a0sU4g==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/outscale-api/-/outscale-api-0.12.0.tgz", + "integrity": "sha512-y8qXg+WY1O//Pticb2RnmEJRsRZBxAZZeae/pI6k7je3lSd2K+hJho++GroqinMXOrDffdMHLPNr4HOpO3xz0Q==", "dev": true, "dependencies": { "aws4fetch": "^1.0.13" @@ -7849,9 +7849,9 @@ } }, "outscale-api": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/outscale-api/-/outscale-api-0.11.0.tgz", - "integrity": "sha512-dUfah/6ChkeU8feP5SgahaE0KmubyMafWRzMIqWH1JFP9kZV8opRhs+66NmPPENsBX/ymrllioT+PBf0a0sU4g==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/outscale-api/-/outscale-api-0.12.0.tgz", + "integrity": "sha512-y8qXg+WY1O//Pticb2RnmEJRsRZBxAZZeae/pI6k7je3lSd2K+hJho++GroqinMXOrDffdMHLPNr4HOpO3xz0Q==", "dev": true, "requires": { "aws4fetch": "^1.0.13" diff --git a/package.json b/package.json index 60e4ef4..8d6ca95 100644 --- a/package.json +++ b/package.json @@ -390,7 +390,7 @@ "eslint": "^8.14.0", "glob": "^8.0.1", "mocha": "^9.2.2", - "outscale-api": "^0.11.0", + "outscale-api": "^0.12.0", "ovsx": "^0.8.0", "sinon": "^14.0.1", "ts-mock-imports": "^1.3.8", @@ -403,7 +403,7 @@ "@types/cytoscape": "^3.19.9", "@vscode/l10n": "^0.0.13", "cross-fetch": "^3.1.5", - "outscale-api": "^0.11.0", + "outscale-api": "^0.12.0", "rxjs": "^7.5.7", "true-myth": "^6.2.0" } diff --git a/src/cloud/dedicatedgroup.ts b/src/cloud/dedicatedgroup.ts new file mode 100644 index 0000000..163a52a --- /dev/null +++ b/src/cloud/dedicatedgroup.ts @@ -0,0 +1,68 @@ + +import * as osc from "outscale-api"; +import { FiltersDedicatedGroup } from "outscale-api"; +import { getConfig, handleRejection } from '../cloud/cloud'; +import { Profile } from "../flat/node"; + + +// Retrieve all items of the resource DedicatedGroup +export function getDedicatedGroups(profile: Profile, filters?: FiltersDedicatedGroup): Promise | string> { + const config = getConfig(profile); + const readParameters: osc.ReadDedicatedGroupsOperationRequest = { + readDedicatedGroupsRequest: { + filters: filters + } + }; + + const api = new osc.DedicatedGroupApi(config); + return api.readDedicatedGroups(readParameters) + .then((res: osc.ReadDedicatedGroupsResponse) => { + if (res.dedicatedGroups === undefined || res.dedicatedGroups.length === 0) { + return []; + } + return res.dedicatedGroups; + }, (err_: any) => { + return handleRejection(err_); + }); +} + +// Retrieve a specific item of the resource DedicatedGroup +export function getDedicatedGroup(profile: Profile, resourceId: string): Promise { + const config = getConfig(profile); + const readParameters: osc.ReadDedicatedGroupsOperationRequest = { + readDedicatedGroupsRequest: { + filters: { + dedicatedGroupIds: [resourceId] + } + } + }; + + const api = new osc.DedicatedGroupApi(config); + return api.readDedicatedGroups(readParameters) + .then((res: osc.ReadDedicatedGroupsResponse) => { + if (res.dedicatedGroups === undefined || res.dedicatedGroups.length === 0) { + return undefined; + } + return res.dedicatedGroups[0]; + }, (err_: any) => { + return handleRejection(err_); + }); +} + +// Delete a specific item the resource DedicatedGroup +export function deleteDedicatedGroup(profile: Profile, resourceId: string): Promise { + const config = getConfig(profile); + const deleteParameters: osc.DeleteDedicatedGroupOperationRequest = { + deleteDedicatedGroupRequest: { + dedicatedGroupId: resourceId + } + }; + + const api = new osc.DedicatedGroupApi(config); + return api.deleteDedicatedGroup(deleteParameters) + .then(() => { + return undefined; + }, (err_: any) => { + return handleRejection(err_); + }); +} \ No newline at end of file diff --git a/src/flat/folders/simple/node.folder.dedicatedgroup.ts b/src/flat/folders/simple/node.folder.dedicatedgroup.ts new file mode 100644 index 0000000..315b45b --- /dev/null +++ b/src/flat/folders/simple/node.folder.dedicatedgroup.ts @@ -0,0 +1,45 @@ +import * as vscode from 'vscode'; +import { ExplorerNode, ExplorerFolderNode, Profile, resourceNodeCompare } from '../../node'; +import { FiltersFolderNode } from '../node.filterfolder'; +import { ResourceNode } from '../../resources/node.resources'; +import { FiltersDedicatedGroup, FiltersDedicatedGroupFromJSON } from 'outscale-api'; +import { deleteDedicatedGroup, getDedicatedGroup, getDedicatedGroups } from '../../../cloud/dedicatedgroup'; + +export const DEDICATEDGROUP_FOLDER_NAME = "Dedicated Groups"; +export class DedicatedGroupsFolderNode extends FiltersFolderNode implements ExplorerFolderNode { + constructor(readonly profile: Profile) { + super(profile, DEDICATEDGROUP_FOLDER_NAME); + } + + getChildren(): Thenable { + this.updateFilters(); + return getDedicatedGroups(this.profile, this.filters).then(results => { + if (typeof results === "string") { + vscode.window.showErrorMessage(vscode.l10n.t(`Error while reading {0}: {1}`, this.folderName, results)); + return Promise.resolve([]); + } + const resources = []; + for (const item of results) { + + if (typeof item.dedicatedGroupId === 'undefined') { + + continue; + } + + if (typeof item.name === 'undefined') { + + continue; + } + + resources.push(new ResourceNode(this.profile, item.name, item.dedicatedGroupId, "DedicatedGroup", deleteDedicatedGroup, getDedicatedGroup)); + + } + return Promise.resolve(resources.sort(resourceNodeCompare)); + }); + + } + + filtersFromJson(json: string): FiltersDedicatedGroup { + return FiltersDedicatedGroupFromJSON(json); + } +} \ No newline at end of file diff --git a/src/flat/node.profile.ts b/src/flat/node.profile.ts index 825e05e..94079ba 100644 --- a/src/flat/node.profile.ts +++ b/src/flat/node.profile.ts @@ -30,6 +30,7 @@ import { VpnConnectionsFolderNode, VPNCONNECTIONS_FOLDER_NAME } from './folders/ import { DISABLE_FOLDER_PARAMETER, getConfigurationParameter } from '../configuration/utils'; import { VMGROUPS_FOLDER_NAME, VmGroupsFolderNode } from './folders/simple/node.folder.vmgroup'; import { VMTEMPLATES_FOLDER_NAME, VmTemplatesFolderNode } from './folders/simple/node.folder.vmtemplate'; +import { DEDICATEDGROUP_FOLDER_NAME, DedicatedGroupsFolderNode } from './folders/simple/node.folder.dedicatedgroup'; export class ProfileNode implements ExplorerProfileNode { @@ -50,6 +51,7 @@ export class ProfileNode implements ExplorerProfileNode { [APIACCESSRULES_FOLDER_NAME, new ApiAccessRulesFolderNode(this.profile)], [CA_FOLDER_NAME, new CasFolderNode(this.profile)], [CLIENTGATEWAYS_FOLDER_NAME, new ClientGatewaysFolderNode(this.profile)], + [DEDICATEDGROUP_FOLDER_NAME, new DedicatedGroupsFolderNode(this.profile)], [DHCPOPTIONS_FOLDER_NAME, new DhcpOptionsFolderNode(this.profile)], [DIRECTLINKS_FOLDER_NAME, new DirectLinksFolderNode(this.profile)], [DIRECTLINKINTERFACES_FOLDER_NAME, new DirectLinkInterfacesFolderNode(this.profile)], diff --git a/src/flat/node.ts b/src/flat/node.ts index 0ddd7f2..4051799 100644 --- a/src/flat/node.ts +++ b/src/flat/node.ts @@ -57,7 +57,8 @@ export type ResourceNodeType = "snapshots" | "routetables" | "VmTemplate" | - "VmGroup"; + "VmGroup" | + "DedicatedGroup"; export class NodeImpl { } diff --git a/src/ui-test/treeview.ts b/src/ui-test/treeview.ts index 914987a..03d7897 100644 --- a/src/ui-test/treeview.ts +++ b/src/ui-test/treeview.ts @@ -16,6 +16,7 @@ const resourceTypes = [ "Api Access Rules", "Cas", "Client Gateways", + "Dedicated Groups", "Dhcp Options", "DirectLinks", "DirectLink Interfaces", @@ -115,7 +116,7 @@ describe('ActivityBar', () => { expect(action).not.undefined; }); - it.skip('open dialog', async function() { + it.skip('open dialog', async function () { await action.click(); const input = new InputBox(); // Check the title diff --git a/src/virtual_filesystem/oscvirtualfs.ts b/src/virtual_filesystem/oscvirtualfs.ts index 85c6737..fa9492d 100644 --- a/src/virtual_filesystem/oscvirtualfs.ts +++ b/src/virtual_filesystem/oscvirtualfs.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -import { AccessKeyToJSON, AccountToJSON, ApiAccessRuleToJSON, CaToJSON, ClientGatewayToJSON, DhcpOptionsSetToJSON, DirectLinkInterfaceToJSON, DirectLinkToJSON, FlexibleGpuToJSON, ImageToJSON, InternetServiceToJSON, KeypairToJSON, LoadBalancerToJSON, NatServiceToJSON, NetAccessPointToJSON, NetPeeringToJSON, NetToJSON, NicToJSON, PublicIpToJSON, RouteTableToJSON, SecurityGroupToJSON, SnapshotToJSON, SubnetToJSON, VirtualGatewayToJSON, VmGroupFromJSON, VmGroupToJSON, VmTemplateToJSON, VmToJSON, VolumeToJSON, VpnConnectionToJSON } from "outscale-api"; +import { AccessKeyToJSON, AccountToJSON, ApiAccessRuleToJSON, CaToJSON, ClientGatewayToJSON, DedicatedGroupToJSON, DhcpOptionsSetToJSON, DirectLinkInterfaceToJSON, DirectLinkToJSON, FlexibleGpuToJSON, ImageToJSON, InternetServiceToJSON, KeypairToJSON, LoadBalancerToJSON, NatServiceToJSON, NetAccessPointToJSON, NetPeeringToJSON, NetToJSON, NicToJSON, PublicIpToJSON, RouteTableToJSON, SecurityGroupToJSON, SnapshotToJSON, SubnetToJSON, VirtualGatewayToJSON, VmGroupToJSON, VmTemplateToJSON, VmToJSON, VolumeToJSON, VpnConnectionToJSON } from "outscale-api"; import { getExternalIP } from "../cloud/publicips"; import { getKeypair } from "../cloud/keypairs"; import { getLoadBalancer } from "../cloud/loadbalancers"; @@ -32,6 +32,7 @@ import { getVirtualGateway } from '../cloud/virtualgateways'; import { getVpnConnection } from '../cloud/vpnconnections'; import { getVmGroup } from '../cloud/vmgroup'; import { getVmTemplate } from '../cloud/vmtemplate'; +import { getDedicatedGroup } from '../cloud/dedicatedgroup'; class ResourceEncoding { @@ -71,6 +72,7 @@ const resourceMap = new Map([ ["VpnConnection", new ResourceEncoding(getVpnConnection, VpnConnectionToJSON)], ["VmGroup", new ResourceEncoding(getVmGroup, VmGroupToJSON)], ["VmTemplate", new ResourceEncoding(getVmTemplate, VmTemplateToJSON)], + ["DedicatedGroup", new ResourceEncoding(getDedicatedGroup, DedicatedGroupToJSON)], ]); export class OscVirtualContentProvider implements vscode.TextDocumentContentProvider {