Skip to content

Instantly share code, notes, and snippets.

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

Kev Jackson foamdino

🏠
Working from home
View GitHub Profile
@foamdino
foamdino / api-part1.js
Created November 5, 2018 06:49
accessbot - making request and getting list of environments
var ApiBuilder = require('claudia-api-builder'),
AWS = require('aws-sdk'),
dateFormat = require('dateformat'),
Slack = require('slack-node'),
api = new ApiBuilder();
// initial input from user
api.post('/cockpit/accessrequest', async function(request) {
let ip = request.post.text;
return selection(ip);
@foamdino
foamdino / api-part2.js
Last active November 5, 2018 07:26
accessbot - handle chosen environment response
// handle both ip4 and ip6
let ipv4regex = /(?<=`)[\d.]+(?=`)/;
let ipv6regex = /(?<=`)(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(?=`)/;
function ipAddress(input) {
ip = null;
let ip4result = ipv4regex.exec(input);
if (ip4result != null) {
ip = ip4result[0];
} else {
@foamdino
foamdino / update-security-groups.js
Last active November 5, 2018 07:58
accessbot - core securitygroup update code
function updateSecurityGroups(ip, username) {
return function (groups) {
// remove rules
removals = groups.filter(g => g.IpPermissions.filter(i => i.IpRanges.filter(r => r['Description'] == username).length > 0).length > 0);
console.log(`${username} has ${removals.length} current groups they need removing from`);
removals.forEach(function(element) {
cidrRemovals = element.IpPermissions.map(r => r.IpRanges.filter(x => x['Description'] == username).map(function(x) { return { CidrIp: x.CidrIp }}))[0]
port = element.Tags.find(e => e['Key'] == 'cockpit-port')['Value'];
sgId = element.GroupId;
console.log(`${username} has a rule in ${sgId} that will be removed`);
@foamdino
foamdino / Dockerfile
Created November 5, 2018 08:30
Jenkins Dockerfile
FROM jenkins/jenkins:lts-alpine
USER root
RUN apk update
RUN apk add --no-cache python2 py-setuptools shadow groff less py-pip
RUN pip install --upgrade pip
RUN pip install awscli
RUN pip install virtualenv
RUN apk add docker
@foamdino
foamdino / plugins.txt
Created November 5, 2018 08:31
Jenkins plugins
workflow-aggregator:2.5
timestamper:1.8.8
role-strategy:2.5.1
ssh-slaves:1.20
antisamy-markup-formatter:1.5
extra-columns:1.18
job-dsl:1.69
git-client:2.7.0
github:1.29.2
github-branch-source:2.3.6
@foamdino
foamdino / startup.groovy
Last active November 6, 2018 09:46
Jenkins post-initialisation
#!/usr/bin/env groovy
import java.util.logging.Logger
import jenkins.model.Jenkins
import hudson.model.*
import hudson.markup.RawHtmlMarkupFormatter
import javaposse.jobdsl.dsl.DslScriptLoader
import javaposse.jobdsl.plugin.JenkinsJobManagement
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
@foamdino
foamdino / Jenkinsfile
Created November 6, 2018 06:09
Jenkinsfile example
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('Build Docker Images') {
steps {
dir ("docker/buildbase") {
sh ('docker build --rm -t buildbase .')
}
dir ("docker/builder") {
@foamdino
foamdino / run-tests.sh
Created November 6, 2018 06:15
Jenkins run-tests
#!/usr/bin/env sh
pwd
echo "running pytest at top level"
rm -rf .pytest_cache
python -m pytest example-tests --basetemp=/tmp -p no:cacheprovider '--junit-xml=build/test-results.xml'
chown -R 1000:1000 .
@foamdino
foamdino / build-server-persistence.yaml
Created November 6, 2018 06:30
Jenkins cloudformation for persistence
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates Persistance storage for jenkins in the build environmentName
Parameters:
BuildStack:
Description: The stack this volume relates to.
Type: String
SnapshotId:
Description: The snap shot to build the volume from.
@foamdino
foamdino / run-cleanup.sh
Created November 6, 2018 06:33
Remove containers and images
#!/usr/bin/env sh
CONTAINER_NAME=$1
echo "removing containers: $CONTAINER_NAME"
docker rm $(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}') ||:
echo "removing images associated with: $CONTAINER_NAME"
docker rmi $(docker images -a | grep "$CONTAINER_NAME" | awk '{print $3}') -f ||: