Skip to content

Commit

Permalink
BB-616 use the backbeatClient with the same settings as in production
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas2bert committed Nov 13, 2024
1 parent 3ab1648 commit c3b212b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
41 changes: 35 additions & 6 deletions bin/backbeat-cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env node

const program = require('commander');
const BackbeatClient = require('../lib/clients/BackbeatClient.js');
const url = require('url');
const https = require('https');
const http = require('http');
const { createBackbeatClient } = require('../lib/clients/utils.js');

const pkg = require('../package.json');
const werelogs = require('werelogs');
Expand All @@ -15,12 +18,38 @@ werelogs.configure({
dump: config.log.dumpLevel,
});

function parseEndpoint(endpoint) {
try {
const parsedUrl = new url.URL(endpoint);
const transport = parsedUrl.protocol.slice(0, -1);
const host = parsedUrl.hostname;
const port = parsedUrl.port;

return { transport, host, port };
} catch (error) {
throw new Error(`Invalid endpoint URL: ${endpoint}`);
}
}

function createClient() {
return new BackbeatClient({
endpoint: process.env.BACKBEAT_ENDPOINT || 'http://127.0.0.1:8000',
region: process.env.AWS_REGION || 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'accessKey1',
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'verySecretKey1',
const { transport, host, port } = parseEndpoint(process.env.BACKBEAT_ENDPOINT || 'http://127.0.0.1:8000');

let agent;
if (transport === 'https') {
agent = new https.Agent({ keepAlive: true });
} else {
agent = new http.Agent({ keepAlive: true });
}

return createBackbeatClient({
transport,
host,
port,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'accessKey1',
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'verySecretKey1',
},
agent,
});
}

Expand Down
6 changes: 1 addition & 5 deletions docs/backbeat-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ npm install
4. **Create an alias for easy access**

```bash
alias backbeat-cli='node bin/backbeat.cli.js'
alias backbeat-cli='node bin/backbeat-cli.js'
```

## Configuration
Expand All @@ -65,9 +65,6 @@ Before using the Backbeat CLI, configure the necessary environment variables to
- `BACKBEAT_ENDPOINT`: The endpoint URL for the Backbeat service.
*Default*: `http://127.0.0.1:8000`

- `AWS_REGION`: The AWS region to use.
*Default*: `us-east-1`

- `AWS_ACCESS_KEY_ID`: Your AWS access key ID.
*Default*: `accessKey1`

Expand All @@ -78,7 +75,6 @@ You can set these variables in your shell or include them in a configuration fil

```bash
export BACKBEAT_ENDPOINT='http://your-backbeat-endpoint.com'
export AWS_REGION='your-region'
export AWS_ACCESS_KEY_ID='your-access-key-id'
export AWS_SECRET_ACCESS_KEY='your-secret-access-key'
```
Expand Down

0 comments on commit c3b212b

Please sign in to comment.