forked from influxdata/influxdb-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonboarding.mjs
executable file
·34 lines (32 loc) · 920 Bytes
/
onboarding.mjs
1
2
3
4
5
6
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
#!/usr/bin/env node
/*
This example setups a new INFLUXDB database with user,organization
and bucket that can be then used in examples. All values that used
for onboarding are defined in ./env.ts .
*/
import {InfluxDB} from '@influxdata/influxdb-client'
import {SetupAPI} from '@influxdata/influxdb-client-apis'
import {url, username, password, org, bucket, token} from './env.mjs'
console.log('*** ONBOARDING ***')
const setupApi = new SetupAPI(new InfluxDB({url}))
try {
const {allowed} = await setupApi.getSetup()
if (allowed) {
await setupApi.postSetup({
body: {
org,
bucket,
username,
password,
token,
},
})
console.log(`InfluxDB '${url}' is now onboarded.`)
} else {
console.log(`InfluxDB '${url}' has been already onboarded.`)
}
console.log('\nFinished SUCCESS')
} catch (e) {
console.error(e)
console.log('\nFinished ERROR')
}