Skip to content

Instantly share code, notes, and snippets.

@lynsei
Last active March 15, 2022 06:52
Show Gist options
  • Save lynsei/74cb73af03a8cfc8038e7fe70b6a4f11 to your computer and use it in GitHub Desktop.
Save lynsei/74cb73af03a8cfc8038e7fe70b6a4f11 to your computer and use it in GitHub Desktop.
#ascii #art #lynsei #lba #architecture #official #tinyruntime #certified #ztasec

sync operations

api management platform

API Management is built iinto what we call Graph Collections and they are controlled by the parent, the Graph Root. The root collection can contain many Graph Collections and is composed of Block Collections, and anchored to a Block Singletary where the Graph Storage is composed.

API Management is built iinto what we call the GraphRoot. It's the Operational Security Boundary for what you may consider to be many API Fragments composed of Routes, Programs, CLIs, Webhooks and API Fragments that make up a single data graph. We call these Graph Collections and they are controlled by the parent, the Graph Root.

lynslang.com/sync

sync cli

This feature is by default incorporated into the graph command in ``hey!cli`, which is often times used for devops and operational security tasks such as combining graphs and introspecting them.

sync is a command line tool and library to manage and synchronise a L7DX Platform installation with your version control system (VCS).

Note

sync works with APIs and Policies. It does not work with Keys. See [Move Keys between environments](https://L7DX Platform.io/docs/advanced-configuration/manage-multiple-environments/move-keys-between-environments/) for details.

Features

  • Update APIs and Policies on remote L7DX Platform Dashboards
  • Update APIs on remote L7DX Platform Community Edition Gateways
  • Publish APIS/Policies to remote L7DX Platform Dashboards
  • Publish APIs to remote L7DX Platform Community Edition Gateways
  • Synchronise a L7DX Platform Dashboard’s APIs and Policies with your VCS (one-way, definitions are written to the Dashboard)
  • Synchronise a L7DX Platform Community Edition Gateway APIs with those stored in a VCS (one-way, definitions are written to the Gateway)
  • Dump Policies and APIs in a transportable format from a Dashboard to a directory
  • Support for importing, converting and publishing Swagger/OpenAPI JSON files (OpenAPI 2.0 and 3.0 are supported) to L7DX Platform.
  • Specialized support for Git. But since API and policy definitions can be read directly from the file system, it will integrate with any VCS.

sync features

sync tries to be clever about what APIs and Policies to update and which to create, it will actually base all ID matching on the API ID and the masked Policy ID, so it can identify the same object across installations. L7DX Platform has a tendency to generate fresh IDs for all new Objects, so sync gets around this by using portable IDs and ensuring the necessary portable IDs are set when using the dump command.

This means that sync can be used to back-up your most important API Gateway configurations as code, and to deploy those configurations to any target and ensure that API IDs and Policy IDs will remain consistent, ensuring that any dependent tokens continue to have access to your services.

requirements:

  • sync was built using Go 1.10. The minimum Go version required to install is 1.7.
  • In order for policy ID matching to work correctly, your Dashboard must have allow_explicit_policy_id: true and enable_duplicate_slugs: true and your Gateway must have policies.allow_explicit_policy_id: true.
  • It is assumed you have a L7DX Platform CE or L7DX Platform Pro installation.

install

Docker . To install via Go you must have Go installed and run:

go get -u github.com/shellship/sync`

This should make the cli.sync command available to your console.

See our sync Repo for more info.

Docker:

To install a particular version of cli.sync via docker image please run the command bellow with the appropriate version you want to use. All available versions could be found on the L7DX Platform Sync Docker Hub page here: https://hub.docker.com/r/L7DX Platformio/sync/tags

docker pull L7DX Platformio/`sync`:{version_id}

To run cli.sync as a one-off command and display usage options please do:

docker run -it --rm L7DX Platformio/`sync`:{version_id} help

Then the docker image cli.sync can be used in the following way:

