-
Notifications
You must be signed in to change notification settings - Fork 80
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
NC | S3 internal APIs gaps | Add versions CLI command | S3 internal API refactoring #8800
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,9 @@ | |
3. [Connection Status](#connection-status) | ||
4. [List Connections][#list-connections] | ||
5. [Delete Connection](#delete-connection) | ||
11. [Global Options](#global-options) | ||
12. [Examples](#examples) | ||
11. [Fetching Versions Status](#fetching-versions-status) | ||
12. [Global Options](#global-options) | ||
13. [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) | ||
|
@@ -634,6 +635,19 @@ noobaa-cli connection delete --name <connection_name> | |
- Type: String | ||
- Description: Specifies the name of the connection to be deleted. | ||
|
||
|
||
## Fetching Versions Status | ||
|
||
The `versions` command is used to print the status of the rpm_source_code_versions, host_running_service_versions and config_dir_version. | ||
- rpm_source_code_versions consists of the package_version and the config_fs version. | ||
- host_running_service_versions consists of the running service package_version and config_fs version. | ||
- config_dir_version is the current config_dir_version registered in system.json. | ||
|
||
#### Usage | ||
```sh | ||
noobaa-cli versions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to make sure - that there will be no additional actions (we could |
||
``` | ||
|
||
## Global Options | ||
|
||
Global options used by the CLI to define the config directory settings. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ const s3_rest = require('./s3/s3_rest'); | |
const blob_rest = require('./blob/blob_rest'); | ||
const sts_rest = require('./sts/sts_rest'); | ||
const iam_rest = require('./iam/iam_rest'); | ||
const { CONFIG_DIR_VERSION } = require('../sdk/config_fs'); | ||
const lambda_rest = require('./lambda/lambda_rest'); | ||
const endpoint_utils = require('./endpoint_utils'); | ||
const FuncSDK = require('../sdk/func_sdk'); | ||
|
@@ -60,6 +61,13 @@ const SERVICES_TYPES_ENUM = Object.freeze({ | |
METRICS: 'METRICS' | ||
}); | ||
|
||
const INTERNAL_APIS_OBJ = Object.freeze({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment about this object? |
||
VERSION: 'version', | ||
CONFIG_FS_VERSION: 'config_fs_version', | ||
ENDPOINT_FORK_ID: 'endpoint_fork_id', | ||
TOTAL_FORK_COUNT: 'total_fork_count' | ||
}); | ||
|
||
const new_umask = process.env.NOOBAA_ENDPOINT_UMASK || 0o000; | ||
const old_umask = process.umask(new_umask); | ||
let fork_count; | ||
|
@@ -291,15 +299,17 @@ function create_endpoint_handler(server_type, init_request_sdk, { virtual_hosts, | |
return lambda_rest_handler(req, res); | ||
} else if (req.headers['x-ms-version']) { | ||
return blob_rest_handler(req, res); | ||
} else if (req.url.startsWith('/total_fork_count')) { | ||
return fork_count_handler(req, res); | ||
} else if (req.url.startsWith('/endpoint_fork_id')) { | ||
return endpoint_fork_id_handler(req, res); | ||
} else if (req.url.startsWith('/_/')) { | ||
// internals non S3 requests | ||
const api = req.url.slice('/_/'.length); | ||
if (api === 'version') { | ||
if (api === INTERNAL_APIS_OBJ.VERSION) { | ||
return version_handler(req, res); | ||
} else if (api === INTERNAL_APIS_OBJ.CONFIG_FS_VERSION) { | ||
return config_fs_version_handler(req, res); | ||
} else if (api === INTERNAL_APIS_OBJ.ENDPOINT_FORK_ID) { | ||
return endpoint_fork_id_handler(req, res); | ||
} else if (api === INTERNAL_APIS_OBJ.TOTAL_FORK_COUNT) { | ||
return fork_count_handler(req, res); | ||
} else { | ||
return internal_api_error(req, res, `Unknown API call ${api}`); | ||
} | ||
|
@@ -351,6 +361,21 @@ function version_handler(req, res) { | |
res.end(noobaa_package_version); | ||
} | ||
|
||
/** | ||
* config_fs_version_handler returns the version of configFS | ||
* this is not the actual config dir version | ||
* this is the version that NooBaa targets for writing configuration files. | ||
* @param {EndpointRequest} req | ||
* @param {import('http').ServerResponse} res | ||
*/ | ||
function config_fs_version_handler(req, res) { | ||
const config_dir_version = CONFIG_DIR_VERSION; | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.setHeader('Content-Length', Buffer.byteLength(config_dir_version)); | ||
res.end(config_dir_version); | ||
} | ||
|
||
/** | ||
* internal_api_error returns an internal api error response | ||
* @param {EndpointRequest} req | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* Copyright (C) 2024 NooBaa */ | ||
'use strict'; | ||
|
||
const dbg = require('../util/debug_module')(__filename); | ||
const config = require('../../config'); | ||
const pkg = require('../../package.json'); | ||
const http_utils = require('../util/http_utils'); | ||
const buffer_utils = require('../util/buffer_utils'); | ||
const { write_stdout_response } = require('./manage_nsfs_cli_utils'); | ||
const { ManageCLIResponse } = require('./manage_nsfs_cli_responses'); | ||
|
||
//////////////////////// | ||
// VERSIONS MANAGEMENT // | ||
//////////////////////// | ||
|
||
/** | ||
* versions_management | ||
*/ | ||
async function versions_management(config_fs) { | ||
const system_json = await config_fs.get_system_config_file({ silent_if_missing: true }); | ||
const versions = { | ||
rpm_source_code_versions: { | ||
package_version: pkg.version, | ||
config_fs_version: config_fs.config_dir_version, | ||
}, | ||
host_running_service_versions: await get_running_service_versions(), | ||
config_dir_version: system_json?.config_directory.config_dir_version || 'unknown' | ||
}; | ||
|
||
const response = { code: ManageCLIResponse.VersionsStatus, detail: versions }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @romayalon |
||
write_stdout_response(response.code, response.detail); | ||
} | ||
|
||
/** | ||
* get_running_service_versions returns the versions of the running service | ||
* @returns {Promise<Object>} | ||
*/ | ||
async function get_running_service_versions() { | ||
const host_service_versions = {}; | ||
try { | ||
const package_version_api = '/_/version'; | ||
const config_dir_version_api = '/_/config_fs_version'; | ||
host_service_versions.package_version = await get_version_api_response(package_version_api); | ||
host_service_versions.config_fs_version = await get_version_api_response(config_dir_version_api); | ||
} catch (err) { | ||
dbg.warn('could not receive versions response', err); | ||
} | ||
return host_service_versions; | ||
} | ||
|
||
/** | ||
* get_version_api_response runs a GET request to the given api and returns the response | ||
* @param {string} api | ||
* @returns | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing parameter? |
||
*/ | ||
async function get_version_api_response(api) { | ||
let version; | ||
try { | ||
const res = await http_utils.make_https_request({ | ||
hostname: 'localhost', | ||
port: config.ENDPOINT_SSL_PORT, | ||
path: api, | ||
method: 'GET', | ||
rejectUnauthorized: false | ||
}); | ||
|
||
if (res.statusCode === 200) { | ||
const buffer = await buffer_utils.read_stream_join(res); | ||
version = buffer.toString('utf8'); | ||
} else if (res.statusCode >= 500) { | ||
const buffer = await buffer_utils.read_stream_join(res); | ||
const body = buffer.toString('utf8'); | ||
dbg.log0(`get_version_api_response received an error from ${api} api, skipping', ${body}`); | ||
} | ||
} catch (err) { | ||
dbg.warn('get_version_api_response: err', err); | ||
} | ||
return version?.trim() || 'unknown'; | ||
} | ||
|
||
// EXPORTS | ||
exports.versions_management = versions_management; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add the var name style for easier reading, for example: