Skip to content

Commit

Permalink
Merge pull request #80 from internxt/feature/cli-analytics
Browse files Browse the repository at this point in the history
[PB-2038]: Add Rudderstack analytics events to the CLI and WebDAV
  • Loading branch information
PixoDev authored May 9, 2024
2 parents 9cd7552 + fd6ff87 commit 532b1fb
Show file tree
Hide file tree
Showing 24 changed files with 536 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ APP_CRYPTO_SECRET=6KYQBP847D4ATSFA
APP_CRYPTO_SECRET2=8Q8VMUE3BJZV87GT
APP_MAGIC_IV=d139cb9a2cd17092e79e1861cf9d7023
APP_MAGIC_SALT=38dce0391b49efba88dbc8c39ebf868f0267eb110bb0012ab27dc52a528d61b1d1ed9d76f400ff58e3240028442b1eab9bb84e111d9dadd997982dbde9dbd25e
WEBDAV_SERVER_PORT=3005
WEBDAV_SERVER_PORT=3005
RUDDERSTACK_WRITE_KEY=
RUDDERSTACK_DATAPLANE_URL=
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dist
/tmp
/scripts
59 changes: 44 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A CLI tool to interact with yout Internxt encrypted files
* [Installation](#installation)
* [Usage](#usage)
* [Commands](#commands)
* [Current Limitations](#current-limitations)
<!-- tocstop -->

# Installation
Expand All @@ -30,7 +31,7 @@ $ npm install -g @internxt/cli
$ internxt COMMAND
running command...
$ internxt (--version)
@internxt/cli/0.1.19 darwin-arm64 node-v20.10.0
@internxt/cli/1.0.14 darwin-arm64 node-v20.10.0
$ internxt --help [COMMAND]
USAGE
$ internxt COMMAND
Expand All @@ -42,6 +43,7 @@ USAGE

<!-- commands -->
* [`internxt config`](#internxt-config)
* [`internxt create-folder`](#internxt-create-folder)
* [`internxt download`](#internxt-download)
* [`internxt list`](#internxt-list)
* [`internxt login`](#internxt-login)
Expand Down Expand Up @@ -80,7 +82,28 @@ EXAMPLES
$ internxt config
```

_See code: [src/commands/config.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/config.ts)_
_See code: [src/commands/config.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/config.ts)_

## `internxt create-folder`

Create a folder in your Internxt Drive

```
USAGE
$ internxt create-folder --name <value> [--id <value>]
FLAGS
--id=<value> The folder id to create the folder in, defaults to your root folder
--name=<value> (required) The new folder name
DESCRIPTION
Create a folder in your Internxt Drive
EXAMPLES
$ internxt create-folder
```

_See code: [src/commands/create-folder.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/create-folder.ts)_

## `internxt download`

Expand All @@ -103,7 +126,7 @@ EXAMPLES
$ internxt download
```

_See code: [src/commands/download.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/download.ts)_
_See code: [src/commands/download.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/download.ts)_

## `internxt list`

Expand Down Expand Up @@ -137,7 +160,7 @@ EXAMPLES
$ internxt list
```

_See code: [src/commands/list.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/list.ts)_
_See code: [src/commands/list.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/list.ts)_

## `internxt login`

Expand All @@ -163,7 +186,7 @@ EXAMPLES
$ internxt login
```

_See code: [src/commands/login.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/login.ts)_
_See code: [src/commands/login.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/login.ts)_

## `internxt logout`

Expand All @@ -180,7 +203,7 @@ EXAMPLES
$ internxt logout
```

_See code: [src/commands/logout.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/logout.ts)_
_See code: [src/commands/logout.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/logout.ts)_

## `internxt logs`

Expand All @@ -197,7 +220,7 @@ EXAMPLES
$ internxt logs
```

_See code: [src/commands/logs.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/logs.ts)_
_See code: [src/commands/logs.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/logs.ts)_

## `internxt move`

Expand All @@ -222,7 +245,7 @@ EXAMPLES
$ internxt move
```

_See code: [src/commands/move.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/move.ts)_
_See code: [src/commands/move.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/move.ts)_

## `internxt trash`

Expand All @@ -246,7 +269,7 @@ EXAMPLES
$ internxt trash
```

_See code: [src/commands/trash.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/trash.ts)_
_See code: [src/commands/trash.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/trash.ts)_

## `internxt upload`

Expand All @@ -270,24 +293,30 @@ EXAMPLES
$ internxt upload
```

_See code: [src/commands/upload.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/upload.ts)_
_See code: [src/commands/upload.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/upload.ts)_

## `internxt webdav ACTION`

Enable or disable the Internxt CLI WebDav server
Enable,disable, restart or get the status of the Internxt CLI WebDav server

```
USAGE
$ internxt webdav ACTION
DESCRIPTION
Enable or disable the Internxt CLI WebDav server
Enable,disable, restart or get the status of the Internxt CLI WebDav server
EXAMPLES
$ internxt webdav
$ internxt webdav enable
$ internxt webdav disable
$ internxt webdav restart
$ internxt webdav status
```

_See code: [src/commands/webdav.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/webdav.ts)_
_See code: [src/commands/webdav.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/webdav.ts)_

## `internxt whoami`

Expand All @@ -304,7 +333,7 @@ EXAMPLES
$ internxt whoami
```

_See code: [src/commands/whoami.ts](https://github.com/internxt/cli/blob/v0.1.19/src/commands/whoami.ts)_
_See code: [src/commands/whoami.ts](https://github.com/internxt/cli/blob/v1.0.14/src/commands/whoami.ts)_
<!-- commandsstop -->

# Current Limitations
Expand Down
8 changes: 4 additions & 4 deletions WEBDAV.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ No plain data is being sent or is being pulled from the Internxt servers, you ca

![image](https://raw.githubusercontent.com/internxt/cli/main/public/webdav-how-it-works.png)

*We currently have a 5GB size upload limitation per file for both, CLI and WebDAV*
_We currently have a 5GB size upload limitation per file for both, CLI and WebDAV_

## Officially supported WebDav clients

Expand All @@ -40,10 +40,10 @@ Find below the methods that are supported in the latest version of the Internxt
| HEAD ||
| POST ||
| PUT ||
| DELETE | |
| DELETE | |
| PROPFIND ||
| PROPPATCH ||
| MKCOL | |
| MKCOL | |
| COPY ||
| MOVE ||

Expand All @@ -63,4 +63,4 @@ Find below the methods that are supported in the latest version of the Internxt

- We use selfsigned certificates, so all the requests to the WebDav local server are encrypted, since the certificates are selfsigned, many WebDav clients will complain about the certificates trust. You can safely ignore this warning.

- You may encounter issues with the DNS resolution of webdav.local.internxt.com. In such cases, you can safely replace this address with 127.0.0.1, or the corresponding IP where you have deployed the webdav server if you are connecting from another location.
- You may encounter issues with the DNS resolution of webdav.local.internxt.com. In such cases, you can safely replace this address with 127.0.0.1, or the corresponding IP where you have deployed the webdav server if you are connecting from another location.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "PixoDev",
"version": "0.1.19",
"version": "1.0.5",
"description": "Internxt CLI to manage your encrypted storage",
"scripts": {
"build": "tsc",
Expand All @@ -16,7 +16,8 @@
"migrate": "sequelize db:migrate",
"migrate:undo": "sequelize db:migrate:undo",
"publish:npm": "npm run build && npm publish --scope=@internxt --registry=https://registry.npmjs.org/ --access public",
"publish:github": "npm publish"
"publish:github": "npm publish",
"postinstall": "node ./scripts/skip-in-ci.js || internxt webdav restart"
},
"publishConfig": {
"access": "public",
Expand All @@ -40,6 +41,7 @@
"@internxt/lib": "^1.2.1",
"@internxt/sdk": "^1.4.79",
"@oclif/core": "^3",
"@rudderstack/rudder-sdk-node": "^2.0.7",
"axios": "^1.6.7",
"bip39": "^3.1.0",
"body-parser": "^1.20.2",
Expand Down
5 changes: 5 additions & 0 deletions scripts/skip-in-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (process.env.CI) {
process.exit(0);
} else {
process.exit(1);
}
3 changes: 2 additions & 1 deletion src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ErrorUtils } from '../utils/errors.utils';
import { DriveFolderService } from '../services/drive/drive-folder.service';
import { SdkManager } from '../services/sdk-manager.service';
import { DriveDatabaseManager } from '../services/database/drive-database-manager.service';
import { AnalyticsService } from '../services/analytics.service';

export default class Login extends Command {
static readonly args = {};
Expand Down Expand Up @@ -67,7 +68,7 @@ export default class Login extends Command {
await ConfigService.instance.saveUser(Object.assign(loginCredentials, { root_folder_uuid: rootMeta.uuid }));
await DriveDatabaseManager.init();
await DriveDatabaseManager.clean();

AnalyticsService.instance.track('CLILogin', { app: 'internxt-cli', userId: loginCredentials.user.uuid });
CLIUtils.success(`Succesfully logged in to: ${loginCredentials.user.email} `);
}

Expand Down
2 changes: 2 additions & 0 deletions src/commands/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Command } from '@oclif/core';
import { ConfigService } from '../services/config.service';
import { CLIUtils } from '../utils/cli.utils';
import { ErrorUtils } from '../utils/errors.utils';
import { DriveDatabaseManager } from '../services/database/drive-database-manager.service';

export default class Logout extends Command {
static readonly args = {};
Expand All @@ -15,6 +16,7 @@ export default class Logout extends Command {
const user = await ConfigService.instance.readUser();
if (user) {
await ConfigService.instance.clearUser();
await DriveDatabaseManager.clean();
CLIUtils.success('User logged out correctly');
} else {
CLIUtils.error('You are not logged in');
Expand Down
48 changes: 45 additions & 3 deletions src/commands/webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ import { Args, Command, ux } from '@oclif/core';
import { PM2Utils } from '../utils/pm2.utils';
import { CLIUtils } from '../utils/cli.utils';
import { ConfigService } from '../services/config.service';
import { AnalyticsService } from '../services/analytics.service';
import { AuthService } from '../services/auth.service';
import { DriveDatabaseManager } from '../services/database/drive-database-manager.service';
export default class Webdav extends Command {
static readonly description = 'Enable or disable the Internxt CLI WebDav server';
static readonly description = 'Enable,disable, restart or get the status of the Internxt CLI WebDav server';

static examples = ['<%= config.bin %> <%= command.id %>'];
static examples = [
'<%= config.bin %> <%= command.id %> enable',
'<%= config.bin %> <%= command.id %> disable',
'<%= config.bin %> <%= command.id %> restart',
'<%= config.bin %> <%= command.id %> status',
];

static flags = {};

static args = {
action: Args.string({
required: true,
options: ['enable', 'disable'],
options: ['enable', 'disable', 'restart', 'status'],
}),
};
public async enableWebDav() {
Expand All @@ -28,6 +36,8 @@ export default class Webdav extends Command {
CLIUtils.success(
`Internxt WebDav server started successfully on https://${ConfigService.WEBDAV_LOCAL_URL}:${process.env.WEBDAV_SERVER_PORT}`,
);
const authDetails = await AuthService.instance.getAuthDetails();
await AnalyticsService.instance.track('WebDAVEnabled', { app: 'internxt-cli', userId: authDetails.user.uuid });
} else {
ux.log(`WebDav server status: ${ux.colorize('red', status)}`);
}
Expand All @@ -41,6 +51,28 @@ export default class Webdav extends Command {
CLIUtils.success('Internxt WebDav server stopped successfully');
}

public async restartWebDav() {
CLIUtils.doing('Restarting Internxt WebDav server...');
await DriveDatabaseManager.clean();
await PM2Utils.connect();
const { status } = await PM2Utils.webdavServerStatus();
if (status === 'online') {
await PM2Utils.killWebDavServer();
await PM2Utils.startWebDavServer();
CLIUtils.done();
CLIUtils.success('Internxt WebDav server restarted successfully');
} else {
CLIUtils.done();
CLIUtils.error('Internxt WebDav server is not running, cannot restart');
}
}

public async webDAVStatus() {
await PM2Utils.connect();
const { status } = await PM2Utils.webdavServerStatus();
this.log(`Internxt WebDAV server status: ${status}`);
}

public async run(): Promise<void> {
const { args } = await this.parse(Webdav);

Expand All @@ -55,6 +87,16 @@ export default class Webdav extends Command {
await this.disableWebDav();
break;
}

case 'restart': {
await this.restartWebDav();
break;
}

case 'status': {
await this.webDAVStatus();
break;
}
}
} catch (error) {
if (error instanceof Error) {
Expand Down
Loading

0 comments on commit 532b1fb

Please sign in to comment.