Skip to content

Commit

Permalink
Transformed from pswitch to GCPQ
Browse files Browse the repository at this point in the history
  • Loading branch information
faahren committed May 4, 2024
1 parent 93d938a commit 9a1b8c0
Show file tree
Hide file tree
Showing 12 changed files with 732 additions and 58 deletions.
59 changes: 50 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Simple GCP Project Project Switcher
# Google Cloud Platform CLI Utils

Have you ever struggled to switch between GCP projects locally ?
Here is a simple CLI to switch between GCP projects easily.
Are you constantly struggling with the interface of GCP when you want to switch between services and projects ?
Here is a simple CLI to simplify your daily life



## Requirements
Expand All @@ -10,21 +12,22 @@ GCLOUD SDK has to be installed on your machine and you have to be logged in

## Usage

### Switch between projects
If you want to list all projects before choosing one
```
pswitch
pgo s
```

If you want to search for a specific term in the project name or project id

```
pswitch searchTerm
pgo s searchTerm
```

You will see the following output to choose your project rom:

```
$ pswitch mycompanyName
$ pgo mycompanyName
[0] : mycompany-380102 (mycompany)
[1] : mycompany-airbyte (mycompany-airbyte)
[2] : mycompany-chatbot (mycompany-chatbot)
Expand All @@ -36,12 +39,50 @@ $ pswitch mycompanyName
Enter project number to switch to:
```

If you prefer ordering by name than ordering by id
If you want to automatically switch to the first found project
```
pswitch --name
pgo searchTerm -a
```

If you want to automatically switch to the first found project
### Opening Google Cloud Interface quickly

If you want to open a service quickly. When you don't specify projects, the current Gcloud set project will be used

```
pgo bq
```

Open multiple services at the same time

```
pswitch searchTerm -a
pgo bq,dataform,iam,build,gcs
```

Aliased have been created for the services. You can see them in the `services.yaml` file of the repo


Open services on a specific project (you will be able to choose the project matching the search result)

```
pgo bq myCompanyName
```

Open services on a specific project automatically (Will open the first found project)

```
pgo bq myCompanyName -a
```

Create shortcuts of groups of services
- Open your config file located in `~/.gcpq/config.yaml`
- Add new groups of services in the file (follow current structure)


```
pgo myGroupName
```



# Modifying GCPQU
If you need to modify the package, you can test your modifications with poetry run pgo
File renamed without changes.
34 changes: 34 additions & 0 deletions gcpq/cfg_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Description: This file contains the configuration related functions
import os
import sys
import yaml

def get_full_config_dir():
home = os.path.expanduser("~")
return f"{home}/.gcpq"

def get_config_file_path():
return f"{get_full_config_dir()}/config.yaml"

def install_command():
config_dir = get_full_config_dir()
if not os.path.exists(config_dir):
os.mkdir(config_dir)

cfg_file_path = get_config_file_path()
if not os.path.exists(cfg_file_path):
with open(cfg_file_path, "w") as f:
f.write(yaml.dump({"groups":{"dwh": ["bigquery", "dataform", "storage"] }}))

def load_config():
cfg_file_path = get_config_file_path()
if not os.path.exists(cfg_file_path):
install_command()
config = yaml.load(open(cfg_file_path, "r"), Loader=yaml.SafeLoader)
with open(f'{os.path.dirname(__file__)}/config/services.yaml', 'r') as f:
services = yaml.load(f, Loader=yaml.SafeLoader)

config["services"] = services
return config

config = load_config()
Loading

0 comments on commit 9a1b8c0

Please sign in to comment.