Giter VIP home page Giter VIP logo

cloud-platform-cli's Introduction

Cloud Platform Tool CLI

Releases codecov

cloud-platform is a command-line tool used by the cloud-platform team and tenants to perform actions on the platform, for example:

  • Create environment configuration using a template
  • Divergences in terraform states
  • Terraform apply
  • Others

User documentation is here: https://user-guide.cloud-platform.service.justice.gov.uk/documentation/getting-started/cloud-platform-cli.html

Install

via Homebrew

brew install ministryofjustice/cloud-platform-tap/cloud-platform-cli

Manually

These installation instructions are for a Mac. If you have a different kind of computer, please amend the steps appropriately.

Please substitute the latest release number. You can see the latest release number in the badge near the top of this page, and all available releases on this page.

RELEASE=<insert latest release>
wget https://github.com/ministryofjustice/cloud-platform-cli/releases/download/${RELEASE}/cloud-platform-cli_${RELEASE}_darwin_amd64.tar.gz
tar xzvf cloud-platform-cli_${RELEASE}_darwin_amd64.tar.gz
mv cloud-platform /usr/local/bin/

NB: You may need to manually open the file to override OSX restrictions against executing binaries downloaded from the internet. To do this, locate the file in the Finder, right-click it and choose "Open". After doing this once, you should be able to run the command as normal.

Usage

The /doc directory should contain usage instructions, otherwise, please see the output of cloud-platform --help or the user-guide entry for more information.

Autogenerate documentation

The cli uses the cobra-docs generator to create automated Markdown pages from Cobra.

When a pull-request is opened, a GitHub Action will trigger and autogenerate the documentation. The action will commit these changes back to the remote branch.

Develop

You will need Go installed.

Build locally

Run make to create a cloud-platform binary.

[note] Something worth noting when building locally. You'll need to pass the --skip-version-check command to avoid a message about upgrading.

Testing

There are two types of tests in this repository:

Integration

These tests build the root binary and test the output of a command. For example, cloud-platform version will output testBuild using a package called go-testcmd. Integration tests are tagged with integration so won't run using the normal go test -v ./... command. You'll have to pass the integration keyword as a build tag, i.e. go test -v ./... --tags integration

If you'd like to create a new integration test, add the following to the top of your test file: //go:build integration.

If the output of a command changes and the tests start failing, simply add the -update flag to your test command and they'll automatically update on your behalf. For example: go test . --tags integration -update

Unit

These tests live next to the code, they have no build tag and will run regardless of the flag you on build.

Run make test to run the unit tests.

There are Dockerfile structure tests that run automatically in a pipeline. If you want to run these locally, install the container-structure-test binary and run:

container-structure-test test --image my-image-name \
--config docker-test.yaml
Mocks

We encourage you to implement your own mocks as much as possible, abstract away parameters into interfaces and initialise mock interfaces in your tests for example. Where you require more complex mocks we lean on mockery. You can find examples ./pkg/mocks (these are automatically generated by mockery). To regenerate mocks you can adjust the following commands:

brew install mockery
brew updae mockery
mockery --name=terraformExec  --structname=TerraformExec --output=pkg/mocks/terraform --dir="pkg/terraform"

Releasing a new version

This project includes a github action which will automatically do the following steps:

  • build a new release and make it available in the github ui
  • build a new docker image and push it to docker hub, tagged with the version number

In order to trigger this action, push a new tag version like this:

git tag [my new version]
git push --tags

When pushing a new tag, consider following Semantic Versioning with version format of MAJOR.MINOR.PATCH

PreRun hook

Every new command should have a PreRun hook as follows, to ensure the version of the cli tool is consistent:

PreRun: upgradeIfNotLatest,

See the existing commands for examples.

Update container Image in Cloud Platform Concourse pipelines

