mirror of
https://github.com/OutlineFoundation/outline-server.git
synced 2026-05-13 05:52:04 +00:00
chore: add lint rule to prevent unnecessary public modifiers (#1557)
This commit is contained in:
parent
00f345ad98
commit
69f8e02daf
9 changed files with 38 additions and 40 deletions
|
|
@ -70,6 +70,12 @@
|
||||||
],
|
],
|
||||||
"no-prototype-builtins": "off",
|
"no-prototype-builtins": "off",
|
||||||
"@typescript-eslint/ban-types": "off",
|
"@typescript-eslint/ban-types": "off",
|
||||||
|
"@typescript-eslint/explicit-member-accessibility": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"accessibility": "no-public"
|
||||||
|
}
|
||||||
|
],
|
||||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||||
"@typescript-eslint/no-empty-function": "off",
|
"@typescript-eslint/no-empty-function": "off",
|
||||||
"@typescript-eslint/no-explicit-any": "error",
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ const LEGACY_REPORT: HourlyConnectionMetricsReport = {
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeConnectionsTable implements InsertableTable<ConnectionRow> {
|
class FakeConnectionsTable implements InsertableTable<ConnectionRow> {
|
||||||
public rows: ConnectionRow[] | undefined;
|
rows: ConnectionRow[] | undefined;
|
||||||
|
|
||||||
async insert(rows: ConnectionRow[]) {
|
async insert(rows: ConnectionRow[]) {
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import {InsertableTable} from './infrastructure/table';
|
||||||
import {DailyFeatureMetricsReport} from './model';
|
import {DailyFeatureMetricsReport} from './model';
|
||||||
|
|
||||||
class FakeFeaturesTable implements InsertableTable<FeatureRow> {
|
class FakeFeaturesTable implements InsertableTable<FeatureRow> {
|
||||||
public rows: FeatureRow[] | undefined;
|
rows: FeatureRow[] | undefined;
|
||||||
|
|
||||||
async insert(rows: FeatureRow[]) {
|
async insert(rows: FeatureRow[]) {
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export class RealClock implements Clock {
|
||||||
// Fake clock where you manually set what is "now" and can trigger the scheduled callbacks.
|
// Fake clock where you manually set what is "now" and can trigger the scheduled callbacks.
|
||||||
// Useful for tests.
|
// Useful for tests.
|
||||||
export class ManualClock implements Clock {
|
export class ManualClock implements Clock {
|
||||||
public nowMs = 0;
|
nowMs = 0;
|
||||||
private callbacks = [] as (() => void)[];
|
private callbacks = [] as (() => void)[];
|
||||||
|
|
||||||
now(): number {
|
now(): number {
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ export class DelayedConfig<T> implements JsonConfig<T> {
|
||||||
// InMemoryConfig is a JsonConfig backed by an internal member variable. Useful for testing.
|
// InMemoryConfig is a JsonConfig backed by an internal member variable. Useful for testing.
|
||||||
export class InMemoryConfig<T> implements JsonConfig<T> {
|
export class InMemoryConfig<T> implements JsonConfig<T> {
|
||||||
// Holds the data JSON as it was when `write()` was called.
|
// Holds the data JSON as it was when `write()` was called.
|
||||||
public mostRecentWrite: T;
|
mostRecentWrite: T;
|
||||||
constructor(private dataJson: T) {
|
constructor(private dataJson: T) {
|
||||||
this.mostRecentWrite = this.dataJson;
|
this.mostRecentWrite = this.dataJson;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,7 @@ export class ShadowsocksManagerService {
|
||||||
private metricsPublisher: SharedMetricsPublisher
|
private metricsPublisher: SharedMetricsPublisher
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public renameServer(req: RequestType, res: ResponseType, next: restify.Next): void {
|
renameServer(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
logging.debug(`renameServer request ${JSON.stringify(req.params)}`);
|
logging.debug(`renameServer request ${JSON.stringify(req.params)}`);
|
||||||
const name = req.params.name;
|
const name = req.params.name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
|
@ -275,7 +275,7 @@ export class ShadowsocksManagerService {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getServer(req: RequestType, res: ResponseType, next: restify.Next): void {
|
getServer(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
res.send(HttpSuccess.OK, {
|
res.send(HttpSuccess.OK, {
|
||||||
name: this.serverConfig.data().name || this.defaultServerName,
|
name: this.serverConfig.data().name || this.defaultServerName,
|
||||||
serverId: this.serverConfig.data().serverId,
|
serverId: this.serverConfig.data().serverId,
|
||||||
|
|
@ -291,7 +291,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes the server's hostname. Hostname must be a valid domain or IP address
|
// Changes the server's hostname. Hostname must be a valid domain or IP address
|
||||||
public setHostnameForAccessKeys(req: RequestType, res: ResponseType, next: restify.Next): void {
|
setHostnameForAccessKeys(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
logging.debug(`changeHostname request: ${JSON.stringify(req.params)}`);
|
logging.debug(`changeHostname request: ${JSON.stringify(req.params)}`);
|
||||||
|
|
||||||
const hostname = req.params.hostname;
|
const hostname = req.params.hostname;
|
||||||
|
|
@ -329,7 +329,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a access key
|
// Get a access key
|
||||||
public getAccessKey(req: RequestType, res: ResponseType, next: restify.Next): void {
|
getAccessKey(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
try {
|
try {
|
||||||
logging.debug(`getAccessKey request ${JSON.stringify(req.params)}`);
|
logging.debug(`getAccessKey request ${JSON.stringify(req.params)}`);
|
||||||
const accessKeyId = validateAccessKeyId(req.params.id);
|
const accessKeyId = validateAccessKeyId(req.params.id);
|
||||||
|
|
@ -349,7 +349,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lists all access keys
|
// Lists all access keys
|
||||||
public listAccessKeys(req: RequestType, res: ResponseType, next: restify.Next): void {
|
listAccessKeys(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
logging.debug(`listAccessKeys request ${JSON.stringify(req.params)}`);
|
logging.debug(`listAccessKeys request ${JSON.stringify(req.params)}`);
|
||||||
const response = {accessKeys: []};
|
const response = {accessKeys: []};
|
||||||
for (const accessKey of this.accessKeys.listAccessKeys()) {
|
for (const accessKey of this.accessKeys.listAccessKeys()) {
|
||||||
|
|
@ -394,11 +394,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new access key
|
// Creates a new access key
|
||||||
public async createNewAccessKey(
|
async createNewAccessKey(req: RequestType, res: ResponseType, next: restify.Next): Promise<void> {
|
||||||
req: RequestType,
|
|
||||||
res: ResponseType,
|
|
||||||
next: restify.Next
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
logging.debug(`createNewAccessKey request ${JSON.stringify(req.params)}`);
|
logging.debug(`createNewAccessKey request ${JSON.stringify(req.params)}`);
|
||||||
if (req.params.id) {
|
if (req.params.id) {
|
||||||
|
|
@ -420,11 +416,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates an access key with a specific identifier
|
// Creates an access key with a specific identifier
|
||||||
public async createAccessKey(
|
async createAccessKey(req: RequestType, res: ResponseType, next: restify.Next): Promise<void> {
|
||||||
req: RequestType,
|
|
||||||
res: ResponseType,
|
|
||||||
next: restify.Next
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
logging.debug(`createAccessKey request ${JSON.stringify(req.params)}`);
|
logging.debug(`createAccessKey request ${JSON.stringify(req.params)}`);
|
||||||
const accessKeyId = validateAccessKeyId(req.params.id);
|
const accessKeyId = validateAccessKeyId(req.params.id);
|
||||||
|
|
@ -445,7 +437,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the default ports for new access keys
|
// Sets the default ports for new access keys
|
||||||
public async setPortForNewAccessKeys(
|
async setPortForNewAccessKeys(
|
||||||
req: RequestType,
|
req: RequestType,
|
||||||
res: ResponseType,
|
res: ResponseType,
|
||||||
next: restify.Next
|
next: restify.Next
|
||||||
|
|
@ -477,7 +469,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes an existing access key
|
// Removes an existing access key
|
||||||
public removeAccessKey(req: RequestType, res: ResponseType, next: restify.Next): void {
|
removeAccessKey(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
try {
|
try {
|
||||||
logging.debug(`removeAccessKey request ${JSON.stringify(req.params)}`);
|
logging.debug(`removeAccessKey request ${JSON.stringify(req.params)}`);
|
||||||
const accessKeyId = validateAccessKeyId(req.params.id);
|
const accessKeyId = validateAccessKeyId(req.params.id);
|
||||||
|
|
@ -495,7 +487,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public renameAccessKey(req: RequestType, res: ResponseType, next: restify.Next): void {
|
renameAccessKey(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
try {
|
try {
|
||||||
logging.debug(`renameAccessKey request ${JSON.stringify(req.params)}`);
|
logging.debug(`renameAccessKey request ${JSON.stringify(req.params)}`);
|
||||||
const accessKeyId = validateAccessKeyId(req.params.id);
|
const accessKeyId = validateAccessKeyId(req.params.id);
|
||||||
|
|
@ -526,7 +518,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setAccessKeyDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
async setAccessKeyDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
||||||
try {
|
try {
|
||||||
logging.debug(`setAccessKeyDataLimit request ${JSON.stringify(req.params)}`);
|
logging.debug(`setAccessKeyDataLimit request ${JSON.stringify(req.params)}`);
|
||||||
const accessKeyId = validateAccessKeyId(req.params.id);
|
const accessKeyId = validateAccessKeyId(req.params.id);
|
||||||
|
|
@ -545,7 +537,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeAccessKeyDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
async removeAccessKeyDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
||||||
try {
|
try {
|
||||||
logging.debug(`removeAccessKeyDataLimit request ${JSON.stringify(req.params)}`);
|
logging.debug(`removeAccessKeyDataLimit request ${JSON.stringify(req.params)}`);
|
||||||
const accessKeyId = validateAccessKeyId(req.params.id);
|
const accessKeyId = validateAccessKeyId(req.params.id);
|
||||||
|
|
@ -563,7 +555,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setDefaultDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
async setDefaultDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
||||||
try {
|
try {
|
||||||
logging.debug(`setDefaultDataLimit request ${JSON.stringify(req.params)}`);
|
logging.debug(`setDefaultDataLimit request ${JSON.stringify(req.params)}`);
|
||||||
const limit = validateDataLimit(req.params.limit);
|
const limit = validateDataLimit(req.params.limit);
|
||||||
|
|
@ -583,7 +575,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeDefaultDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
async removeDefaultDataLimit(req: RequestType, res: ResponseType, next: restify.Next) {
|
||||||
try {
|
try {
|
||||||
logging.debug(`removeDefaultDataLimit request ${JSON.stringify(req.params)}`);
|
logging.debug(`removeDefaultDataLimit request ${JSON.stringify(req.params)}`);
|
||||||
// Enforcement is done asynchronously in the proxy server. This is transparent to the manager
|
// Enforcement is done asynchronously in the proxy server. This is transparent to the manager
|
||||||
|
|
@ -599,7 +591,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDataUsage(req: RequestType, res: ResponseType, next: restify.Next) {
|
async getDataUsage(req: RequestType, res: ResponseType, next: restify.Next) {
|
||||||
try {
|
try {
|
||||||
logging.debug(`getDataUsage request ${JSON.stringify(req.params)}`);
|
logging.debug(`getDataUsage request ${JSON.stringify(req.params)}`);
|
||||||
const response = await this.managerMetrics.getOutboundByteTransfer({hours: 30 * 24});
|
const response = await this.managerMetrics.getOutboundByteTransfer({hours: 30 * 24});
|
||||||
|
|
@ -612,7 +604,7 @@ export class ShadowsocksManagerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getShareMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
|
getShareMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
logging.debug(`getShareMetrics request ${JSON.stringify(req.params)}`);
|
logging.debug(`getShareMetrics request ${JSON.stringify(req.params)}`);
|
||||||
const response = {metricsEnabled: this.metricsPublisher.isSharingEnabled()};
|
const response = {metricsEnabled: this.metricsPublisher.isSharingEnabled()};
|
||||||
res.send(HttpSuccess.OK, response);
|
res.send(HttpSuccess.OK, response);
|
||||||
|
|
@ -620,7 +612,7 @@ export class ShadowsocksManagerService {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public setShareMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
|
setShareMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
logging.debug(`setShareMetrics request ${JSON.stringify(req.params)}`);
|
logging.debug(`setShareMetrics request ${JSON.stringify(req.params)}`);
|
||||||
const metricsEnabled = req.params.metricsEnabled;
|
const metricsEnabled = req.params.metricsEnabled;
|
||||||
if (metricsEnabled === undefined || metricsEnabled === null) {
|
if (metricsEnabled === undefined || metricsEnabled === null) {
|
||||||
|
|
@ -647,7 +639,7 @@ export class ShadowsocksManagerService {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enableAsnMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
|
enableAsnMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
|
||||||
try {
|
try {
|
||||||
logging.debug(`enableAsnMetrics request ${JSON.stringify(req.params)}`);
|
logging.debug(`enableAsnMetrics request ${JSON.stringify(req.params)}`);
|
||||||
const asnMetricsEnabled = req.params.asnMetricsEnabled;
|
const asnMetricsEnabled = req.params.asnMetricsEnabled;
|
||||||
|
|
|
||||||
|
|
@ -806,28 +806,28 @@ class RepoBuilder {
|
||||||
private prometheusClient_ = new FakePrometheusClient({});
|
private prometheusClient_ = new FakePrometheusClient({});
|
||||||
private defaultDataLimit_;
|
private defaultDataLimit_;
|
||||||
|
|
||||||
public port(port: number): RepoBuilder {
|
port(port: number): RepoBuilder {
|
||||||
this.port_ = port;
|
this.port_ = port;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public keyConfig(keyConfig: InMemoryConfig<AccessKeyConfigJson>): RepoBuilder {
|
keyConfig(keyConfig: InMemoryConfig<AccessKeyConfigJson>): RepoBuilder {
|
||||||
this.keyConfig_ = keyConfig;
|
this.keyConfig_ = keyConfig;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public shadowsocksServer(shadowsocksServer: FakeShadowsocksServer): RepoBuilder {
|
shadowsocksServer(shadowsocksServer: FakeShadowsocksServer): RepoBuilder {
|
||||||
this.shadowsocksServer_ = shadowsocksServer;
|
this.shadowsocksServer_ = shadowsocksServer;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public prometheusClient(prometheusClient: FakePrometheusClient): RepoBuilder {
|
prometheusClient(prometheusClient: FakePrometheusClient): RepoBuilder {
|
||||||
this.prometheusClient_ = prometheusClient;
|
this.prometheusClient_ = prometheusClient;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public defaultDataLimit(limit: DataLimit): RepoBuilder {
|
defaultDataLimit(limit: DataLimit): RepoBuilder {
|
||||||
this.defaultDataLimit_ = limit;
|
this.defaultDataLimit_ = limit;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public build(): ServerAccessKeyRepository {
|
build(): ServerAccessKeyRepository {
|
||||||
return new ServerAccessKeyRepository(
|
return new ServerAccessKeyRepository(
|
||||||
this.port_,
|
this.port_,
|
||||||
'hostname',
|
'hostname',
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ export interface AccessKeyConfigJson {
|
||||||
|
|
||||||
// AccessKey implementation with write access enabled on properties that may change.
|
// AccessKey implementation with write access enabled on properties that may change.
|
||||||
class ServerAccessKey implements AccessKey {
|
class ServerAccessKey implements AccessKey {
|
||||||
public isOverDataLimit = false;
|
isOverDataLimit = false;
|
||||||
constructor(
|
constructor(
|
||||||
readonly id: AccessKeyId,
|
readonly id: AccessKeyId,
|
||||||
public name: string,
|
public name: string,
|
||||||
|
|
|
||||||
|
|
@ -244,8 +244,8 @@ describe('OutlineSharedMetricsPublisher', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
class FakeMetricsCollector implements MetricsCollectorClient {
|
class FakeMetricsCollector implements MetricsCollectorClient {
|
||||||
public collectedServerUsageReport: HourlyServerMetricsReportJson;
|
collectedServerUsageReport: HourlyServerMetricsReportJson;
|
||||||
public collectedFeatureMetricsReport: DailyFeatureMetricsReportJson;
|
collectedFeatureMetricsReport: DailyFeatureMetricsReportJson;
|
||||||
|
|
||||||
async collectServerUsageMetrics(report) {
|
async collectServerUsageMetrics(report) {
|
||||||
this.collectedServerUsageReport = report;
|
this.collectedServerUsageReport = report;
|
||||||
|
|
@ -257,7 +257,7 @@ class FakeMetricsCollector implements MetricsCollectorClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ManualUsageMetrics implements UsageMetrics {
|
class ManualUsageMetrics implements UsageMetrics {
|
||||||
public countryUsage = [] as CountryUsage[];
|
countryUsage = [] as CountryUsage[];
|
||||||
|
|
||||||
getCountryUsage(): Promise<CountryUsage[]> {
|
getCountryUsage(): Promise<CountryUsage[]> {
|
||||||
return Promise.resolve(this.countryUsage);
|
return Promise.resolve(this.countryUsage);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue