Compare commits
No commits in common. "dc97d5e14a613e8618a3afdb494913fee34d2a90" and "9f50d56cea526fc21945e8b2f5342413cf8ac776" have entirely different histories.
dc97d5e14a
...
9f50d56cea
|
@ -40,5 +40,3 @@ ASSETS="https://asset.sky.eigen.co.id/"
|
||||||
|
|
||||||
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
|
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
|
||||||
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
|
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
|
||||||
|
|
||||||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
|
|
@ -37,5 +37,3 @@ ASSETS="https://asset.sky.eigen.co.id/"
|
||||||
|
|
||||||
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
|
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
|
||||||
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
|
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
|
||||||
|
|
||||||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
|
|
@ -1,16 +1,14 @@
|
||||||
import { Controller, Get, Param } from '@nestjs/common';
|
import { Controller, Get, Param } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { SupersetService } from './superset.service';
|
import { SupersetService } from './superset.service';
|
||||||
|
|
||||||
@ApiTags(`Superset`)
|
@ApiTags(`Superset`)
|
||||||
@Controller(`v1/superset`)
|
@Controller(`v1/superset`)
|
||||||
@Public(false)
|
|
||||||
@ApiBearerAuth('JWT')
|
|
||||||
export class SupersetController {
|
export class SupersetController {
|
||||||
constructor(private service: SupersetService) {}
|
constructor(private service: SupersetService) {}
|
||||||
@Get('token/:id')
|
@Get('token/:id')
|
||||||
@ExcludePrivilege()
|
@Public(true)
|
||||||
async getGuestToken(@Param('id') id: string) {
|
async getGuestToken(@Param('id') id: string) {
|
||||||
return this.service.getGuestToken(id);
|
return this.service.getGuestToken(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,8 @@ import { firstValueFrom } from 'rxjs';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SupersetService {
|
export class SupersetService {
|
||||||
private SUPERSET_URL = process.env.SUPERSET_URL + '/api';
|
private SUPERSET_URL = 'https://dashboard.weplayground.eigen.co.id';
|
||||||
|
|
||||||
constructor(private readonly httpService: HttpService) {}
|
constructor(private readonly httpService: HttpService) {}
|
||||||
|
|
||||||
async getLoginToken() {
|
async getLoginToken() {
|
||||||
const data = {
|
const data = {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
|
@ -15,13 +13,8 @@ export class SupersetService {
|
||||||
provider: 'db',
|
provider: 'db',
|
||||||
refresh: true,
|
refresh: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.request({
|
this.httpService.post(`${this.SUPERSET_URL}/api/v1/security/login`, data),
|
||||||
method: 'POST',
|
|
||||||
url: `${this.SUPERSET_URL}/v1/security/login`,
|
|
||||||
data: data,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.data.access_token;
|
return response.data.access_token;
|
||||||
|
@ -29,10 +22,9 @@ export class SupersetService {
|
||||||
|
|
||||||
async getCSRFToken() {
|
async getCSRFToken() {
|
||||||
const loginToken = await this.getLoginToken();
|
const loginToken = await this.getLoginToken();
|
||||||
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.request({
|
this.httpService.get(`${this.SUPERSET_URL}/api/v1/security/csrf_token/`, {
|
||||||
method: 'GET',
|
|
||||||
url: `${this.SUPERSET_URL}/v1/security/csrf_token/`,
|
|
||||||
headers: { Authorization: `Bearer ${loginToken}` },
|
headers: { Authorization: `Bearer ${loginToken}` },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -42,7 +34,6 @@ export class SupersetService {
|
||||||
|
|
||||||
async getGuestToken(uuid: string) {
|
async getGuestToken(uuid: string) {
|
||||||
const { loginToken, csrfToken } = await this.getCSRFToken();
|
const { loginToken, csrfToken } = await this.getCSRFToken();
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
resources: [{ type: 'dashboard', id: uuid }],
|
resources: [{ type: 'dashboard', id: uuid }],
|
||||||
rls: [],
|
rls: [],
|
||||||
|
@ -53,16 +44,15 @@ export class SupersetService {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${loginToken}`,
|
Authorization: `Bearer ${loginToken}`,
|
||||||
'X-CSRFToken': `${csrfToken}`,
|
'X-CSRFToken': `${csrfToken}`,
|
||||||
Referer: `${this.SUPERSET_URL}/v1/security/guest_token/`,
|
Referer: `${this.SUPERSET_URL}/api/v1/security/guest_token/`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.request({
|
this.httpService.post(
|
||||||
method: 'POST',
|
`${this.SUPERSET_URL}/api/v1/security/guest_token/`,
|
||||||
url: `${this.SUPERSET_URL}/v1/security/guest_token/`,
|
data,
|
||||||
data: data,
|
{ headers, xsrfHeaderName: 'X-CSRFToken' },
|
||||||
headers: headers,
|
),
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.data.token;
|
return response.data.token;
|
||||||
|
|
Loading…
Reference in New Issue