Skip to content

Instantly share code, notes, and snippets.

View hendrixroa's full-sized avatar
🏠
Working from home

Hendrix Roa hendrixroa

🏠
Working from home
View GitHub Profile
@hendrixroa
hendrixroa / AWSSecretsByKeys.ts
Created January 18, 2020 21:57
Pull aws secrets values given keys.
import AWS = require('aws-sdk');
import minimist = require('minimist');
const args: any = minimist(process.argv);
const secretsManager = new AWS.SecretsManager({
region: process.env.AWS_DEFAULT_REGION || 'us-east-2',
});
export class SecretByKey {
public getSecretByKey(secretId: string, keys: string[]): Promise<any> {
@hendrixroa
hendrixroa / GetGitMessages.ts
Created January 18, 2020 21:58
Get current git message and print into stdout
import { spawnSync } from 'child_process';
const child = spawnSync('git', ['log', '-1', '--pretty=format:%s']);
if (child.error) {
// tslint:disable-next-line: no-console
console.error(null);
process.exit(1);
}
// tslint:disable-next-line: no-console
console.log(
@hendrixroa
hendrixroa / putRestApi.ts
Created January 18, 2020 22:03
Script to put rest api in format swagger to AWS APIGATEWAY
import AWS = require('aws-sdk');
import fs = require('fs');
import minimist = require('minimist');
const args: any = minimist(process.argv);
const apigateway = new AWS.APIGateway({
region: process.env.AWS_DEFAULT_REGION || 'us-east-2',
});
@hendrixroa
hendrixroa / SnykAudit.ts
Last active January 18, 2020 22:15
Snyk (snyk.io) script to find vulnerabilities and report to slack via webhook, for run this script you should run first `snyk test --docker $IMAGE_BH --file=Dockerfile --json > snyk_docker.json || true` and later ` node -r ts-node/register snykAudit.ts`
import * as fs from 'fs';
import * as _ from 'lodash';
import { RequestAPI, RequiredUriUrl } from 'request';
import * as request from 'request-promise-native';
export class SnykDockerAudit {
private client: RequestAPI<
request.RequestPromise,
request.RequestPromiseOptions,
RequiredUriUrl
@hendrixroa
hendrixroa / yarnAudit.ts
Created January 18, 2020 22:14
Script to report yarn audit vulnerabilities to slack channet, for run 'yarn audit --json > yarn_audit.json' and later 'node -r ts-node/register scripts/yarnAudit.ts PATH_FILE MODULE'
import * as fs from 'fs';
import * as _ from 'lodash';
import { RequestAPI, RequiredUriUrl } from 'request';
import * as request from 'request-promise-native';
export class YarnAudit {
private client: RequestAPI<
request.RequestPromise,
request.RequestPromiseOptions,
RequiredUriUrl
@hendrixroa
hendrixroa / aws_rotate_key.ts
Created January 18, 2020 22:19
Script to rotate aws keys in Gitlab CI/CD
import * as aws from 'aws-sdk';
import { RequestAPI, RequiredUriUrl } from 'request';
import * as request from 'request-promise-native';
// Update the credentials depending of environment
aws.config.update({
accessKeyId: process.env[`AWS_KEY_${process.env.STAGE}`],
region: process.env.AWS_DEFAULT_REGION,
secretAccessKey: process.env[`AWS_SECRET_${process.env.STAGE}`],
});
@hendrixroa
hendrixroa / CodedeployTriggerToSlack.ts
Created January 18, 2020 22:28
AWS Lambda function triggered by aws codedeploy to send a notification to slack if a deployment was successful or not
const axios = require('axios');
const AWS = require('aws-sdk');
const FunctionShield = require('@puresec/function-shield');
const ENV = process.env;
const slackInfraAlertBot = 'your slack bot token';
FunctionShield.configure(
{
policy: {
@hendrixroa
hendrixroa / CloudwatchLogsToElasticSearch.ts
Created January 18, 2020 22:31
AWS Lambda function to stream cloudwatch logs to elasticsearch with some modification to accept multiples indices
const https = require('https');
const zlib = require('zlib');
const crypto = require('crypto');
const FunctionShield = require('@puresec/function-shield');
const ENV = process.env;
const endpoint = ENV.es_endpoint;
FunctionShield.configure(
{
@hendrixroa
hendrixroa / yarn_audit.bash
Last active March 1, 2023 01:51
yarn audit command to get json data
yarn audit --json > yarn_audit.json
{
"type":"auditAdvisory",
"data":{
"resolution":{
"id":1091144,
"path":"swagger-ui>@braintree/sanitize-url",
"dev":false,
"optional":false,
"bundled":false
},