Skip to content

Commit 1d52ffb

Browse files
authored
bucket notifications - introduce new type Connection to allow encryption of auth field (#8684)
Signed-off-by: Amit Prinz Setter <[email protected]>
1 parent 1828352 commit 1d52ffb

10 files changed

+732
-17
lines changed

docs/NooBaaNonContainerized/NooBaaCLI.md

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
1. [Upgrade Start](#upgrade-start)
2626
2. [Upgrade Status](#upgrade-status)
2727
3. [Upgrade History](#upgrade-history)
28-
10. [Global Options](#global-options)
29-
11. [Examples](#examples)
28+
10. [Connections](#connection)
29+
1. [Add Connection](#add-connection)
30+
2. [Update Connection](#update-connection)
31+
3. [Connection Status](#connection-status)
32+
4. [List Connections][#list-connections]
33+
5. [Delete Connection](#delete-connection)
34+
11. [Global Options](#global-options)
35+
12. [Examples](#examples)
3036
1. [Bucket Commands Examples](#bucket-commands-examples)
3137
2. [Account Commands Examples](#account-commands-examples)
3238
3. [White List Server IP Command Example](#white-list-server-ip-command-example)
@@ -525,6 +531,109 @@ The available history information is an array of upgrade information - upgrade s
525531
noobaa-cli upgrade history
526532
```
527533

534+
## Managing Connections
535+
536+
A connection file holds information needed to send out a notification to an external server.
537+
The connection files is specified in each notification configuration of the bucket.
538+
539+
- **[Add Connection](#add-connection)**: Create new connections with customizable options.
540+
- **[Update Connection](#update-connection)**: Modify the settings and configurations of existing connections.
541+
- **[Connection Status](#connection-status)**: Retrieve the current status and detailed information about a specific connection.
542+
- **[List Connections](#list-connections)**: Display a list of all existing connections.
543+
- **[Delete Connection](#delete-connection)**: Remove unwanted or obsolete connections from the system.
544+
545+
### Add Connection
546+
547+
The `connection add` command is used to create a new connection with customizable options.
548+
549+
#### Usage
550+
```sh
551+
noobaa-cli connection add --from_file
552+
```
553+
#### Flags -
554+
555+
- `name` (Required)
556+
- Type: String
557+
- Description: A name to identify the connection.
558+
559+
- `notification_protocol` (Required)
560+
- Type: String
561+
- Enum: http | https | kafka
562+
- Description - Target external server's protocol.
563+
564+
- `agent_request_object`
565+
- Type: Object
566+
- Description: An object given as options to node http(s) agent.
567+
568+
- `request_options_object`
569+
- Type: Object
570+
- Description: An object given as options to node http(s) request. If "auth" field is specified, it's value is encrypted.
571+
572+
- `from_file`
573+
- Type: String
574+
- 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 example below.
575+
576+
### Update Connection
577+
578+
The `connection update` command is used to update an existing bucket with customizable options.
579+
580+
#### Usage
581+
```sh
582+
noobaa-cli connection update --name <connection_name> --key [--value] [--remove_key]
583+
```
584+
#### Flags -
585+
- `name` (Required)
586+
- Type: String
587+
- Description: Specifies the name of the updated connection.
588+
589+
- `key` (Required)
590+
- Type: String
591+
- Description: Specifies the key to be updated.
592+
593+
- `value`
594+
- Type: String
595+
- Description: Specifies the new value of the specified key.
596+
597+
- `remove_key`
598+
- Type: Boolean
599+
- Description: Specifies that the specified key should be removed.
600+
601+
### Connection Status
602+
603+
The `connection status` command is used to print the status of the connection.
604+
605+
#### Usage
606+
```sh
607+
noobaa-cli connection status --name <connection_name>
608+
```
609+
#### Flags -
610+
- `name` (Required)
611+
- Type: String
612+
- Description: Specifies the name of the connection.
613+
614+
### List Connections
615+
616+
The `connection list` command is used to display a list of all existing connections.
617+
618+
619+
#### Usage
620+
```sh
621+
noobaa-cli connection list
622+
```
623+
624+
### Delete Connection
625+
626+
The `connection delete` command is used to delete an existing connection.
627+
628+
#### Usage
629+
```sh
630+
noobaa-cli connection delete --name <connection_name>
631+
```
632+
#### Flags -
633+
- `name` (Required)
634+
- Type: String
635+
- Description: Specifies the name of the connection to be deleted.
636+
528637
## Global Options
529638

530639
Global options used by the CLI to define the config directory settings.
@@ -658,7 +767,21 @@ sudo noobaa-cli bucket delete --name bucket1 2>/dev/null
658767
```
659768

660769
-----
770+
### Connection Commands Examples
771+
772+
#### Create Connection in CLI
773+
774+
```sh
775+
sudo noobaa-cli connection add --name conn1 --notification_protocol http --request_options_object '{"auth": "user:passw"}'
776+
```
661777

778+
#### Update Connection Field
779+
780+
```sh
781+
sudo noobaa-cli connection update --name conn1 --key request_options_object --value '{"auth":"user2:pw2"}'
782+
```
783+
784+
-----
662785
#### `--from-file` flag usage example
663786

664787
Using `from_file` flag:
@@ -695,6 +818,21 @@ sudo noobaa-cli account add --from_file <options_account_JSON_file_path>
695818
sudo noobaa-cli bucket add --from_file <options_bucket_JSON_file_path>
696819
```
697820

821+
##### 2. Create JSON file for connection:
822+
823+
```json
824+
{
825+
"name": "http_conn",
826+
"notification_protocol": "http",
827+
"agent_request_object": {"host": "localhost", "port": 9999, "timeout": 100},
828+
"request_options_object": {"auth": "user:passw", "path": "/query"}
829+
}
830+
```
831+
832+
```bash
833+
sudo noobaa-cli connection add --from_file <options_connection_JSON_file_path>
834+
```
835+
698836
------
699837

700838
### White List Server IP command example

src/cmd/manage_nsfs.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ async function main(argv = minimist(process.argv.slice(2))) {
7474
await noobaa_cli_upgrade.manage_upgrade_operations(action, user_input, config_fs);
7575
} else if (type === TYPES.NOTIFICATION) {
7676
await notification_management();
77+
} else if (type === TYPES.CONNECTION) {
78+
await connection_management(action, user_input);
7779
} else {
7880
throw_cli_error(ManageCLIError.InvalidType);
7981
}
@@ -642,6 +644,19 @@ async function list_config_files(type, wide, show_secrets, filters = {}) {
642644
return config_files_list;
643645
}
644646

647+
/**
648+
* list_connections
649+
* @returns An array with names of all connection files.
650+
*/
651+
async function list_connections() {
652+
let conns = await config_fs.list_connections();
653+
// it inserts undefined for the entry '.noobaa-config-nsfs' and we wish to remove it
654+
// in case the entry was deleted during the list it also inserts undefined
655+
conns = conns.filter(item => item);
656+
657+
return conns;
658+
}
659+
645660
/**
646661
* get_access_keys will return the access_keys and new_access_key according to the user input
647662
* and action
@@ -725,12 +740,51 @@ async function logging_management() {
725740
}
726741

727742
async function notification_management() {
728-
new notifications_util.Notificator({
743+
await new notifications_util.Notificator({
729744
fs_context: config_fs.fs_context,
730745
connect_files_dir: config_fs.connections_dir_path,
731746
nc_config_fs: config_fs,
732747
}).process_notification_files();
733748
}
734749

750+
async function connection_management(action, user_input) {
751+
manage_nsfs_validations.validate_connection_args(user_input, action);
752+
753+
let response = {};
754+
let data;
755+
756+
switch (action) {
757+
case ACTIONS.ADD:
758+
data = await notifications_util.add_connect_file(user_input, config_fs);
759+
response = { code: ManageCLIResponse.ConnectionCreated, detail: data };
760+
break;
761+
case ACTIONS.DELETE:
762+
await config_fs.delete_connection_config_file(user_input.name);
763+
response = { code: ManageCLIResponse.ConnectionDeleted };
764+
break;
765+
case ACTIONS.UPDATE:
766+
await notifications_util.update_connect_file(user_input.name, user_input.key,
767+
user_input.value, user_input.remove_key, config_fs);
768+
response = { code: ManageCLIResponse.ConnectionUpdated };
769+
break;
770+
case ACTIONS.STATUS:
771+
data = await new notifications_util.Notificator({
772+
fs_context: config_fs.fs_context,
773+
connect_files_dir: config_fs.connections_dir_path,
774+
nc_config_fs: config_fs,
775+
}).parse_connect_file(user_input.name, user_input.decrypt);
776+
response = { code: ManageCLIResponse.ConnectionStatus, detail: data };
777+
break;
778+
case ACTIONS.LIST:
779+
data = await list_connections();
780+
response = { code: ManageCLIResponse.ConnectionList, detail: data };
781+
break;
782+
default:
783+
throw_cli_error(ManageCLIError.InvalidAction);
784+
}
785+
786+
write_stdout_response(response.code, response.detail, response.event_arg);
787+
}
788+
735789
exports.main = main;
736790
if (require.main === module) main();

src/manage_nsfs/manage_nsfs_cli_errors.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ManageCLIError.InvalidArgumentType = Object.freeze({
9494

9595
ManageCLIError.InvalidType = Object.freeze({
9696
code: 'InvalidType',
97-
message: 'Invalid type, available types are account, bucket, logging, whitelist, upgrade or notification',
97+
message: 'Invalid type, available types are account, bucket, logging, whitelist, upgrade, notification or connection.',
9898
http_code: 400,
9999
});
100100

@@ -490,6 +490,16 @@ ManageCLIError.ConfigDirUpdateBlocked = Object.freeze({
490490
http_code: 500,
491491
});
492492

493+
///////////////////////////////
494+
// CONNECTION ERRORS //
495+
///////////////////////////////
496+
497+
ManageCLIError.MissingCliParam = Object.freeze({
498+
code: 'MissingCliParam',
499+
message: 'Required cli parameter is missing.',
500+
http_code: 400,
501+
});
502+
493503
///////////////////////////////
494504
// ERRORS MAPPING //
495505
///////////////////////////////

src/manage_nsfs/manage_nsfs_cli_responses.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ ManageCLIResponse.UpgradeHistory = Object.freeze({
144144
status: {}
145145
});
146146

147+
///////////////////////////////
148+
// CONNECTION RESPONSES //
149+
///////////////////////////////
150+
151+
ManageCLIResponse.ConnectionCreated = Object.freeze({
152+
code: 'ConnectionCreated',
153+
status: {}
154+
});
155+
156+
ManageCLIResponse.ConnectionDeleted = Object.freeze({
157+
code: 'ConnectionDeleted',
158+
});
159+
160+
ManageCLIResponse.ConnectionUpdated = Object.freeze({
161+
code: 'ConnectionUpdated',
162+
status: {}
163+
});
164+
165+
ManageCLIResponse.ConnectionStatus = Object.freeze({
166+
code: 'ConnectionStatus',
167+
status: {}
168+
});
169+
170+
ManageCLIResponse.ConnectionList = Object.freeze({
171+
code: 'ConnectionList',
172+
list: {}
173+
});
174+
147175
///////////////////////////////
148176
// RESPONSES-EVENT MAPPING //
149177
///////////////////////////////

src/manage_nsfs/manage_nsfs_constants.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const TYPES = Object.freeze({
99
LOGGING: 'logging',
1010
DIAGNOSE: 'diagnose',
1111
UPGRADE: 'upgrade',
12-
NOTIFICATION: 'notification'
12+
NOTIFICATION: 'notification',
13+
CONNECTION: 'connection'
1314
});
1415

1516
const ACTIONS = Object.freeze({
@@ -84,6 +85,16 @@ const VALID_OPTIONS_UPGRADE = {
8485
'history': new Set([...CLI_MUTUAL_OPTIONS])
8586
};
8687

88+
const VALID_OPTIONS_NOTIFICATION = {};
89+
90+
const VALID_OPTIONS_CONNECTION = {
91+
'add': new Set(['name', 'notification_protocol', 'agent_request_object', 'request_options_object', FROM_FILE, ...CLI_MUTUAL_OPTIONS]),
92+
'update': new Set(['name', 'key', 'value', 'remove_key', ...CLI_MUTUAL_OPTIONS]),
93+
'delete': new Set(['name', ...CLI_MUTUAL_OPTIONS]),
94+
'list': new Set(CLI_MUTUAL_OPTIONS),
95+
'status': new Set(['name', 'decrypt', ...CLI_MUTUAL_OPTIONS]),
96+
};
97+
8798

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

@@ -97,7 +108,9 @@ const VALID_OPTIONS = {
97108
from_file_options: VALID_OPTIONS_FROM_FILE,
98109
anonymous_account_options: VALID_OPTIONS_ANONYMOUS_ACCOUNT,
99110
diagnose_options: VALID_OPTIONS_DIAGNOSE,
100-
upgrade_options: VALID_OPTIONS_UPGRADE
111+
upgrade_options: VALID_OPTIONS_UPGRADE,
112+
notification_options: VALID_OPTIONS_NOTIFICATION,
113+
connection_options: VALID_OPTIONS_CONNECTION,
101114
};
102115

103116
const OPTION_TYPE = {
@@ -137,8 +150,14 @@ const OPTION_TYPE = {
137150
expected_hosts: 'string',
138151
custom_upgrade_scripts_dir: 'string',
139152
skip_verification: 'boolean',
140-
//notifications
141-
notifications: 'object'
153+
//connection
154+
notification_protocol: 'string',
155+
agent_request_object: 'string',
156+
request_options_object: 'string',
157+
decrypt: 'boolean',
158+
key: 'string',
159+
value: 'string',
160+
remove_key: 'boolean',
142161
};
143162

144163
const BOOLEAN_STRING_VALUES = ['true', 'false'];

0 commit comments

Comments
 (0)