Skip to content

Commit cc03c96

Browse files
feat: setting data for adopted probes (#442)
* feat: ignore syncing of custom fields * refactor: move fetch sockets from ws server * test: fix tests * refactor: rename fetchsockets * feat: update probe info with custom data * feat: add index values * feat: get username from dashboard * test: fix tests * feat: return probe info after send code to the probe * fix: fix filtering by user tags * fix: fix test ts build * feat: log and send to the probe updated location * fix: tests * feat: do not apply adoption city data if country doesn`t match * fix: test db * fix: update init sql script * test: add GET int test * fix: nock geo ip * test: add adoption POST test * test: add adopted-probes tests * test: add more adopted sockets tests * feat: update state of the adopted probes in US cities * feat: update gihtub ci * feat: use github field instead of last_name field * test: update userId value * fix: treat null and undefined values as equal * refactor: update sql query * fix: remove user tags from index * feat: rename normalize function * feat: update country field of the adopted probe * feat: send notification to the user * test: add tests for edit of country field * feat: get rid of duplicate notification messages * feat: update dev mariadb password * test: fix tests * feat: add new cities altnames --------- Co-authored-by: Martin Kolárik <[email protected]>
1 parent 113fd52 commit cc03c96

33 files changed

+1116
-419
lines changed

Diff for: .github/workflows/ci.yml

+15-13
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ jobs:
2424
--health-timeout 5s
2525
--health-retries 5
2626
27+
mariadb:
28+
image: mariadb:10.11.5
29+
ports:
30+
- 3306:3306
31+
env:
32+
MARIADB_DATABASE: directus
33+
MARIADB_USER: directus
34+
MARIADB_PASSWORD: password
35+
MARIADB_RANDOM_ROOT_PASSWORD: 1
36+
options: >-
37+
--health-cmd "mysqladmin ping"
38+
--health-interval 10s
39+
--health-timeout 5s
40+
--health-retries 5
41+
2742
steps:
2843
- uses: actions/checkout@v3
29-
30-
- name: Shutdown Ubuntu MySQL
31-
run: sudo service mysql stop
32-
33-
- name: Setup MariaDB
34-
uses: getong/[email protected]
35-
with:
36-
mariadb version: '10.11.5'
37-
mysql user: 'directus'
38-
mysql password: 'password'
39-
mysql database: 'directus'
40-
4144
- name: Init MariaDB
4245
run: |
43-
sleep 5
4446
mysql -u directus -ppassword --database=directus --protocol=tcp < config/init.sql
4547
4648
- uses: actions/setup-node@v3

Diff for: config/init.sql

+66-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,72 @@ CREATE TABLE IF NOT EXISTS adopted_probes (
1010
userId VARCHAR(255) NOT NULL,
1111
ip VARCHAR(255) NOT NULL,
1212
uuid VARCHAR(255),
13-
lastSyncDate DATE,
14-
status VARCHAR(255),
15-
version VARCHAR(255),
16-
country VARCHAR(255),
13+
lastSyncDate DATE NOT NULL,
14+
isCustomCity TINYINT DEFAULT 0,
15+
tags LONGTEXT,
16+
status VARCHAR(255) NOT NULL,
17+
version VARCHAR(255) NOT NULL,
18+
country VARCHAR(255) NOT NULL,
1719
city VARCHAR(255),
18-
latitude FLOAT,
19-
longitude FLOAT,
20-
asn INTEGER,
21-
network VARCHAR(255)
20+
state VARCHAR(255),
21+
latitude FLOAT(10, 5),
22+
longitude FLOAT(10, 5),
23+
asn INTEGER NOT NULL,
24+
network VARCHAR(255) NOT NULL,
25+
countryOfCustomCity VARCHAR(255)
2226
);
2327

24-
INSERT IGNORE INTO adopted_probes (id, userId, ip) VALUES ('1', '6191378', '79.205.97.254');
28+
CREATE TABLE IF NOT EXISTS directus_users (
29+
id CHAR(36),
30+
github VARCHAR(255)
31+
);
32+
33+
CREATE TABLE IF NOT EXISTS directus_notifications (
34+
id CHAR(10),
35+
recipient CHAR(36),
36+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
37+
subject VARCHAR(255),
38+
message TEXT
39+
);
40+
41+
INSERT IGNORE INTO adopted_probes (
42+
userId,
43+
lastSyncDate,
44+
ip,
45+
uuid,
46+
isCustomCity,
47+
tags,
48+
status,
49+
version,
50+
country,
51+
city,
52+
latitude,
53+
longitude,
54+
network,
55+
asn,
56+
countryOfCustomCity
57+
) VALUES (
58+
'89da69bd-a236-4ab7-9c5d-b5f52ce09959',
59+
CURRENT_DATE,
60+
'51.158.22.211',
61+
'c77f021d-23ff-440a-aa96-35e82c73e731',
62+
1,
63+
'["mytag1"]',
64+
'ready',
65+
'0.26.0',
66+
'FR',
67+
'Marseille',
68+
'43.29695',
69+
'5.38107',
70+
'SCALEWAY S.A.S.',
71+
12876,
72+
'FR'
73+
);
74+
75+
INSERT IGNORE INTO directus_users (
76+
id,
77+
github
78+
) VALUES (
79+
'89da69bd-a236-4ab7-9c5d-b5f52ce09959',
80+
'jimaek'
81+
);

Diff for: docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- MARIADB_DATABASE=directus
1616
- MARIADB_USER=directus
1717
- MARIADB_PASSWORD=password
18-
- MARIADB_RANDOM_ROOT_PASSWORD=1
18+
- MARIADB_ROOT_PASSWORD=root
1919
ports:
2020
- "3306:3306"
2121
volumes:

Diff for: public/demo/measurements.vue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const app = () => ({
176176
const locations = this.query.locations.map(({ limit, fields }) => ({
177177
fields: fields.map(field => ({
178178
...field,
179-
value: field.type === 'tags' ? field.value.split(',') : field.value,
179+
value: field.type === 'tags' ? field.value.split(',').map(tag => tag.trim()) : field.value,
180180
})),
181181
...(limit ? { limit } : {}),
182182
}));

Diff for: src/adoption-code/route/adoption-code.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ import { codeSender } from '../sender.js';
99

1010
const handle = async (ctx: Context): Promise<void> => {
1111
const request = ctx.request.body as AdoptionCodeRequest;
12-
const result = await codeSender.sendCode(request);
12+
const socket = await codeSender.sendCode(request);
1313

1414
ctx.body = {
15-
result,
15+
uuid: socket.data.probe.uuid,
16+
version: socket.data.probe.version,
17+
status: socket.data.probe.status,
18+
city: socket.data.probe.location.city,
19+
state: socket.data.probe.location.state,
20+
country: socket.data.probe.location.country,
21+
latitude: socket.data.probe.location.latitude,
22+
longitude: socket.data.probe.location.longitude,
23+
asn: socket.data.probe.location.asn,
24+
network: socket.data.probe.location.network,
1625
};
1726
};
1827

Diff for: src/adoption-code/sender.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22
import createHttpError from 'http-errors';
3-
import { fetchSockets, RemoteProbeSocket } from '../lib/ws/server.js';
3+
import type { RemoteProbeSocket } from '../lib/ws/server.js';
4+
import { fetchSockets } from '../lib/ws/fetch-sockets.js';
45
import type { AdoptionCodeRequest } from './types.js';
56

67
export class CodeSender {
78
constructor (private readonly fetchWsSockets: typeof fetchSockets) {}
89

9-
async sendCode (request: AdoptionCodeRequest): Promise<string> {
10+
async sendCode (request: AdoptionCodeRequest): Promise<RemoteProbeSocket> {
1011
const socket = await this.findSocketByIp(request.ip);
1112

1213
if (!socket) {
@@ -15,16 +16,16 @@ export class CodeSender {
1516

1617
this.sendToSocket(socket, request.code);
1718

18-
return 'Code was sent to the probe.';
19+
return socket;
1920
}
2021

2122
private async findSocketByIp (ip: string) {
2223
const sockets = await this.fetchWsSockets();
2324
return sockets.find(socket => socket.data.probe.ipAddress === ip);
2425
}
2526

26-
private sendToSocket (sockets: RemoteProbeSocket, code: string) {
27-
sockets.emit('probe:adoption:code', {
27+
private sendToSocket (socket: RemoteProbeSocket, code: string) {
28+
socket.emit('probe:adoption:code', {
2829
code,
2930
});
3031
}

0 commit comments

Comments
 (0)