Skip to content

Commit 4ac67cd

Browse files
committed
fix uuid generation and retrieval
1 parent 15387b6 commit 4ac67cd

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ token.txt
77
app_id.txt
88
app_secret.txt
99
firewall_defaults.json
10+
uuid.txt
1011
.env
1112
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
1213

client_common/package-lock.json

Lines changed: 20 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client_common/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"dependencies": {
2424
"@grpc/grpc-js": "^1.3.2",
2525
"@grpc/proto-loader": "^0.6.2",
26-
"dotenv": "^16.5.0"
26+
"dotenv": "^16.5.0",
27+
"uuid": "^11.1.0"
2728
},
2829
"husky": {
2930
"hooks": {

client_common/src/auth.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {AppGuardService} from "./appguard";
22
import {AuthorizationRequest} from "./proto/appguard_commands/AuthorizationRequest";
33
import {FirewallDefaults} from "./proto/appguard_commands/FirewallDefaults";
4+
import { v4 as uuidv4 } from 'uuid';
45

56
export const TOKEN_FILE = process.cwd() + '/../token.txt'
67
export const APP_ID_FILE = process.cwd() + '/../app_id.txt'
@@ -18,12 +19,13 @@ export class AuthHandler {
1819
constructor(client: AppGuardService) {
1920
require('dotenv').config()
2021

21-
let uuid: string = fs.readFileSync(UUID_FILE, 'utf8');
22-
if (!uuid || uuid.trim() === '') {
23-
uuid = crypto.randomUUID();
24-
fs.writeFileSync(UUID_FILE, uuid, {flag: 'w'});
22+
let uuid_exists: boolean = fs.existsSync(UUID_FILE);
23+
if (uuid_exists) {
24+
this.uuid = fs.readFileSync(UUID_FILE, 'utf8');
25+
} else {
26+
this.uuid = uuidv4();
27+
fs.writeFileSync(UUID_FILE, this.uuid, {flag: 'w'})
2528
}
26-
this.uuid = uuid.trim();
2729

2830
this.installation_code = process.env.INSTALLATION_CODE || ''
2931
this.client = client

clients/express/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/express/yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ anymatch@~3.1.2:
103103
"@grpc/grpc-js" "^1.3.2"
104104
"@grpc/proto-loader" "^0.6.2"
105105
dotenv "^16.5.0"
106+
uuid "^11.1.0"
106107

107108
array-flatten@1.1.1:
108109
version "1.1.1"

0 commit comments

Comments
 (0)