The Cloud Platform concourse pipeline uses many of the cli commands such as deploying the environments repo to Cloud Platform kubernetes Cluster, checking divergence on cloud platform infrastructure, regular cluster create-test-destroy operations etc. Whenever the cli tool is released, a docker image is build an pushed to the docker hub using github workflow. Update the concourse pipeline with the latest cli image to ensure latest of cli binary runs on the pipeline.

cloud-platform-cli's People

Contributors

antonybishop avatar davidread avatar dependabot[bot] avatar digitalronin avatar jackstockley89 avatar jakemulley avatar jaskaransarkaria avatar jasonbirchall avatar mikebell avatar mogaal avatar poornima-krishnasamy avatar razvan-moj avatar sablumiah avatar sj-williams avatar timckt avatar tom-webber avatar vijay-veeranki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cloud-platform-cli's Issues

Add a HOODAW page of orphaned AWS resources

Use this project: https://github.com/ministryofjustice/cloud-platform-report-stateless-resources/tree/cloud-platform-res
...to generate a JSON report of AWS resources which are not listed in a terraform state (usually because of a partial failure when deleting test clusters).

Add a corresponding page in HOODAW which displays items which need to be cleaned up.

This count should also contribute to the HOODAW summary and dashboard reporter which tells us that there is something we need to fix.

decode-secret adding (MISSING) to client secret when decoding

steps to reproduce

Compare the output from

kubectl -n hmpps-tier-preprod get secrets hmpps-tier -o json | jq ".data.OAUTH_CLIENT_SECRET" -r | base64 -D

and

cloud-platform decode-secret -n hmpps-tier-preprod -s hmpps-tier | jq ".data.OAUTH_CLIENT_SECRET" -r

I don't want to post the secret in here but the output of the second command is quite different from the first and contains the string
(MISSING)

Prototype template uses random Basic-Auth password

Background

Hello,

Our designer has used the CLI to generate a new prototype environment yesterday.
The CLI asked for username and password to be used for HTTP Basic Authentication.

Once deployed I noticed that these credentials were not working, so I manually updated the corresponding k8s Secret to fix this.
However today the password has changed again.

Source of the issue

Upon investigation I noticed that the password has changed again and that in fact the template generated by the CLI is writing a random password in the secret:

resource "kubernetes_secret" "basic-auth" {
  # ...

  data = {
    username = var.basic-auth-username
    password = random_password.password.result
  }
}

This is coming from the template file here: https://github.com/ministryofjustice/cloud-platform-environments/blob/main/namespace-resources-cli-template/resources/prototype/basic-auth.tf

Problem

It was surprising that CLI asked for username/password but a random password is used instead.

Fail if user doesn't supply 'name' flag for service account

Currently, if the user doesn't supply a name for their serviceaccount, they end up with a serviceaccount called "cloud-platform-user". This is confusing.

Instead, if the user doesn't supply a name for their serviceaccount, the cli should just stop with an error, explaining the problem.

decode-secret - '<' character incorrectly decoded as \u003c

Spotted in version 1.9.7 on Mac OSX Catalina 10.15.7

I stumbled across this issue recently with an automatically generated password. I've redacted the first part of the password and anything sensitive but fortunately the < character appears right at the end.

You can see from the terminal output below that the base64 returns a < as expected whereas we get some kind of Unicode character reference string back from cloud-platform decode-secret:

echo '...NS44NEU8' | base64 -D
...5.84E<
cloud-platform decode-secret -n court-probation-dev -s court-hearing-event-receiver
{
    "apiVersion": "v1",
    "data": {
       ...
        "A_SECRET": "...5.84E\u003c"
    },
    "kind": "Secret",
    "metadata": {
        "annotations": {

Enable the `cloud-platform` binary to update itself

Running:

cloud-platform update

...or something like that, should result in the user having the latest version
of the cloud-platform cli tool installed.

Better yet, the tool should check for upgrades on launch (maybe not every
time, but at least once per day), and update itself with no input required from
the user.

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.