@scaleway/configuration-loader 0.1.0-beta.7 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/config-loader.js +2 -2
- package/dist/env.js +3 -3
- package/dist/index.cjs +11 -10
- package/dist/index.d.ts +57 -56
- package/dist/path-resolver.js +3 -3
- package/dist/yml-loader.js +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.0.1 (2024-02-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @scaleway/configuration-loader
|
|
9
|
+
|
|
10
|
+
## 1.0.0 (2023-02-21)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- prepare v1 release ([#454](https://github.com/scaleway/scaleway-sdk-js/issues/454)) ([57bc014](https://github.com/scaleway/scaleway-sdk-js/commit/57bc014556338ba9fa7eca2a2d4179f5ff8383be))
|
|
15
|
+
|
|
6
16
|
## 0.1.0-beta.7 (2023-01-27)
|
|
7
17
|
|
|
8
18
|
### Features
|
package/dist/config-loader.js
CHANGED
|
@@ -42,7 +42,7 @@ const loadProfileFromEnvironmentValues = () => ({
|
|
|
42
42
|
* @public
|
|
43
43
|
*/
|
|
44
44
|
const loadAllProfilesFromConfigurationFile = params => {
|
|
45
|
-
const filePath =
|
|
45
|
+
const filePath = params?.filepath ?? resolveConfigurationFilePath();
|
|
46
46
|
if (typeof filePath !== 'string' || filePath.length === 0) {
|
|
47
47
|
throw new Error('Could not find the path to the configuration file.');
|
|
48
48
|
}
|
|
@@ -67,7 +67,7 @@ const loadAllProfilesFromConfigurationFile = params => {
|
|
|
67
67
|
*/
|
|
68
68
|
const loadProfileFromConfigurationFile = params => {
|
|
69
69
|
const configs = loadAllProfilesFromConfigurationFile(params);
|
|
70
|
-
const profileName =
|
|
70
|
+
const profileName = params?.profileName ?? 'default';
|
|
71
71
|
const profileMap = configs[profileName];
|
|
72
72
|
if (typeof profileMap !== 'object') {
|
|
73
73
|
throw new Error(`Could not find the desired profile '${profileName}' in the configuration file.`);
|
package/dist/env.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Environment Key.
|
|
3
3
|
*/
|
|
4
|
-
let EnvironmentKey
|
|
5
|
-
(function (EnvironmentKey) {
|
|
4
|
+
let EnvironmentKey = /*#__PURE__*/function (EnvironmentKey) {
|
|
6
5
|
EnvironmentKey["ScwConfigPath"] = "SCW_CONFIG_PATH";
|
|
7
6
|
EnvironmentKey["ScwAccessKey"] = "SCW_ACCESS_KEY";
|
|
8
7
|
EnvironmentKey["ScwSecretKey"] = "SCW_SECRET_KEY";
|
|
@@ -11,6 +10,7 @@ let EnvironmentKey;
|
|
|
11
10
|
EnvironmentKey["ScwDefaultProjectId"] = "SCW_DEFAULT_PROJECT_ID";
|
|
12
11
|
EnvironmentKey["ScwDefaultRegion"] = "SCW_DEFAULT_REGION";
|
|
13
12
|
EnvironmentKey["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
|
|
14
|
-
|
|
13
|
+
return EnvironmentKey;
|
|
14
|
+
}({});
|
|
15
15
|
|
|
16
16
|
export { EnvironmentKey };
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var process = require('process');
|
|
4
|
-
var
|
|
5
|
-
var path = require('path');
|
|
4
|
+
var node_os = require('node:os');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var node_process = require('node:process');
|
|
6
7
|
var fs = require('fs');
|
|
7
8
|
|
|
8
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -27,8 +28,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
27
28
|
/**
|
|
28
29
|
* Environment Key.
|
|
29
30
|
*/
|
|
30
|
-
let EnvironmentKey
|
|
31
|
-
(function (EnvironmentKey) {
|
|
31
|
+
let EnvironmentKey = /*#__PURE__*/function (EnvironmentKey) {
|
|
32
32
|
EnvironmentKey["ScwConfigPath"] = "SCW_CONFIG_PATH";
|
|
33
33
|
EnvironmentKey["ScwAccessKey"] = "SCW_ACCESS_KEY";
|
|
34
34
|
EnvironmentKey["ScwSecretKey"] = "SCW_SECRET_KEY";
|
|
@@ -37,7 +37,8 @@ let EnvironmentKey;
|
|
|
37
37
|
EnvironmentKey["ScwDefaultProjectId"] = "SCW_DEFAULT_PROJECT_ID";
|
|
38
38
|
EnvironmentKey["ScwDefaultRegion"] = "SCW_DEFAULT_REGION";
|
|
39
39
|
EnvironmentKey["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
|
|
40
|
-
|
|
40
|
+
return EnvironmentKey;
|
|
41
|
+
}({});
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Gets the Scaleway directory.
|
|
@@ -47,11 +48,11 @@ let EnvironmentKey;
|
|
|
47
48
|
* @internal
|
|
48
49
|
*/
|
|
49
50
|
const getScwConfigurationDirectory = () => {
|
|
50
|
-
const xdgConfigPath =
|
|
51
|
+
const xdgConfigPath = node_process.env.XDG_CONFIG_HOME;
|
|
51
52
|
if (typeof xdgConfigPath === 'string' && xdgConfigPath.length > 0) {
|
|
52
53
|
return path__namespace.join(xdgConfigPath, 'scw');
|
|
53
54
|
}
|
|
54
|
-
return path__namespace.join(
|
|
55
|
+
return path__namespace.join(node_os.homedir(), '.config', 'scw');
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
/**
|
|
@@ -63,7 +64,7 @@ const getScwConfigurationDirectory = () => {
|
|
|
63
64
|
*/
|
|
64
65
|
const resolveConfigurationFilePath = () => {
|
|
65
66
|
// Try path defined by user in env variables
|
|
66
|
-
const envFilePath =
|
|
67
|
+
const envFilePath = node_process.env[EnvironmentKey.ScwConfigPath];
|
|
67
68
|
if (typeof envFilePath === 'string' && envFilePath.length > 0) {
|
|
68
69
|
return envFilePath;
|
|
69
70
|
}
|
|
@@ -77,9 +78,9 @@ const DETECT_SECTION_REGEX = /^\s*([^]+):\s*$/;
|
|
|
77
78
|
const DETECT_ITEM_REGEX = /^\s*(.+?)\s*:\s*(.+?)\s*$/;
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* Converts
|
|
81
|
+
* Converts YAML to configuration map.
|
|
81
82
|
*
|
|
82
|
-
* @param input -
|
|
83
|
+
* @param input - YAML string
|
|
83
84
|
* @returns The configuration map
|
|
84
85
|
*
|
|
85
86
|
* @internal
|
package/dist/index.d.ts
CHANGED
|
@@ -4,65 +4,66 @@
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
type Profile = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* You need an access key and a secret key to connect to Scaleway API.
|
|
9
|
+
* Generate your token at the following address: {@link https://console.scaleway.com/project/credentials}
|
|
10
|
+
*/
|
|
11
|
+
accessKey?: string
|
|
12
|
+
/**
|
|
13
|
+
* APIURL overrides the API URL of the Scaleway API to the given URL.
|
|
14
|
+
* Change that if you want to direct requests to a different endpoint.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue `https://api.scaleway.com`
|
|
17
|
+
*/
|
|
18
|
+
apiURL?: string
|
|
19
|
+
/**
|
|
20
|
+
* Your organization ID is the identifier of your account inside Scaleway infrastructure.
|
|
21
|
+
*/
|
|
22
|
+
defaultOrganizationId?: string
|
|
23
|
+
/**
|
|
24
|
+
* Your project ID is the identifier of the project your resources are attached to.
|
|
25
|
+
*/
|
|
26
|
+
defaultProjectId?: string
|
|
27
|
+
/**
|
|
28
|
+
* A region is represented as a geographical area such as France (Paris) or the Netherlands (Amsterdam).
|
|
29
|
+
* It can contain multiple availability zones.
|
|
30
|
+
*
|
|
31
|
+
* Examples: fr-par, nl-ams.
|
|
32
|
+
*/
|
|
33
|
+
defaultRegion?: string
|
|
34
|
+
/**
|
|
35
|
+
* A region can be split into many availability zones (AZ).
|
|
36
|
+
* Latency between multiple AZ of the same region are low as they have a common network layer.
|
|
37
|
+
*
|
|
38
|
+
* Examples: fr-par-1, nl-ams-1
|
|
39
|
+
*/
|
|
40
|
+
defaultZone?: string
|
|
41
|
+
/**
|
|
42
|
+
* The secret key is the value that can be used to authenticate against the API (the value used in X-Auth-Token HTTP-header).
|
|
43
|
+
* The secret key MUST remain secret and not given to anyone or published online.
|
|
44
|
+
*/
|
|
45
|
+
secretKey?: string
|
|
46
|
+
}
|
|
47
47
|
/** Parameters to load the all the profiles from the configuration file */
|
|
48
48
|
type AllProfilesFromFileParams = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
49
|
+
/**
|
|
50
|
+
* The path at which to locate the configuration file.
|
|
51
|
+
*
|
|
52
|
+
* Defaults to the value of the `SCW_CONFIG_PATH` environment variable
|
|
53
|
+
* or `~/.scw/config` otherwise.
|
|
54
|
+
*/
|
|
55
|
+
filepath?: string
|
|
56
|
+
}
|
|
57
|
+
|
|
57
58
|
/** Parameters to load the profile from the configuration file */
|
|
58
59
|
type ProfileFromFileParams = AllProfilesFromFileParams & {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
60
|
+
/**
|
|
61
|
+
* Name of the profile to load.
|
|
62
|
+
*
|
|
63
|
+
* @defaultValue `default`
|
|
64
|
+
* */
|
|
65
|
+
profileName?: 'default' | string
|
|
66
|
+
}
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* Loads profile from environment values.
|
|
@@ -98,4 +99,4 @@ declare const loadAllProfilesFromConfigurationFile: (params?: Readonly<AllProfil
|
|
|
98
99
|
*/
|
|
99
100
|
declare const loadProfileFromConfigurationFile: (params?: Readonly<ProfileFromFileParams>) => Profile;
|
|
100
101
|
|
|
101
|
-
export { AllProfilesFromFileParams, Profile, ProfileFromFileParams, loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
|
102
|
+
export { type AllProfilesFromFileParams, type Profile, type ProfileFromFileParams, loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
package/dist/path-resolver.js
CHANGED
package/dist/yml-loader.js
CHANGED
|
@@ -5,9 +5,9 @@ const DETECT_SECTION_REGEX = /^\s*([^]+):\s*$/;
|
|
|
5
5
|
const DETECT_ITEM_REGEX = /^\s*(.+?)\s*:\s*(.+?)\s*$/;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Converts
|
|
8
|
+
* Converts YAML to configuration map.
|
|
9
9
|
*
|
|
10
|
-
* @param input -
|
|
10
|
+
* @param input - YAML string
|
|
11
11
|
* @returns The configuration map
|
|
12
12
|
*
|
|
13
13
|
* @internal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleway/configuration-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Load configuration via file or environment for NodeJS.",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^18.11.18"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "be0ae25435fdaf070491fd28121cfe844d907b10"
|
|
25
25
|
}
|