Giter Site home page Giter Site logo

adamrodger / gcloud-ctx Goto Github PK

View Code? Open in Web Editor NEW
18.0 5.0 1.0 135 KB

Manage Google Cloud Platform gcloud configurations easily and quickly

License: MIT License

Rust 99.39% Shell 0.61%
gcloud gcp rust cli google-cloud google-cloud-platform gctx gcloud-ctx

gcloud-ctx's People

Contributors

adamrodger avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

c3st7n

gcloud-ctx's Issues

Default region implied by zone

When creating a configuration, if a region is not supplied then it should be inferred from the zone (e.g. zone europe-west1-d implies region europe-west1).

It'll probably be the case that the region almost always matches the zone so it'll save some typing, plus the option is there to override it if necessary.

Exiting fzf without a selection

Steps

  • Make sure fzf is installed and on PATH
  • Run gctx activate
  • Press Ctrl+C to exit fzf without a selection

Expected
Nothing happens because the selection was cancelled

Actual
Error: Unable to find configuration '' is shown

Setup CI

Would be good to have automated builds using Travis or similar for stable and nightly rust versions.

Copy existing configuration

Create a new command to allow copying an existing configuration, optionally overriding supported properties from the source configuration. For example:

gctx copy <existing> <new name> --project bar

would copy the existing configuration entirely, but with the project setting overridden (so the account, zone, etc would all be the same)

Check zone/region exists

The zone/region formatted is to be validated in #29 which would catch some simple typos, but it would still let you type invalid zones/regions. Instead, we should validate the zone/region actually exists.

The challenge is that this data is not really static so we can't hard-code it into the executable. We'll need to do a web request to get the current valid list (and probably cache it locally somewhere).

Check account format

When creating a new configuration, verify the account argument is a valid email address

Fix interactive creation tests

There are placeholder tests for gctx create --interactive but they are set to ignored because they don't work. The assert_cmd crate used to write the integration tests does not support interactive programs so you can't send multiple lines to stdin after each prompt for a field.

It may be that another crate is needed to test that, such as rexpect

Create a new configuration

Add a new command to support creating a new configuration. This command will allow you to specify:

  • Name
  • Project
  • Account
  • Zone
  • Region (optional)
  • Whether to activate the new config immediately (optional)

Interactive creation mode

It can be tedious having to type out all the flags for creating a new configuration. It would be a better user experience to have an option to be prompted for each property instead so you could just type them as you go e.g.:

$ gctx create --interactive
Creating a new configuration interactively
Please enter the following properties

Name: my-name
Warning: a configuration named 'my-name' already exists, overwrite? [yN]: y
Project: my-project
Account: [email protected]
Zone: europe-west1-d
Region (optional):
Activate? [yN]: y

Successfully created configuration 'my-name'
Configuration 'my-name' is now active

Check zone/region format

The zone/region have no validation currently. It would be good to at least verify the format (e.g. (continent)-(geography)(id)-(id)). Something like the regex ^[a-z]+-[a-z]+\d-[a-z]$ to match europe-west1-d.

The list of zones/regions is here to verify they all follow that pattern

Replace fzf with skim

Replace fzf external tool usage with skim: https://github.com/lotabout/skim

This has the advantages:

  • The user won't have to add any third party tools to get fuzzy matching
  • We can control how the display looks instead of showing direct output of other commands

Incorrect directory used on Mac

On a Mac, gcloud stores config in ~/.config/gcloud just like on Linux. However, gctx uses the Apple developer guidelines to look in ~/Library/Application Support/gcloud, which obviously doesn't work.

There will need to be a platform-specific override for forcing Mac to use the proper location.

Replace boolean flags for force overwrite with enum

Some of the APIs allow force-overwriting, e.g. if trying to create a configuration which already exists, but they do so by specifying a boolean flag, like this:

store.rename("foo", "bar", true);

Instead that should work off an enum to make the API more ergonomic

Complete lack of unit tests

Currently gctx has no tests at all. This is tricky because:

  • It's essentially a wrapper around std::fs::* methods, so you'd need to do lots of filesystem stuff or find a way to mock out the filesystem calls
  • The user dir is in a fixed location and comes from the dirs crate. Perhaps a #[cfg(test)] could be used to allow tests to override the location to a temp directory during tests?
  • We call into other crates which themselves use std::fs::* to do stuff
  • The main reason - I don't know enough about Rust yet to mock/stub that kind of stuff yet

In reality I think some refactoring is just required to separate out the filesystem calls from the logic so that the logic can be tested in isolation. Then there can be a few select integration tests using a temp dir where necessary.

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.