Skip to content

Commit

Permalink
chore(manager): lint with gts (#2104)
Browse files Browse the repository at this point in the history
* chore(server_manager): lint with gts

* don't move the browserslist

* fix revert
  • Loading branch information
daniellacosse authored Aug 8, 2024
1 parent b0601c9 commit 55d09c0
Show file tree
Hide file tree
Showing 82 changed files with 2,968 additions and 1,162 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@
"no-unused-vars": ["error", {
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}],
"n/no-unpublished-import": ["error", {
"allowModules": ["electron", "electron-notarize", "electron-to-chromium", "@open-wc/testing", "@babel/polyfill"]
}],
"n/no-unpublished-require": ["error", {
"allowModules": ["webpack", "puppeteer", "postcss", "postcss-rtl", "electron-notarize", "copy-webpack-plugin", "html-webpack-plugin"]
}]
}
}
58 changes: 45 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions server_manager/base.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@
// limitations under the License.

const path = require('path');

const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

const OUTPUT_BASE = path.resolve(__dirname, '../output/build/server_manager/www/static');
const OUTPUT_BASE = path.resolve(
__dirname,
'../output/build/server_manager/www/static'
);

const GENERATE_CSS_RTL_LOADER = path.resolve(__dirname, 'css-in-js-rtl-loader.js');
const GENERATE_CSS_RTL_LOADER = path.resolve(
__dirname,
'css-in-js-rtl-loader.js'
);

const CIRCLE_FLAGS_PATH = path.dirname(require.resolve('circle-flags/package.json'));
const CIRCLE_FLAGS_PATH = path.dirname(
require.resolve('circle-flags/package.json')
);