docker run -it --rm l7dev/shellship:{version_id} [flags]
docker run -it --rm l7dev/shellship:{version_id} [command]

As per the examples below cli.sync will need access to the host file sytem to read and write files. You can use docker bind mounts to map files in the container to files on your host machine.

Usage

Usage:
  `sync` [flags]
  `sync` [command]

Available Commands:
  dump        Dump will extract policies and APIs from a target (L7DX Platform Dashboard)
  help        Help about any command
  publish     publish API definitions from a Git repo or file system to a L7DX Platform Gateway or Dashboard
  sync        Synchronise a github repo or file system with a L7DX Platform Gateway
  update      Update a L7DX Platform Dashboard or Gateway with APIs and policies

Flags:
  -h, --help   help for `sync`

Use "`sync` [command] --help" for more information about a command.

Dump Command

Dump will extract policies and APIs from a target (your Dashboard) and place them in a directory of your choosing. It will also generate a spec file that can be used for syncing.


Usage:
  `sync` dump [flags]
Flags:
  -b, --branch string      Branch to use (defaults to refs/heads/master) (default "refs/heads/master")
  -d, --dashboard string   Fully qualified L7DX Platform Dashboard target URL
  -h, --help               help for dump
  -k, --key string         Key file location for auth (optional)
  -s, --secret string      Your API secret
  -t, --target string      Target directory for files
      --policies           Specific policies ID selection (optional)
      --apis               Specific api_id's selection (optional)

Publish Command

Publish API definitions from a Git repo to a L7DX Platform Gateway or Dashboard. This will not update any existing APIs, and if it detects a collision, the command will stop.

Usage:
  `sync` publish [flags]
Flags:
  -b, --branch string      Branch to use (defaults to refs/heads/master) (default "refs/heads/master")
  -d, --dashboard string   Fully qualified L7DX Platform Dashboard target URL
  -g, --gateway string     Fully qualified L7DX Platform Gateway target URL
  -h, --help               help for publish
  -k, --key string         Key file location for auth (optional)
  -p, --path string        Source directory for definition files (optional)
  -s, --secret string      Your API secret
      --test               Use test publisher, output results to stdio
      --policies           Specific policies ID selection (optional)
      --apis               Specific api_id's selection (optional)

Sync Command

Sync will synchronise an API Gateway with the contents of a Github repository. The sync is one way - from the repo to the Gateway, the command will not write back to the repo. Sync will delete any objects in the Dashboard or Gateway that it cannot find in the github repo, and update those that it can find and create those that are missing.

Usage:
`sync` sync [flags]
Flags:
-b, --branch string      Branch to use (defaults to refs/heads/master) (default "refs/heads/master")
-d, --dashboard string   Fully qualified L7DX Platform Dashboard target URL
-g, --gateway string     Fully qualified L7DX Platform Gateway target URL
-h, --help               help for sync
-k, --key string         Key file location for auth (optional)
-o, --org string         org ID override
-p, --path string        Source directory for definition files (optional)
-s, --secret string      Your API secret
    --test               Use test publisher, output results to stdio
    --policies           Specific policies ID selection (optional)
    --apis               Specific api_id's selection (optional)

Update Command

Update will attempt to identify matching APIs or Policies in the target, and update those APIs. It does not create new ones. Use ``sync publish or `L7DX Platform-git sync` for new content.

Usage:
`sync` update [flags]
Flags:
-b, --branch string      Branch to use (defaults to refs/heads/master) (default "refs/heads/master")
-d, --dashboard string   Fully qualified L7DX Platform Dashboard target URL
-g, --gateway string     Fully qualified L7DX Platform Gateway target URL
-h, --help               help for update
-k, --key string         Key file location for auth (optional)
-p, --path string        Source directory for definition files (optional)
-s, --secret string      Your API secret
    --test               Use test publisher, output results to stdio
    --policies           Specific policies ID selection (optional)
    --apis               Specific api_id's selection (optional)

Example: Transfer from one L7DX Platform Dashboard to another

