Skip to content

Commit

Permalink
bucket notifications - introduce new type Connection to allow encrypt…
Browse files Browse the repository at this point in the history
…ion of auth field

Signed-off-by: Amit Prinz Setter <[email protected]>
  • Loading branch information
alphaprinz committed Jan 19, 2025
1 parent e24c627 commit 9edbb66
Show file tree
Hide file tree
Showing 11 changed files with 675 additions and 16 deletions.
94 changes: 92 additions & 2 deletions docs/NooBaaNonContainerized/NooBaaCLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
1. [Upgrade Start](#upgrade-start)
2. [Upgrade Status](#upgrade-status)
3. [Upgrade History](#upgrade-history)
10. [Global Options](#global-options)
11. [Examples](#examples)
10. [Connections](#connection)
1. [Add Connection](#add-connection)
2. [Update Connection](#update-connection)
3. [Connection Status](#connection-status)
4. [List Connections][#list-connections]
5. [Delete Connection](#delete-connection)
11. [Global Options](#global-options)
12. [Examples](#examples)
1. [Bucket Commands Examples](#bucket-commands-examples)
2. [Account Commands Examples](#account-commands-examples)
3. [White List Server IP Command Example](#white-list-server-ip-command-example)
Expand Down Expand Up @@ -525,6 +531,90 @@ The available history information is an array of upgrade information - upgrade s
noobaa-cli upgrade history
```

## Managing Connections

- **[Add Connection](#add-connection)**: Create new connections with customizable options.
- **[Update Connection](#update-connection)**: Modify the settings and configurations of existing connections.
- **[Connection Status](#connection-status)**: Retrieve the current status and detailed information about a specific connection.
- **[List Connections](#list-connections)**: Display a list of all existing connections.
- **[Delete Connection](#delete-connection)**: Remove unwanted or obsolete connections from the system.

### Add Connection

The `connection add` command is used to create a new connection with customizable options.

#### Usage
```sh
noobaa-cli connection add --from_file
```
#### Flags -

- `from_file`
- Type: String
- Description: Path to a JSON file which includes connection properties. When using `from_file` flag the connection details must only appear inside the options JSON file. See [from file example](#--from-file-flag-usage-example).


### Update Connection

The `connection update` command is used to update an existing bucket with customizable options.

#### Usage
```sh
noobaa-cli connection update --name <connection_name> --key [--value] [--remove_key]
```
#### Flags -
- `name` (Required)
- Type: String
- Description: Specifies the name of the updated connection.

- `key`
- Type: String
- Description: Specifies the key to be updated.

- `value`
- Type: String
- Description: Specifies the new value of the specified key.

- `remove_key`
- Type: Boolean
- Description: Specifies that the specified key should be removed.

### Connection Status

The `connection status` command is used to print the status of the connection.

#### Usage
```sh
noobaa-cli connection status --name <connection_name>
```
#### Flags -
- `name` (Required)
- Type: String
- Description: Specifies the name of the connection.

### List Connections

The `connection list` command is used to display a list of all existing connections.


#### Usage
```sh
noobaa-cli connection list
```

### Delete Connection

The `connection delete` command is used to delete an existing connection.

#### Usage
```sh
noobaa-cli connection delete --name <connection_name>
```
#### Flags -
- `name` (Required)
- Type: String
- Description: Specifies the name of the connection to be deleted.

## Global Options

Global options used by the CLI to define the config directory settings.
Expand Down
56 changes: 55 additions & 1 deletion src/cmd/manage_nsfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ async function main(argv = minimist(process.argv.slice(2))) {
await noobaa_cli_upgrade.manage_upgrade_operations(action, user_input, config_fs);
} else if (type === TYPES.NOTIFICATION) {
await notification_management();
} else if (type === TYPES.CONNECTION) {
await connection_management(action, user_input);
} else {
throw_cli_error(ManageCLIError.InvalidType);
}
Expand Down Expand Up @@ -642,6 +644,19 @@ async function list_config_files(type, wide, show_secrets, filters = {}) {
return config_files_list;
}

/**
* list_connections
* @returns An array with names of all connection files.
*/
async function list_connections() {
let conns = await config_fs.list_connections();
// it inserts undefined for the entry '.noobaa-config-nsfs' and we wish to remove it
// in case the entry was deleted during the list it also inserts undefined
conns = conns.filter(item => item);

return conns;
}

/**
* get_access_keys will return the access_keys and new_access_key according to the user input
* and action
Expand Down Expand Up @@ -725,12 +740,51 @@ async function logging_management() {
}

async function notification_management() {
new notifications_util.Notificator({
await new notifications_util.Notificator({
fs_context: config_fs.fs_context,
connect_files_dir: config_fs.connections_dir_path,
nc_config_fs: config_fs,
}).process_notification_files();
}

async function connection_management(action, user_input) {
manage_nsfs_validations.validate_connection_args(user_input, action);

let response = {};
let data;

switch (action) {
case ACTIONS.ADD:
data = await notifications_util.add_connect_file(user_input, config_fs);
response = { code: ManageCLIResponse.ConnectionCreated, detail: data };
break;
case ACTIONS.DELETE:
await config_fs.delete_connection_config_file(user_input.name);
response = { code: ManageCLIResponse.ConnectionDeleted };
break;
case ACTIONS.UPDATE:
await notifications_util.update_connect_file(user_input.name, user_input.key,
user_input.value, user_input.remove_key, config_fs);
response = { code: ManageCLIResponse.ConnectionUpdated };
break;
case ACTIONS.STATUS:
data = await new notifications_util.Notificator({
fs_context: config_fs.fs_context,
connect_files_dir: config_fs.connections_dir_path,
nc_config_fs: config_fs,
}).parse_connect_file(user_input.name, user_input.decrypt);
response = { code: ManageCLIResponse.ConnectionStatus, detail: data };
break;
case ACTIONS.LIST:
data = await list_connections();
response = { code: ManageCLIResponse.ConnectionList, detail: data };
break;
default:
throw_cli_error(ManageCLIError.InvalidAction);
}

write_stdout_response(response.code, response.detail, response.event_arg);
}

exports.main = main;
if (require.main === module) main();
12 changes: 11 additions & 1 deletion src/manage_nsfs/manage_nsfs_cli_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ManageCLIError.InvalidArgumentType = Object.freeze({

ManageCLIError.InvalidType = Object.freeze({
code: 'InvalidType',
message: 'Invalid type, available types are account, bucket, logging, whitelist, upgrade or notification',
message: 'Invalid type, available types are account, bucket, logging, whitelist, upgrade, notification or connection.',
http_code: 400,
});

Expand Down Expand Up @@ -490,6 +490,16 @@ ManageCLIError.ConfigDirUpdateBlocked = Object.freeze({
http_code: 500,
});

///////////////////////////////
// CONNECTION ERRORS //
///////////////////////////////

ManageCLIError.MissingCliParam = Object.freeze({
code: 'MissingCliParam',
message: 'Required cli parameter is missing.',
http_code: 400,
});

///////////////////////////////
// ERRORS MAPPING //
///////////////////////////////
Expand Down
28 changes: 28 additions & 0 deletions src/manage_nsfs/manage_nsfs_cli_responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ ManageCLIResponse.UpgradeHistory = Object.freeze({
status: {}
});

///////////////////////////////
// CONNECTION RESPONSES //
///////////////////////////////

ManageCLIResponse.ConnectionCreated = Object.freeze({
code: 'ConnectionCreated',
status: {}
});

ManageCLIResponse.ConnectionDeleted = Object.freeze({
code: 'ConnectionDeleted',
});

ManageCLIResponse.ConnectionUpdated = Object.freeze({
code: 'ConnectionUpdated',
status: {}
});

ManageCLIResponse.ConnectionStatus = Object.freeze({
code: 'ConnectionStatus',
status: {}
});

ManageCLIResponse.ConnectionList = Object.freeze({
code: 'ConnectionList',
list: {}
});

///////////////////////////////
// RESPONSES-EVENT MAPPING //
///////////////////////////////
Expand Down
24 changes: 20 additions & 4 deletions src/manage_nsfs/manage_nsfs_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const TYPES = Object.freeze({
LOGGING: 'logging',
DIAGNOSE: 'diagnose',
UPGRADE: 'upgrade',
NOTIFICATION: 'notification'
NOTIFICATION: 'notification',
CONNECTION: 'connection'
});

const ACTIONS = Object.freeze({
Expand Down Expand Up @@ -84,6 +85,14 @@ const VALID_OPTIONS_UPGRADE = {
'history': new Set([...CLI_MUTUAL_OPTIONS])
};

const VALID_OPTIONS_CONNECTION = {
'add': new Set(['name', 'notification_protocol', 'agent_request_object', 'request_options_object', FROM_FILE, ...CLI_MUTUAL_OPTIONS]),
'update': new Set(['name', 'key', 'value', 'remove_key', ...CLI_MUTUAL_OPTIONS]),
'delete': new Set(['name', ...CLI_MUTUAL_OPTIONS]),
'list': new Set(CLI_MUTUAL_OPTIONS),
'status': new Set(['name', 'decrypt', ...CLI_MUTUAL_OPTIONS]),
};


const VALID_OPTIONS_WHITELIST = new Set(['ips', ...CLI_MUTUAL_OPTIONS]);

Expand All @@ -97,7 +106,8 @@ const VALID_OPTIONS = {
from_file_options: VALID_OPTIONS_FROM_FILE,
anonymous_account_options: VALID_OPTIONS_ANONYMOUS_ACCOUNT,
diagnose_options: VALID_OPTIONS_DIAGNOSE,
upgrade_options: VALID_OPTIONS_UPGRADE
upgrade_options: VALID_OPTIONS_UPGRADE,
connection_options: VALID_OPTIONS_CONNECTION,
};

const OPTION_TYPE = {
Expand Down Expand Up @@ -137,8 +147,14 @@ const OPTION_TYPE = {
expected_hosts: 'string',
custom_upgrade_scripts_dir: 'string',
skip_verification: 'boolean',
//notifications
notifications: 'object'
//connection
notification_protocol: 'string',
agent_request_object: 'object',
request_options_object: 'object',
decrypt: 'boolean',
key: 'string',
value: 'string',
remove_key: 'boolean',
};

const BOOLEAN_STRING_VALUES = ['true', 'false'];
Expand Down
Loading

0 comments on commit 9edbb66

Please sign in to comment.