Compare commits

..

No commits in common. "7e7d40ea1a140fafc7bb3124df7121af8c55d4bd" and "79adf156db23d3f6e93f7ad6359c165a8037c8b2" have entirely different histories.

4 changed files with 19 additions and 46 deletions

4
env/env.development vendored
View File

@ -40,7 +40,3 @@ ASSETS="https://asset.sky.eigen.co.id/"
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
SUPERSET_ADMIN_USERNAME=admin
SUPERSET_ADMIN_PASSWORD=admin

4
env/env.production vendored
View File

@ -37,7 +37,3 @@ ASSETS="https://asset.sky.eigen.co.id/"
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
SUPERSET_ADMIN_USERNAME=admin
SUPERSET_ADMIN_PASSWORD=admin

View File

@ -1,16 +1,14 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ExcludePrivilege, Public } from 'src/core/guards';
import { ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { SupersetService } from './superset.service';
@ApiTags(`Superset`)
@Controller(`v1/superset`)
@Public(false)
@ApiBearerAuth('JWT')
export class SupersetController {
constructor(private service: SupersetService) {}
@Get('token/:id')
@ExcludePrivilege()
@Public(true)
async getGuestToken(@Param('id') id: string) {
return this.service.getGuestToken(id);
}

View File

@ -1,30 +1,20 @@
import { HttpService } from '@nestjs/axios';
import { Injectable, Logger } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { firstValueFrom } from 'rxjs';
@Injectable()
export class SupersetService {
private readonly logger = new Logger(SupersetService.name);
private supersetURL = process.env.SUPERSET_URL + '/api';
private adminUsername = process.env.SUPERSET_ADMIN_USERNAME;
private adminPassword = process.env.SUPERSET_ADMIN_PASSWORD;
private SUPERSET_URL = 'https://dashboard.weplayground.eigen.co.id';
constructor(private readonly httpService: HttpService) {}
async getLoginToken() {
const data = {
username: this.adminUsername,
password: this.adminPassword,
username: 'admin',
password: 'admin',
provider: 'db',
refresh: true,
};
const response = await firstValueFrom(
this.httpService.request({
method: 'POST',
url: `${this.supersetURL}/v1/security/login`,
data: data,
}),
this.httpService.post(`${this.SUPERSET_URL}/api/v1/security/login`, data),
);
return response.data.access_token;
@ -32,10 +22,9 @@ export class SupersetService {
async getCSRFToken() {
const loginToken = await this.getLoginToken();
const response = await firstValueFrom(
this.httpService.request({
method: 'GET',
url: `${this.supersetURL}/v1/security/csrf_token/`,
this.httpService.get(`${this.SUPERSET_URL}/api/v1/security/csrf_token/`, {
headers: { Authorization: `Bearer ${loginToken}` },
}),
);
@ -45,7 +34,6 @@ export class SupersetService {
async getGuestToken(uuid: string) {
const { loginToken, csrfToken } = await this.getCSRFToken();
const data = {
resources: [{ type: 'dashboard', id: uuid }],
rls: [],
@ -56,21 +44,16 @@ export class SupersetService {
'Content-Type': 'application/json',
Authorization: `Bearer ${loginToken}`,
'X-CSRFToken': `${csrfToken}`,
Referer: `${this.supersetURL}/v1/security/guest_token/`,
Referer: `${this.SUPERSET_URL}/api/v1/security/guest_token/`,
};
const response = await firstValueFrom(
this.httpService.request({
method: 'POST',
url: `${this.supersetURL}/v1/security/guest_token/`,
data: data,
headers: headers,
}),
).catch((err) => {
this.logger.verbose({ loginToken, csrfToken });
this.logger.error(err.response.data);
throw err;
});
this.httpService.post(
`${this.SUPERSET_URL}/api/v1/security/guest_token/`,
data,
{ headers, xsrfHeaderName: 'X-CSRFToken' },
),
);
return response.data.token;
}