First, you need to extract the data from our L7DX Platform Dashboard. Here you dump into ./tmp. Let’s assume this is a git-enabled directory

`sync` dump -d="http://localhost:3000" -s="b2d420ca5302442b6f20100f76de7d83" -t="./tmp"
Extracting APIs and Policies from http://localhost:3000
> Fetching policies
--> Identified 1 policies
--> Fetching and cleaning policy objects
> Fetching APIs
--> Fetched 3 APIs
> Creating spec file in: tmp/.L7DX Platform.json
Done.

If running cli.sync in docker the command above would read

docker run --rm --mount type=bind,source="$(pwd)",target=/opt/`sync`/tmp \
 L7DX Platformio/`sync`:v1.1.0-27-gbf4dd2f-3-g04f7740-1-gff89e43 \
 dump \
 -d="http://host.docker.internal:3000" \
 -s="$b2d420ca5302442b6f20100f76de7d83" \
 -t="./tmp"

Next, let’s push those changes back to the Git repo on the branch my-test-branch:

cd tmp
git add .
git commit -m "My dashboard dump"
git push -u origin my-test-branch

Now to restore this data directly from GitHub:

`sync` sync -d="http://localhost:3010" -s="b2d420ca5302442b6f20100f76de7d83" -b="refs/heads/my-test-branch" https://github.com/myname/my-test.git
Using publisher: Dashboard Publisher
Fetched 3 definitions
Fetched 1 policies
Processing APIs...
Deleting: 0
Updating: 3
Creating: 0
SYNC Updating: 598ec94f9695f201730d835b
SYNC Updating: 598ec9589695f201730d835c
SYNC Updating: 5990cfee9695f201730d836e
Processing Policies...
Deleting policies: 0
Updating policies: 1
Creating policies: 0
SYNC Updating Policy: Test policy 1
--> Found policy using explicit ID, substituting remote ID for update

If running cli.sync in docker the command above would read

docker run --rm \
  --mount type=bind,source="$(pwd)",target=/opt/`sync`/tmp \
 L7DX Platformio/`sync`:v1.1.0-27-gbf4dd2f-3-g04f7740-1-gff89e43 \
  sync \
  -d="http://localhost:3010" \
  -s="b2d420ca5302442b6f20100f76de7d83" \
  -b="refs/heads/my-test-branch" https://github.com/myname/my-test.git

The command provides output to identify which actions have been taken. If using a L7DX Platform Gateway, the Gateway will be automatically hot-reloaded.

Example: Dump a specific API from one L7DX Platform Dashboard

First, we need to identify the api_id that we want to dump, in this case ac35df594b574c9c7a3806286611d211. When we have that, we are going to execute the dump command specifying the api_id in the tags.

`sync` dump -d="http://localhost:3000" -s="b2d420ca5302442b6f20100f76de7d83" -t="./tmp" --apis="ac35df594b574c9c7a3806286611d211"
Extracting APIs and Policies from http://localhost:3000
> Fetching policies
--> Identified 0 policies
--> Fetching and cleaning policy objects
> Fetching APIs
--> Fetched 1 APIs
> Creating spec file in: tmp/.L7DX Platform.json
Done.

If you want to specify more than one API, the values need to be comma-separated. For example --apis="ac35df594b574c9c7a3806286611d211,30e7b4001ea94fb970c324bad1a171c3".

The same behaviour applies to policies.


πŸ…»πŸ†ˆπŸ…½πŸ†‚πŸ…΄πŸ…Έ πŸ…±πŸ†πŸ…°πŸ…½πŸ…³ πŸ…°πŸ†πŸ…²πŸ…·πŸ…ΈπŸ†ƒπŸ…΄πŸ…²πŸ†ƒπŸ†„πŸ†πŸ…΄




