Skip to content

Commit

Permalink
fix: fix OIAnalytics registration url and accept unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Apr 19, 2024
1 parent 7438e36 commit bad2d9a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
58 changes: 58 additions & 0 deletions backend/src/db/entity-migrations/v3.3.1-oia-registration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Knex } from 'knex';
import { REGISTRATIONS_TABLE } from '../../repository/registration.repository';

export async function up(knex: Knex): Promise<void> {
await updateRegistrationSettings(knex);
}

async function updateRegistrationSettings(knex: Knex) {
await knex.schema.raw(`create table ${REGISTRATIONS_TABLE}_dg_tmp
(
id char(36) primary key,
created_at datetime default CURRENT_TIMESTAMP not null,
updated_at datetime default CURRENT_TIMESTAMP not null,
host varchar(255) not null,
use_proxy boolean default '0',
proxy_url varchar(255),
proxy_username varchar(255),
proxy_password varchar(255),
accept_unauthorized boolean default '0',
activation_code varchar(255),
check_url varchar(255),
activation_date varchar(255),
activation_expiration_date varchar(255),
token varchar(255),
status text check (status in ('NOT_REGISTERED', 'PENDING', 'REGISTERED')) not null default 'NOT_REGISTERED'
);`);

await knex.schema
.raw(`insert into ${REGISTRATIONS_TABLE}_dg_tmp(id, created_at, updated_at, host, use_proxy, proxy_url, proxy_username, proxy_password,
accept_unauthorized, activation_code, check_url, activation_date,
activation_expiration_date, token, status)
select id,
created_at,
updated_at,
host,
use_proxy,
proxy_url,
proxy_username,
proxy_password,
accept_unauthorized,
activation_code,
check_url,
activation_date,
activation_expiration_date,
token,
status
from ${REGISTRATIONS_TABLE};`);

await knex.schema.raw(`drop table ${REGISTRATIONS_TABLE};`);

await knex.schema.raw(`alter table ${REGISTRATIONS_TABLE}_dg_tmp rename to ${REGISTRATIONS_TABLE};`);

await knex.schema.alterTable(REGISTRATIONS_TABLE, table => {
table.unique(['activation_code', 'check_url', 'host']);
});
}

export async function down(_knex: Knex): Promise<void> {}
2 changes: 1 addition & 1 deletion backend/src/service/oia/registration.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Registration service', () => {
(generateRandomId as jest.Mock).mockReturnValue('1234');

const command: RegistrationSettingsCommandDTO = {
host: 'http://localhost:4200',
host: 'http://localhost:4200/',
acceptUnauthorized: false,
useProxy: true,
proxyUrl: 'http://localhost:3128',
Expand Down
3 changes: 3 additions & 0 deletions backend/src/service/oia/registration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export default class RegistrationService {
};
let response;
try {
if (command.host.endsWith('/')) {
command.host = command.host.slice(0, command.host.length - 1);
}
const url = `${command.host}/api/oianalytics/oibus/registration`;
const agent = createProxyAgent(
command.useProxy,
Expand Down

0 comments on commit bad2d9a

Please sign in to comment.