exports.makeConfig = options => {
return {
Expand Down Expand Up @@ -62,13 +71,19 @@ exports.makeConfig = options => {
resolve: {extensions: ['.tsx', '.ts', '.js']},
plugins: [
new webpack.DefinePlugin({
'outline.gcpAuthEnabled': JSON.stringify(process.env.GCP_AUTH_ENABLED !== 'false'),
'outline.gcpAuthEnabled': JSON.stringify(
process.env.GCP_AUTH_ENABLED !== 'false'
),
// Statically link the Roboto font, rather than link to fonts.googleapis.com
'window.polymerSkipLoadingFontRoboto': JSON.stringify(true),
}),
new CopyPlugin({
patterns: [
{from: `${CIRCLE_FLAGS_PATH}/flags`, to: 'images/flags', context: __dirname},
{
from: `${CIRCLE_FLAGS_PATH}/flags`,
to: 'images/flags',
context: __dirname,
},
{from: 'images', to: 'images', context: __dirname}, // Overwrite any colliding flags.
{from: 'messages', to: 'messages', context: __dirname},
],
Expand Down
1 change: 1 addition & 0 deletions server_manager/browser.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Webpack config to run the Outline Manager on the browser.

const path = require('path');

const {makeConfig} = require('./base.webpack.js');

module.exports = makeConfig({
Expand Down
72 changes: 53 additions & 19 deletions server_manager/cloud/digitalocean_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,16 @@ export class RestApiSession implements DigitalOceanSession {
// Register a key with DigitalOcean, so the user will not get a potentially
// confusing email with their droplet password, which could get mistaken for
// an invite.
return this.registerKey_(dropletName, publicKeyForSSH).then((keyId: number) => {
return this.makeCreateDropletRequest(dropletName, region, keyId, dropletSpec);
});
return this.registerKey_(dropletName, publicKeyForSSH).then(
(keyId: number) => {
return this.makeCreateDropletRequest(
dropletName,
region,
keyId,
dropletSpec
);
}
);
}

private makeCreateDropletRequest(
Expand All @@ -129,7 +136,9 @@ export class RestApiSession implements DigitalOceanSession {
return new Promise((fulfill, reject) => {
const makeRequestRecursive = () => {
++requestCount;
console.info(`Requesting droplet creation ${requestCount}/${MAX_REQUESTS}`);
console.info(
`Requesting droplet creation ${requestCount}/${MAX_REQUESTS}`
);
// See https://docs.digitalocean.com/reference/api/api-reference/#operation/droplets_create
this.request<{droplet: DropletInfo}>('POST', 'droplets', {
name: dropletName,
Expand All @@ -146,7 +155,10 @@ export class RestApiSession implements DigitalOceanSession {
})
.then(fulfill)
.catch(e => {
if (e.message.toLowerCase().indexOf('finalizing') >= 0 && requestCount < MAX_REQUESTS) {
if (
e.message.toLowerCase().indexOf('finalizing') >= 0 &&
requestCount < MAX_REQUESTS
) {
// DigitalOcean is still validating this account and may take
// up to 30 seconds. We can retry more frequently to see when
// this error goes away.
Expand All @@ -167,13 +179,18 @@ export class RestApiSession implements DigitalOceanSession {

public getRegionInfo(): Promise<RegionInfo[]> {
console.info('Requesting region info');
return this.request<{regions: RegionInfo[]}>('GET', 'regions').then(response => {
return response.regions;
});
return this.request<{regions: RegionInfo[]}>('GET', 'regions').then(
response => {
return response.regions;
}
);
}

// Registers a SSH key with DigitalOcean.
private registerKey_(keyName: string, publicKeyForSSH: string): Promise<number> {
private registerKey_(
keyName: string,
publicKeyForSSH: string
): Promise<number> {
console.info('Requesting key registration');
return this.request<{ssh_key: {id: number}}>('POST', 'account/keys', {
name: keyName,
Expand All @@ -185,7 +202,10 @@ export class RestApiSession implements DigitalOceanSession {

public getDroplet(dropletId: number): Promise<DropletInfo> {
console.info('Requesting droplet');
return this.request<{droplet: DropletInfo}>('GET', 'droplets/' + dropletId).then(response => {
return this.request<{droplet: DropletInfo}>(
'GET',
'droplets/' + dropletId
).then(response => {
return response.droplet;
});
}
Expand All @@ -199,24 +219,32 @@ export class RestApiSession implements DigitalOceanSession {
public getDropletsByTag(tag: string): Promise<DropletInfo[]> {
console.info('Requesting droplet by tag');
// TODO Add proper pagination support. Going with 100 for now to extend the default of 20, and confirm UI works
return this.request<{droplets: DropletInfo[]}>('GET', `droplets?per_page=100&tag_name=${encodeURI(tag)}`).then(
response => {
return response.droplets;
}
);
return this.request<{droplets: DropletInfo[]}>(
'GET',
`droplets?per_page=100&tag_name=${encodeURI(tag)}`
).then(response => {
return response.droplets;
});
}

public getDroplets(): Promise<DropletInfo[]> {
console.info('Requesting droplets');
// TODO Add proper pagination support. Going with 100 for now to extend the default of 20, and confirm UI works
return this.request<{droplets: DropletInfo[]}>('GET', 'droplets?per_page=100').then(response => {
return this.request<{droplets: DropletInfo[]}>(
'GET',
'droplets?per_page=100'
).then(response => {
return response.droplets;
});
}

// Makes an XHR request to DigitalOcean's API, returns a promise which fulfills
// with the parsed object if successful.
private request<T>(method: string, actionPath: string, data?: {}): Promise<T> {
private request<T>(
method: string,
actionPath: string,
data?: {}
): Promise<T> {
return new Promise<T>((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(method, `https://api.digitalocean.com/v2/${actionPath}`);
Expand All @@ -235,8 +263,14 @@ export class RestApiSession implements DigitalOceanSession {
} else {
// this.response is a JSON object, whose message is an error string.
const responseJson = JSON.parse(xhr.response);
console.error(`DigitalOcean request failed with status ${xhr.status}`);
reject(new Error(`XHR ${responseJson.id} failed with ${xhr.status}: ${responseJson.message}`));
console.error(
`DigitalOcean request failed with status ${xhr.status}`
);
reject(
new Error(
`XHR ${responseJson.id} failed with ${xhr.status}: ${responseJson.message}`
)
);
}
};
xhr.onerror = () => {
Expand Down
Loading

0 comments on commit 55d09c0

Please sign in to comment.