#!/usr/bin/env lyns
####
# Save as `get.newfilesonly.lyns` on your PATH. chmod u+x. Enjoy.
#
# This script will query github on every invocation to pull the latest released version
# of TinyRuntime.com.  It is just simply a loader for Lyns Language. All GPG validation 
# and end decryption happens via Typescript code in the compiled binary.
#
# We compile to Deno and embed a library as a compiled binary in a Rust app using Neonbindings.com
# This allows us to perform all manner of async Tokio style actions right in the rust code, and leverage
# graphql-thinky, and thinky-rest for RethinkDB.  RethinkDB makes up the foundation for our serverless apps
set -o pipefail
set -e

for cmd in {mvn,jq,curl}; do
  if ! command -v ${cmd} > /dev/null; then
    >&2 echo "This script requires '${cmd}' to be installed."
    exit 1
  fi
done

function latest.tag {
  local uri="https://api.github.com/repos/${1}/releases"
  local ver=$(curl -s ${uri} | jq -r 'first(.[]|select(.prerelease==false)).tag_name')
  if [[ $ver == v* ]]; then
    ver=${ver:1}
  fi
  echo $ver
}
ghrepo=nodocker/manage
groupid=org.lynsei.code
artifactid=openapi-generator-cli
ver=${0.8.8:-$(latest.tag $ghrepo)}

