Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] Network Groups initial support #780

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 117 additions & 1 deletion bin/clever.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import * as login from '../src/commands/login.js';
import * as logout from '../src/commands/logout.js';
import * as logs from '../src/commands/logs.js';
import * as makeDefault from '../src/commands/makeDefault.js';
import * as ng from '../src/commands/ng.js';
import * as notifyEmail from '../src/commands/notify-email.js';
import * as open from '../src/commands/open.js';
import * as consoleModule from '../src/commands/console.js';
Expand Down Expand Up @@ -90,10 +91,43 @@ async function run () {

// ARGUMENTS
const args = {
kvRawCommand: cliparse.argument('command', { description: 'The raw command to send to the Materia KV or Redis® add-on' }),
kvRawCommand: cliparse.argument('command', {
description: 'The raw command to send to the Materia KV or Redis® add-on',
}),
kvIdOrName: cliparse.argument('kv-id', {
description: 'Add-on/Real ID (or name, if unambiguous) of a Materia KV or Redis® add-on',
}),
ngId: cliparse.argument('id', {
description: 'Network Group ID',
parser: Parsers.ngResourceType,
}),
ngLabel: cliparse.argument('ng-label', {
description: 'Network Group label',
parser: Parsers.ngResourceType,
}),
ngIdOrLabel: cliparse.argument('ng-id-or-label', {
description: 'Network Group ID or label',
parser: Parsers.ngResourceType,
}),
ngDescription: cliparse.argument('ng-description', {
description: 'Network Group description',
}),
ngExternalPeerLabel: cliparse.argument('external-peer-label', {
description: 'External peer label',
parser: Parsers.ngResourceType,
}),
ngExternalIdOrLabel: cliparse.argument('external-peer-id-or-label', {
description: 'External peer ID or label',
parser: Parsers.ngResourceType,
}),
ngAnyIdOrLabel: cliparse.argument('id-or-label', {
description: 'ID or Label of a Network group, a member or an (external) peer',
parser: Parsers.ngResourceType,
}),
wgPublicKey: cliparse.argument('public-key', {
metavar: 'public_key',
description: 'Wireguard public key of the external peer to link to a Network Group',
}),
addonIdOrName: cliparse.argument('addon-id', {
description: 'Add-on ID (or name, if unambiguous)',
parser: Parsers.addonIdOrName,
Expand Down Expand Up @@ -147,6 +181,30 @@ async function run () {

// OPTIONS
const opts = {
// Network Groups options
ngDescription: cliparse.option('description', {
metavar: 'description',
description: 'Network Group description',
}),
ngMembersIdsToLink: cliparse.option('link', {
metavar: 'members_ids',
description: "Comma separated list of members IDs to link to a Network Group ('app_xxx', 'addon_xxx', 'external_xxx')",
parser: Parsers.commaSeparated,
}),
ngMemberLabel: cliparse.option('label', {
required: false,
metavar: 'member_label',
description: 'The member label',
parser: Parsers.ngResourceType,
}),
ngPeerGetConfig: cliparse.flag('config', {
description: 'Get the Wireguard configuration of an external peer',
}),
ngResourceType: cliparse.option('type', {
metavar: 'type',
description: 'Type of resource to look for (NetworkGroup, Member, CleverPeer, ExternalPeer)',
parser: Parsers.ngValidType,
}),
sourceableEnvVarsList: cliparse.flag('add-export', { description: 'Display sourceable env variables setting' }),
logsFormat: getOutputFormatOption(['json-stream']),
activityFormat: getOutputFormatOption(['json-stream']),
Expand Down Expand Up @@ -746,6 +804,60 @@ async function run () {
args: [args.alias],
}, makeDefault.makeDefault);

// NETWORK GROUP COMMANDS
const ngCreateExternalPeerCommand = cliparse.command('external', {
description: 'Create an external peer in a Network Group',
args: [args.ngExternalPeerLabel, args.ngIdOrLabel, args.wgPublicKey],
}, ng.createExternalPeer);
const ngDeleteExternalPeerCommand = cliparse.command('external', {
description: 'Delete an external peer from a Network Group',
args: [args.ngExternalIdOrLabel, args.ngIdOrLabel],
}, ng.deleteExternalPeer);
const ngCreateCommand = cliparse.command('create', {
description: 'Create a Network Group',
args: [args.ngLabel],
privateOptions: [opts.ngMembersIdsToLink, opts.ngDescription, opts.optTags],
commands: [ngCreateExternalPeerCommand],
}, ng.createNg);
const ngDeleteCommand = cliparse.command('delete', {
description: 'Delete a Network Group',
args: [args.ngIdOrLabel],
commands: [ngDeleteExternalPeerCommand],
}, ng.deleteNg);
const ngLinkCommand = cliparse.command('link', {
description: 'Link an application or a database add-on by its ID to a Network Group',
args: [args.ngAnyIdOrLabel, args.ngIdOrLabel],
}, ng.linkToNg);
const ngUnlinkCommand = cliparse.command('unlink', {
description: 'Unlink an application or a database add-on by its ID from a Network Group',
args: [args.ngAnyIdOrLabel, args.ngIdOrLabel],
}, ng.unlinkFromNg);
const ngGetCommand = cliparse.command('get', {
description: 'Get details about a Network Group, a member or a peer',
args: [args.ngAnyIdOrLabel],
options: [opts.ngResourceType, opts.humanJsonOutputFormat],
}, ng.get);
const ngGetConfigCommand = cliparse.command('get-config', {
description: 'Get the Wireguard configuration of a peer in a Network Group',
args: [args.ngExternalIdOrLabel, args.ngIdOrLabel],
options: [opts.humanJsonOutputFormat],
}, ng.getPeerConfig);
const ngSearchCommand = cliparse.command('search', {
description: 'Search Network Groups, members or peers and get their details',
args: [args.ngAnyIdOrLabel],
options: [opts.ngResourceType, opts.humanJsonOutputFormat],
}, ng.search);
/* const ngJoinCommand = cliparse.command('join', {
description: 'Join a Network Group',
args: [args.ngIdOrLabel],
}, ng.joinNg); */
const networkGroupsCommand = cliparse.command('ng', {
description: 'List Network Groups',
options: [opts.orgaIdOrName],
privateOptions: [opts.humanJsonOutputFormat],
commands: [ngCreateCommand, ngDeleteCommand, ngLinkCommand, ngUnlinkCommand, ngGetCommand, ngGetConfigCommand, ngSearchCommand],
}, ng.listNg);

// NOTIFY-EMAIL COMMAND
const addEmailNotificationCommand = cliparse.command('add', {
description: 'Add a new email notification',
Expand Down Expand Up @@ -982,6 +1094,10 @@ async function run () {
commands.push(colorizeExperimentalCommand(kvRawCommand, 'kv'));
}

if (featuresFromConf.ng) {
commands.push(colorizeExperimentalCommand(networkGroupsCommand, 'ng'));
}

// CLI PARSER
const cliParser = cliparse.cli({
name: 'clever',
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ to ask for new features, enhancements or help us to provide them to our communit
You'll find below the first commands to know to connect Clever Tools to your account, get its information and manage some options. Others are developed in dedicated pages:

- [Materia KV](/docs/kv.md)
- [Network Groups](/docs/ng.md)
- [Applications: configuration](/docs/applications-config.md)
- [Applications: management](/docs/applications-management.md)
- [Applications: deployment and lifecycle](/docs/applications-deployment-lifecycle.md)
Expand Down
167 changes: 0 additions & 167 deletions docs/networkgroups/commands.md

This file was deleted.

Loading