clever-tools 2.8.1 → 2.9.0

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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # clever-tools changelog
2
2
 
3
- ## 2.8.1 (2021-01-10)
3
+ ## 2.9.0 (2022-01-12)
4
+
5
+ * Add NewRelic support in `clever drains`
6
+
7
+ ## 2.8.1 (2022-01-10)
4
8
 
5
9
  * Fix `colors` to `1.4.0`
6
10
 
package/README.md CHANGED
@@ -320,6 +320,7 @@ Where `DRAIN-TYPE` is one of:
320
320
  - `HTTP`: for TCP syslog endpoint (note that this endpoint has optional username/passwordparameters as HTTP Basic Authentication);
321
321
  - `ElasticSearch`: for ElasticSearch endpoint (note that this endpoint requires username/password parameters as HTTP Basic Authentication);
322
322
  - `DatadogHTTP`: for Datadog endpoint (note that this endpoint needs your Datadog API Key).
323
+ - `NewRelicHTTP`: for NewRelic endpoint (note that this endpoint needs your NewRelic API Key).
323
324
 
324
325
  #### ElasticSearch logs drains
325
326
 
@@ -337,6 +338,16 @@ clever drain create DatadogHTTP "https://http-intake.logs.datadoghq.com/v1/input
337
338
 
338
339
  Please note that the `host` query parameter is not mandatory: in the Datadog pipeline configuration, you can map `@source_host` which is the host provided by Clever Cloud in logs as `host` property.
339
340
 
341
+ #### NewRelic logs drains
342
+
343
+ NewRelic has two zones, EU and US. An account on one zone is not available on the other, make sure to target the good EU or US intake endpoint.
344
+
345
+ To create a [NewRelic](https://docs.newrelic.com/docs/logs/log-api/introduction-log-api/) drain, you just need to use:
346
+
347
+ ```sh
348
+ clever drain create NewRelicHTTP "https://log-api.eu.newrelic.com/log/v1" --api-key <API_KEY>
349
+ ```
350
+
340
351
  ### Display help
341
352
 
342
353
  You can display help about each command with `clever help`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clever-tools",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "Command Line Interface for Clever Cloud.",
5
5
  "main": "bin/clever.js",
6
6
  "keywords": [
@@ -8,12 +8,13 @@ const DRAIN_TYPES = [
8
8
  { id: 'HTTP', credentials: 'OPTIONAL' },
9
9
  { id: 'ElasticSearch', credentials: 'MANDATORY' },
10
10
  { id: 'DatadogHTTP' },
11
+ { id: 'NewRelicHTTP', apiKey: 'MANDATORY' },
11
12
  ];
12
13
 
13
14
  function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCredentials, drainTargetConfig) {
14
15
 
15
- if (!authorizeDrainCreation(drainTargetType, drainTargetCredentials)) {
16
- throw new Error("Credentials are: optional for HTTP, mandatory for ElasticSearch and TCPSyslog/UDPSyslog don't need them.");
16
+ if (!authorizeDrainCreation(drainTargetType, drainTargetCredentials, drainTargetConfig)) {
17
+ throw new Error("Credentials are: optional for HTTP, mandatory for ElasticSearch, NewRelicHTTP and TCPSyslog/UDPSyslog don't need them.");
17
18
  }
18
19
 
19
20
  const body = {
@@ -26,20 +27,37 @@ function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCre
26
27
  password: drainTargetCredentials.password || '',
27
28
  };
28
29
  }
30
+ if (keyExist(drainTargetConfig)) {
31
+ body.APIKey = drainTargetConfig.apiKey;
32
+ }
29
33
  return body;
30
34
  }
31
35
 
32
- function authorizeDrainCreation (drainTargetType, drainTargetCredentials) {
36
+ function authorizeDrainCreation (drainTargetType, drainTargetCredentials, drainTargetConfig) {
33
37
  if (drainTypeExists(drainTargetType)) {
34
38
  // retrieve creds for drain type ('mandatory', 'optional', undefined)
35
- const status = credentialsStatus(drainTargetType).credentials;
36
- if (status === 'MANDATORY') {
39
+ const credStatus = credentialsStatus(drainTargetType).credentials;
40
+ const keyStatus = credentialsStatus(drainTargetType).apiKey;
41
+
42
+ if (credStatus === 'MANDATORY') {
37
43
  return credentialsExist(drainTargetCredentials);
38
44
  }
39
- if (status === 'OPTIONAL') {
45
+ if (credStatus === 'OPTIONAL') {
46
+ return true;
47
+ }
48
+ if (!credStatus && !keyStatus) {
49
+ return credentialsEmpty(drainTargetCredentials);
50
+ }
51
+
52
+ if (keyStatus === 'MANDATORY') {
53
+ return keyExist(drainTargetConfig);
54
+ }
55
+ if (keyStatus === 'OPTIONAL') {
40
56
  return true;
41
57
  }
42
- return credentialsEmpty(drainTargetCredentials);
58
+ if (!keyStatus) {
59
+ return keyEmpty(drainTargetConfig);
60
+ }
43
61
  }
44
62
  }
45
63
 
@@ -59,6 +77,14 @@ function credentialsEmpty ({ username, password }) {
59
77
  return username == null && password == null;
60
78
  }
61
79
 
80
+ function keyExist ({ apiKey }) {
81
+ return apiKey != null;
82
+ }
83
+
84
+ function keyEmpty ({ apiKey }) {
85
+ return apiKey == null;
86
+ }
87
+
62
88
  function listDrainTypes () {
63
89
  return autocomplete.words(DRAIN_TYPES.map((type) => type.id));
64
90
  }