Code Monkey home page Code Monkey logo

ero's Introduction

Ero

Ero is a cli tool, built in Go, used to diff between local & remote Fastly CDN VCL files

ero is "difference" in Finnish

If you require a cli tool for uploading local VCL files to a remote version within a Fastly account, then see Lataa

Why?

Typically when modifying VCL files, I'll be working within a 'staging' environment (this would be where we test out any VCL changes before applying them to our production environment).

Lots of different engineers 'borrow' the staging environment so they can test their changes, but they don't necessarily put the master version back (which leaves the stage environment in an unknown, and possibly unstable, state).

This ultimately means I don't know what's changed in comparison to the branch I happen to be working on. What I've experienced in the past is a scenario where I upload a single VCL file to stage (this would be the file I'm modifying), but things don't work as expected because another VCL file has been changed to something from another engineer's testing branch and it causes a conflict or some other odd behaviour.

The ero cli tool allows me to quickly verify which files I actually need to update (i.e. the file on stage isn't the same as what's in master). Otherwise I'll be forced to blindly upload 10+ separate VCL files via the Fastly UI to ensure that stage is in a stable state for me to upload my own changes on top of.

Installation

go get github.com/integralist/ero

Usage

ero -help

  -debug
        show the error/diff output
  -dir string
        vcl directory to compare files against (default "VCL_DIRECTORY")
  -help
        show available flags
  -match string
        regex for matching vcl directories
  -service string
        your service id (default "FASTLY_SERVICE_ID")
  -skip string
        regex for skipping vcl directories (default "^____")
  -token string
        your fastly api token (default "FASTLY_API_TOKEN")
  -vcl-version string
        specify Fastly service 'version' to verify against
  -version
        show application version

Specify credentials via cli flags:

ero -service 123abc -token 456def

If no flags provided, fallback to environment vars:
FASTLY_SERVICE_ID and FASTLY_API_TOKEN

View the error/diff output using the debug flag:

ero -debug

Typically you'll not care for the output,
you just want to know the files didn't match up

Specify which nested directories you want to verfiy against:

ero -match 'foo|bar'

Note: .git directories are automatically ignored
If no flag provided, we'll look for the environment var:
VCL_MATCH_DIRECTORY

Specify which nested directories you want to skip over:

ero -skip 'foo|bar'

If no flag provided, we'll look for the environment var:
VCL_SKIP_DIRECTORY

Example

The following example execution has presumed the use of the environment variables: VCL_DIRECTORY, FASTLY_API_TOKEN, FASTLY_SERVICE_ID to keep the length of the command short.

$ ero -match www -debug

No difference between the version (123) of 'ab_tests_callback' and the version found locally
        /Users/foo/code/cdn/www/fastly/ab_tests_callback.vcl

No difference between the version (123) of 'ab_tests_deliver' and the version found locally
        /Users/foo/code/cdn/www/fastly/ab_tests_deliver.vcl

No difference between the version (123) of 'blacklist' and the version found locally
        /Users/foo/code/cdn/www/fastly/blacklist.vcl

No difference between the version (123) of 'ab_tests_config' and the version found locally
        /Users/foo/code/cdn/www/fastly/ab_tests_config.vcl

No difference between the version (123) of 'set_country_cookie' and the version found locally
        /Users/foo/code/cdn/www/fastly/set_country_cookie.vcl

No difference between the version (123) of 'ab_tests_recv' and the version found locally
        /Users/foo/code/cdn/www/fastly/ab_tests_recv.vcl

There was a difference between the version (123) of 'main' and the version found locally
        /Users/foo/code/cdn/www/fastly/main.vcl

18,21c18
<   # Blacklist check
<   # Add any IP or User-Agent that should be blacklisted to the blacklist.vcl file
<   call check_ip_blacklist;
<   call check_url_blacklist;
---
>   call check_foo_blacklist;

Build

I find using Gox the simplest way to build multiple OS versions of a Golang application:

go get github.com/mitchellh/gox

gox -osarch="linux/amd64" -osarch="darwin/amd64" -osarch="windows/amd64" -output="ero.{{.OS}}"

./ero.darwin -h

Environment Variables

The use of environment variables help to reduce the amount of flags required to get stuff done. For example, I always diff against a stage environment of Fastly and so I don't want to have to put in the same credentials all the time.

Below is a list of environment variables this tool supports:

  • FASTLY_API_TOKEN
  • FASTLY_SERVICE_ID
  • VCL_DIRECTORY
  • VCL_MATCH_DIRECTORY
  • VCL_SKIP_DIRECTORY

ero's People

Contributors

integralist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ero's Issues

Issue with skipping files

I've noticed that if I try to skip a specific file it doesn't work (e.g. blacklist.vcl), and yet it does work when skipping another file (e.g. fastly_boilerplate.vcl).

I need to understand why that it.

At first I thought it might be the order in which I call the relevant regex functions in my conditional check, but then I'd expect the skipping of fastly_boilerplate.vcl to not work either, and yet it does).

Issue with chosen terminology for environment vars

  • VCL_MATCH_DIRECTORY should be VCL_MATCH_PATH
  • VCL_SKIP_DIRECTORY should be VCL_SKIP_PATH

As that's what we're really doing, running the relevant regex against the whole 'path' and not just a directory structure.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.