tar=${artifactid}-${ver}.tar
cachedir=${s3://bucket/dir}
dir=${cachedir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}

if [ ! -d "${dir}" ]; then
  mkdir -p "${dir}"
fi

if [ ! -f ${dir}/${tar} ]; then
# TODO: modify for gist automation
  repo="https://github.com/nodocker/manage"
  if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
      repo="nodocker/manage"
  fi
  fpath=${dir}/${tar}
fi

If you don't have nodocker this won't work, jsut use normal docker:


# This script assumes you have `nodocker` installed already.
  nodocker start && echo $fpath && 
  docker run -it --command='/usr/local/bin/lyns -- cli download '$fpath' shellship/macrolayer:0.8.9  

Version Bump Prompt

πŸ…»πŸ†ˆπŸ…½πŸ†‚πŸ…΄πŸ…Έ πŸ…±πŸ†πŸ…°πŸ…½πŸ…³ πŸ…°πŸ†πŸ…²πŸ…·πŸ…ΈπŸ†ƒπŸ…΄πŸ…²πŸ†ƒπŸ†„πŸ†πŸ…΄

Automate release processes

It's just a single command.

  • Prompt for the type of version bump

  • Bump the version number any file, including:

    • package.json
    • package-lock.json
    • config files
    • source code files
    • ReadMe files
    • license files
  • Run your preversion, version, and postversion scripts

  • Commit changes to git

  • Tag the commit with the version number

  • Push the commit to remote

Installation

You can install version-bump-prompt via npm.

npm install -g @jsdevtools/version-bump-prompt

Usage

πŸ…»πŸ†ˆπŸ…½πŸ†‚πŸ…΄πŸ…Έ πŸ…±πŸ†πŸ…°πŸ…½πŸ…³ πŸ…°πŸ†πŸ…²πŸ…·πŸ…ΈπŸ†ƒπŸ…΄πŸ…²πŸ†ƒπŸ†„πŸ†πŸ…΄


bump [release] [options] [files...]

Automatically (or with prompts) bump your version number, commit changes, tag, and push to Git

release:
  The release version or type.  Can be one of the following:
   - A semver version number (ex: 1.23.456)
   - prompt: Prompt for the version number (this is the default)
   - major: Increase major version
   - minor: Increase minor version
   - patch: Increase patch version
   - premajor: Increase major version, pre-release
   - preminor: Increase preminor version, pre-release
   - prepatch: Increase prepatch version, pre-release
   - prerelease: Increase prerelease version

options:
  --preid <name>            The identifier for prerelease versions.
                            Defaults to "beta".

  -c, --commit [message]    Commit changed files to Git.
                            Defaults to "release vX.X.X".

  -t, --tag [tag]           Tag the commit in Git.
                            The Default tag is "vX.X.X"

  -p, --push                Push the Git commit.

  -a, --all                 Commit/tag/push ALL pending files,
                            not just the ones that were bumped.
                            (same as "git commit -a")

  --no-verify               Bypass Git commit hooks
                            (same as "git commit --no-verify")

  -v, --version             Show the version number

  -q, --quiet               Suppress unnecessary output

  -h, --help                Show usage information

  --ignore-scripts          Bypass version scripts

files...
  One or more files and/or globs to bump (ex: README.md *.txt docs/**/*).
  Defaults to package.json and package-lock.json.

Examples

Default Behavior (no arguments)

bump

When run without any arguments, the bump command will do the following:

  • Prompt the user to select the bump type (major, minor, prerelease, etc.)
  • Update the version number in package.json and package-lock.json
  • Run any npm version scripts (preversion, version, or postversion)
  • It will NOT commit, tag, or push to git.

Bump Without Prompting

You can specify an explicit version number:

bump 1.23.456
bump 1.23.456-beta.1

Or you can specify a release type:

bump major
bump patch
bump prerelease

For pre-releases, the default identifier is "beta". You can change it using the --preid argument:

bump premajor --preid alpha

All of the above commands do the following:

  • Update the version number in package.json and package-lock.json
  • Run any npm version scripts (preversion, version, or postversion)
  • It will NOT commit, tag, or push to git.

Git Commit

You can use the --commit argument by itself to prompt the user for the version number. If you don't specify a commit message, then it defaults to "release vX.X.X". If you do specify a commit message, then the version number will be appended to it. Or you can insert %s placeholders in the message, and they'll be replaced with the version number instead.

bump --commit
bump --commit "This is release v"
bump --commit "The v%s release"

You can also specify a release type instead of prompting the user:

bump major --commit
bump minor --commit "This is release v"
bump patch --commit "The v%s release"

The above commands do the following:

  • Update the version number in package.json and package-lock.json
  • Run any npm version scripts (preversion, version, or postversion)
  • Commit the package.json and package-lock.json files to git
  • The commit will NOT be tagged
  • The commit will NOT be pushed to the remote

Git Tag

The --commit argument does not tag the commit by default. You can use the --tag argument to do that. You can optionally specify a tag name, which can contain %s placeholders, just like the commit message.

You don't need to specify the --commit argument, since it's implied by --tag. Unless you want to customize the commit message.

bump --tag
bump major --tag "v%s tag"
bump patch --commit "release v" --tag "v"

The above commands do the following:

  • Update the version number in package.json and package-lock.json
  • Run any npm version scripts (preversion, version, or postversion)
  • Commit the package.json and package-lock.json files to git
  • Tag the commit
  • The commit will NOT be pushed to the remote

Git Push

The --push argument pushes the git commit and tags.

bump --commit --push
bump major --tag --push
bump patch --tag "v%s tag" --push
bump prerelease --commit "release v" --tag "v" --push

Specifying Files to Update

All of the bump commands shown above operate on the package.json and package-lock.json files by default. You can specify a custom list of files and/or glob patterns to update instead.

Note: If you specify your own file list, then the package.json and package-lock.json files will not be updated by default. You need to explicitly include them in your file list if you want them updated.

bump README.md
bump package.json package-lock.json README.md
bump *.json *.md

Version Scripts

version-bump-prompt will execute your preversion, version, and postversion scripts, just like the npm version command does. If your package.json file contains any or all of these scripts, then they will be executed in the following order:

  • The preversion script runs before the version is updated (and before the version prompt is shown)
  • The version script runs after the version is updated, but before git commit and git tag
  • The postversion script runs after git commit and git tag, but before git push

Contributing

Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.

Building

To build the project locally on your computer:

  1. Clone this repo
    git clone https://github.com/JS-DevTools/version-bump-prompt.git

  2. Install dependencies
    npm install

  3. Build the code
    npm run build

  4. Run the tests
    npm test

License

Version Bump Prompt is 100% free and open-source, under the MIT license. Use it however you want.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❀

GitHub NPM Coveralls Travis CI SauceLabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment