-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from porters-xyz/develop
v0.6.0
- Loading branch information
Showing
31 changed files
with
960 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package plugins | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAllowedOriginMatches(t *testing.T) { | ||
want := true | ||
origin := "http://test.com" | ||
allowed := []string{"http://test2.com", "http://test.com"} | ||
filter := &AllowedOriginFilter{} | ||
got := filter.matchesRules(origin, allowed) | ||
if want != got { | ||
t.Fatal("origin doesn't match") | ||
} | ||
} | ||
|
||
func TestAllowedOriginMismatch(t *testing.T) { | ||
want := false | ||
origin := "http://test3.com" | ||
allowed := []string{"http://test2.com", "http://test.com"} | ||
filter := &AllowedOriginFilter{} | ||
got := filter.matchesRules(origin, allowed) | ||
if want != got { | ||
t.Fatal("origin doesn't match") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AlertsController } from './alerts.controller'; | ||
|
||
describe('AlertsController', () => { | ||
let controller: AlertsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AlertsController], | ||
}).compile(); | ||
|
||
controller = module.get<AlertsController>(AlertsController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
import { AlertsService } from './alerts.service'; | ||
|
||
@Controller('alerts') | ||
export class AlertsController { | ||
constructor(private readonly alertService: AlertsService) { } | ||
@Get('app/:appId') | ||
async getAppAlerts(@Param('appId') appId: string) { | ||
return this.alertService.getAppAlerts(appId) | ||
} | ||
@Get('tenant/:tenantId') | ||
async getTenantAlerts(@Param('appId') tenantId: string) { | ||
return this.alertService.getTenantAlerts(tenantId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AlertsService } from './alerts.service'; | ||
import { AlertsController } from './alerts.controller'; | ||
|
||
@Module({ | ||
providers: [AlertsService], | ||
controllers: [AlertsController] | ||
}) | ||
export class AlertsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AlertsService } from './alerts.service'; | ||
|
||
describe('AlertsService', () => { | ||
let service: AlertsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AlertsService], | ||
}).compile(); | ||
|
||
service = module.get<AlertsService>(AlertsService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { HttpException, Injectable } from '@nestjs/common'; | ||
import { createHash } from 'crypto'; | ||
|
||
|
||
interface PromResponse { | ||
data: { | ||
result: { | ||
value: any[]; | ||
}; | ||
}; | ||
} | ||
|
||
@Injectable() | ||
export class AlertsService { | ||
|
||
async getAppAlerts(appId: string): Promise<any> { | ||
const hashedAppId = createHash('sha256').update(appId).digest('hex'); | ||
const result = await this.fetchRateLimitStatus({ appId: hashedAppId }) | ||
return result.json() | ||
} | ||
|
||
async getTenantAlerts(tenantId: string): Promise<any> { | ||
const result = await this.fetchRateLimitStatus({ tenantId }) | ||
return result.json() | ||
} | ||
|
||
private async fetchRateLimitStatus( | ||
{ tenantId, appId }: { tenantId?: string; appId?: string } | ||
): Promise<Response> { | ||
|
||
const query = tenantId | ||
? `query?query=gateway_rate_limit_hit{tenant="${tenantId}"}` | ||
: `query?query=gateway_rate_limit_hit{appId="${appId}"}`; | ||
|
||
const url = process.env.PROM_URL + query; | ||
|
||
const res = await fetch(url, { | ||
headers: { | ||
Authorization: String(process.env.PROM_TOKEN), | ||
}, | ||
}); | ||
|
||
if (!res.ok) { | ||
throw new HttpException('Failed to fetch data', res.status); | ||
} | ||
|
||
|
||
return res | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.