Skip to content

Commit

Permalink
Add tslint.json and lint every TS file (pulumi#370)
Browse files Browse the repository at this point in the history
* Add tslint.json and lint every TS file

* Remove go.mod
  • Loading branch information
mikhailshilkov authored and stack72 committed Sep 9, 2019
1 parent 119af2b commit 76cdb38
Show file tree
Hide file tree
Showing 109 changed files with 1,182 additions and 961 deletions.
40 changes: 21 additions & 19 deletions aws-ts-airflow/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as pulumi from "@pulumi/pulumi";
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";

let config = new pulumi.Config("airflow");
const config = new pulumi.Config("airflow");
const dbPassword = config.require("dbPassword");

let vpc = awsx.ec2.Vpc.getDefault();
const vpc = awsx.ec2.Vpc.getDefault();

// Create a basic cluster and autoscaling group
let cluster = new awsx.ecs.Cluster("airflow", { vpc });
let autoScalingGroup = cluster.createAutoScalingGroup("airflow", {
const cluster = new awsx.ecs.Cluster("airflow", { vpc });
const autoScalingGroup = cluster.createAutoScalingGroup("airflow", {
subnetIds: vpc.publicSubnetIds,
templateParameters: {
minSize: 20,
Expand All @@ -19,13 +21,13 @@ let autoScalingGroup = cluster.createAutoScalingGroup("airflow", {
},
});

let securityGroupIds = cluster.securityGroups.map(g => g.id);
const securityGroupIds = cluster.securityGroups.map(g => g.id);

let dbSubnets = new aws.rds.SubnetGroup("dbsubnets", {
const dbSubnets = new aws.rds.SubnetGroup("dbsubnets", {
subnetIds: vpc.publicSubnetIds,
});

let db = new aws.rds.Instance("postgresdb", {
const db = new aws.rds.Instance("postgresdb", {
engine: "postgres",

instanceClass: "db.t2.micro",
Expand All @@ -41,11 +43,11 @@ let db = new aws.rds.Instance("postgresdb", {
skipFinalSnapshot: true,
});

let cacheSubnets = new aws.elasticache.SubnetGroup("cachesubnets", {
const cacheSubnets = new aws.elasticache.SubnetGroup("cachesubnets", {
subnetIds: vpc.publicSubnetIds,
});

let cacheCluster = new aws.elasticache.Cluster("cachecluster", {
const cacheCluster = new aws.elasticache.Cluster("cachecluster", {
clusterId: `cache-${pulumi.getStack()}`.substr(0, 20),
engine: "redis",

Expand All @@ -56,21 +58,21 @@ let cacheCluster = new aws.elasticache.Cluster("cachecluster", {
securityGroupIds: securityGroupIds,
});

let hosts = pulumi.all([db.endpoint.apply(e => e.split(":")[0]), cacheCluster.cacheNodes[0].address]);
let environment = hosts.apply(([postgresHost, redisHost]) => [
const hosts = pulumi.all([db.endpoint.apply(e => e.split(":")[0]), cacheCluster.cacheNodes[0].address]);
const environment = hosts.apply(([postgresHost, redisHost]) => [
{ name: "POSTGRES_HOST", value: postgresHost },
{ name: "POSTGRES_PASSWORD", value: dbPassword },
{ name: "REDIS_HOST", value: redisHost },
{ name: "EXECUTOR", value: "Celery" }
{ name: "EXECUTOR", value: "Celery" },
]);

let airflowControllerListener = new awsx.elasticloadbalancingv2.ApplicationListener("airflowcontroller", {
const airflowControllerListener = new awsx.elasticloadbalancingv2.ApplicationListener("airflowcontroller", {
external: true,
port: 8080,
protocol: "HTTP",
});

let airflowController = new awsx.ecs.EC2Service("airflowcontroller", {
const airflowController = new awsx.ecs.EC2Service("airflowcontroller", {
cluster,
desiredCount: 1,
taskDefinitionArgs: {
Expand All @@ -93,13 +95,13 @@ let airflowController = new awsx.ecs.EC2Service("airflowcontroller", {
},
});

let airflowerListener = new awsx.elasticloadbalancingv2.ApplicationListener("airflower", {
const airflowerListener = new awsx.elasticloadbalancingv2.ApplicationListener("airflower", {
port: 5555,
external: true,
protocol: "HTTP"
protocol: "HTTP",
});

let airflower = new awsx.ecs.EC2Service("airflower", {
const airflower = new awsx.ecs.EC2Service("airflower", {
cluster,
taskDefinitionArgs: {
containers: {
Expand All @@ -116,7 +118,7 @@ let airflower = new awsx.ecs.EC2Service("airflower", {
},
});

let airflowWorkers = new awsx.ecs.EC2Service("airflowworkers", {
const airflowWorkers = new awsx.ecs.EC2Service("airflowworkers", {
cluster,
desiredCount: 3,
taskDefinitionArgs: {
Expand Down
24 changes: 12 additions & 12 deletions aws-ts-apigateway-auth0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import * as awsx from "@pulumi/awsx";
import * as pulumi from '@pulumi/pulumi';
import * as pulumi from "@pulumi/pulumi";

import * as jwksClient from 'jwks-rsa';
import * as jwt from 'jsonwebtoken';
import * as util from 'util';
import * as jwt from "jsonwebtoken";
import * as jwksClient from "jwks-rsa";
import * as util from "util";

const config = new pulumi.Config();
const jwksUri = config.require("jwksUri");
Expand Down Expand Up @@ -66,7 +66,7 @@ export const url = api.url;

// Extract and return the Bearer Token from the Lambda event parameters
function getToken(event: awsx.apigateway.AuthorizerEvent): string {
if (!event.type || event.type !== 'TOKEN') {
if (!event.type || event.type !== "TOKEN") {
throw new Error('Expected "event.type" parameter to have value "TOKEN"');
}

Expand All @@ -89,33 +89,33 @@ async function authenticate(event: awsx.apigateway.AuthorizerEvent): Promise<aws

const decoded = jwt.decode(token, { complete: true });
if (!decoded || typeof decoded === "string" || !decoded.header || !decoded.header.kid) {
throw new Error('invalid token');
throw new Error("invalid token");
}

const client = jwksClient({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 10, // Default value
jwksUri: jwksUri
jwksUri: jwksUri,
});

const key = await util.promisify(client.getSigningKey)(decoded.header.kid);
const signingKey = key.publicKey || key.rsaPublicKey;
if (!signingKey) {
throw new Error('could not get signing key');
throw new Error("could not get signing key");
}

const verifiedJWT = await jwt.verify(token, signingKey, { audience, issuer });
if (!verifiedJWT || typeof verifiedJWT === "string" || !isVerifiedJWT(verifiedJWT)) {
throw new Error('could not verify JWT');
throw new Error("could not verify JWT");
}
return awsx.apigateway.authorizerResponse(verifiedJWT.sub, 'Allow', event.methodArn);
return awsx.apigateway.authorizerResponse(verifiedJWT.sub, "Allow", event.methodArn);
}

interface VerifiedJWT {
sub: string,
sub: string;
}

function isVerifiedJWT(toBeDetermined: VerifiedJWT | Object): toBeDetermined is VerifiedJWT {
return (<VerifiedJWT>toBeDetermined).sub !== undefined;
}
}
8 changes: 5 additions & 3 deletions aws-ts-apigateway/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

// Create a mapping from 'route' to a count
let counterTable = new aws.dynamodb.Table("counterTable", {
const counterTable = new aws.dynamodb.Table("counterTable", {
attributes: [{
name: "id",
type: "S",
Expand All @@ -13,12 +15,12 @@ let counterTable = new aws.dynamodb.Table("counterTable", {
});

// Create an API endpoint
let endpoint = new awsx.apigateway.API("hello-world", {
const endpoint = new awsx.apigateway.API("hello-world", {
routes: [{
path: "/{route+}",
method: "GET",
eventHandler: async (event) => {
let route = event.pathParameters!["route"];
const route = event.pathParameters!["route"];
console.log(`Getting count for '${route}'`);

const client = new aws.sdk.DynamoDB.DocumentClient();
Expand Down
6 changes: 4 additions & 2 deletions aws-ts-appsync/iam.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as pulumi from "@pulumi/pulumi";
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";

export function createIamRole(name: string, table: aws.dynamodb.Table) {
const role = new aws.iam.Role(`${name}-role`, {
Expand All @@ -25,7 +27,7 @@ export function createIamRole(name: string, table: aws.dynamodb.Table) {
})).json,
});

new aws.iam.RolePolicyAttachment(`${name}-rpa`, {
const attachment = new aws.iam.RolePolicyAttachment(`${name}-rpa`, {
role: role,
policyArn: policy.arn,
});
Expand Down
18 changes: 10 additions & 8 deletions aws-ts-appsync/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as aws from "@pulumi/aws";
import { createIamRole } from "./iam";

Expand All @@ -14,7 +16,7 @@ const table = new aws.dynamodb.Table("tenants", {
const role = createIamRole("iam", table);

// GraphQL Schema
const schema =
const schema =
`type Query {
getTenantById(id: ID!): Tenant
}
Expand Down Expand Up @@ -54,7 +56,7 @@ const dataSource = new aws.appsync.DataSource("tenants-ds", {
});

// A resolver for the [getTenantById] query
new aws.appsync.Resolver("get-resolver", {
const getResolver = new aws.appsync.Resolver("get-resolver", {
apiId: api.id,
dataSource: dataSource.name,
type: "Query",
Expand All @@ -66,11 +68,11 @@ new aws.appsync.Resolver("get-resolver", {
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id),
}
}`,
responseTemplate: `$util.toJson($ctx.result)`
responseTemplate: `$util.toJson($ctx.result)`,
});

// A resolver for the [addTenant] mutation
new aws.appsync.Resolver("add-resolver", {
const addResolver = new aws.appsync.Resolver("add-resolver", {
apiId: api.id,
dataSource: dataSource.name,
type: "Mutation",
Expand All @@ -85,7 +87,7 @@ new aws.appsync.Resolver("add-resolver", {
"name": $util.dynamodb.toDynamoDBJson($ctx.args.name)
}
}`,
responseTemplate: `$util.toJson($ctx.result)`
responseTemplate: `$util.toJson($ctx.result)`,
});

export const endpoint = api.uris["GRAPHQL"];
Expand All @@ -95,7 +97,7 @@ export const key = apiKey.key;
*
* An example query:
*
query GetTenant {
getTenantById(id: "123") {
id
Expand All @@ -105,8 +107,8 @@ export const key = apiKey.key;
*
* An example mutation:
*
*
mutation AddTenant {
addTenant(id: "123", name: "First Corp") {
id
Expand Down
2 changes: 2 additions & 0 deletions aws-ts-assume-role/assume-role/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

Expand Down
2 changes: 2 additions & 0 deletions aws-ts-assume-role/create-role/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

Expand Down
8 changes: 5 additions & 3 deletions aws-ts-containers/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as pulumi from "@pulumi/pulumi";
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";

// Create an elastic network listener to listen for requests and route them to the container.
// See https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html
// for more details.
let listener = new awsx.elasticloadbalancingv2.NetworkListener("nginx", { port: 80 });
const listener = new awsx.elasticloadbalancingv2.NetworkListener("nginx", { port: 80 });

// Define the service to run. We pass in the listener to hook up the network load balancer
// to the containers the service will launch.
let service = new awsx.ecs.FargateService("nginx", {
const service = new awsx.ecs.FargateService("nginx", {
desiredCount: 2,
taskDefinitionArgs: {
containers: {
Expand Down
17 changes: 9 additions & 8 deletions aws-ts-eks-hello-world/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as awsx from "@pulumi/awsx";
import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
Expand All @@ -19,7 +20,7 @@ const cluster = new eks.Cluster(name, {
});

// Export the clusters' kubeconfig.
export const kubeconfig = cluster.kubeconfig
export const kubeconfig = cluster.kubeconfig;

// Create a Kubernetes Namespace
const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider });
Expand Down Expand Up @@ -47,16 +48,16 @@ const deployment = new k8s.apps.v1.Deployment(name,
{
name: name,
image: "nginx:latest",
ports: [{ name: "http", containerPort: 80 }]
}
ports: [{ name: "http", containerPort: 80 }],
},
],
}
}
},
},
},
},
{
provider: cluster.provider,
}
},
);

// Export the Deployment name
Expand All @@ -77,9 +78,9 @@ const service = new k8s.core.v1.Service(name,
},
{
provider: cluster.provider,
}
},
);

// Export the Service name and public LoadBalancer Endpoint
export const serviceName = service.metadata.name;
export const serviceHostname = service.status.apply(s => s.loadBalancer.ingress[0].hostname)
export const serviceHostname = service.status.apply(s => s.loadBalancer.ingress[0].hostname);
2 changes: 2 additions & 0 deletions aws-ts-eks-migrate-nodegroups/echoserver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
Expand Down
2 changes: 2 additions & 0 deletions aws-ts-eks-migrate-nodegroups/iam.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import * as iam from "./iam";
Expand Down
2 changes: 2 additions & 0 deletions aws-ts-eks-migrate-nodegroups/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as awsx from "@pulumi/awsx"; import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
Expand Down
2 changes: 2 additions & 0 deletions aws-ts-eks-migrate-nodegroups/nginx-ing-cntlr-rbac.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";

Expand Down
2 changes: 2 additions & 0 deletions aws-ts-eks-migrate-nodegroups/nginx-ing-cntlr.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as k8s from "@pulumi/kubernetes";
import * as input from "@pulumi/kubernetes/types/input";
import * as pulumi from "@pulumi/pulumi";
Expand Down
Loading

0 comments on commit 76cdb38

Please sign in to comment.