Skip to content

Commit

Permalink
Merge pull request #26 from KeisukeYamashita/add-gcp-product
Browse files Browse the repository at this point in the history
Add gcp product
  • Loading branch information
KeisukeYamashita authored Oct 6, 2019
2 parents a1cf242 + a0d7ae5 commit b9335ce
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ $ biko gcp [product] [flag(s)]
| Cloud Run | Go to Cloud Run page or the deployments detail | `run` | `--region, -r`, `--name, -n` |
| Compute Engine | Go to GCE page | `compute` | - |
| Stackdriver Logging | Go to Stackdriver logging | `logs`, `l` | - |
| IAM & admin | Go to IAM & admin logging | `iam` | - |
| Cloud SQL | Go to Cloud SQL | `sql` | - |
| Cloud PubSub | Go to Cloud PubSub | `pubsub` | - |
| Cloud Storage | Go to Cloud Storage `storage` | - |
| Cloud Dataflow | Go to Cloud Dataflow | `dataflow` | - |

Note that there is `--project` command flag for all commands.

Expand Down
105 changes: 105 additions & 0 deletions cli/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func newGCPCmd() cli.Command {
newGCPCloudRunCmd(),
newGCPGCECmd(),
newGCPLogsCmd(),
newGCPIAMCmd(),
newGCPSQLCmd(),
newGCPPubSubCmd(),
newGCPStorageCmd(),
newGCPDataflowCmd(),
},
}
}
Expand Down Expand Up @@ -267,3 +272,103 @@ func newGCPLogsCmd() cli.Command {
},
}
}

func newGCPIAMCmd() cli.Command {
return cli.Command{
Name: "iam",
Usage: "Open IAM & admin page",
Flags: []cli.Flag{
cli.StringFlag{
Name: "project",
Usage: "Specify the project to open",
},
},
Action: func(c *cli.Context) error {
gcp, err := gcp.GetProvider()
if err != nil {
return err
}
return browser.Open(c, gcp)
},
}
}

func newGCPSQLCmd() cli.Command {
return cli.Command{
Name: "sql",
Usage: "Open Cloud SQL page",
Flags: []cli.Flag{
cli.StringFlag{
Name: "project",
Usage: "Specify the project to open",
},
},
Action: func(c *cli.Context) error {
gcp, err := gcp.GetProvider()
if err != nil {
return err
}
return browser.Open(c, gcp)
},
}
}

func newGCPPubSubCmd() cli.Command {
return cli.Command{
Name: "pubsub",
Usage: "Open Cloud PubSub page",
Flags: []cli.Flag{
cli.StringFlag{
Name: "project",
Usage: "Specify the project to open",
},
},
Action: func(c *cli.Context) error {
gcp, err := gcp.GetProvider()
if err != nil {
return err
}
return browser.Open(c, gcp)
},
}
}

func newGCPStorageCmd() cli.Command {
return cli.Command{
Name: "storage",
Usage: "Open Cloud Storage page",
Flags: []cli.Flag{
cli.StringFlag{
Name: "project",
Usage: "Specify the project to open",
},
},
Action: func(c *cli.Context) error {
gcp, err := gcp.GetProvider()
if err != nil {
return err
}
return browser.Open(c, gcp)
},
}
}

func newGCPDataflowCmd() cli.Command {
return cli.Command{
Name: "dataflow",
Usage: "Open Cloud Dataflow page",
Flags: []cli.Flag{
cli.StringFlag{
Name: "project",
Usage: "Specify the project to open",
},
},
Action: func(c *cli.Context) error {
gcp, err := gcp.GetProvider()
if err != nil {
return err
}
return browser.Open(c, gcp)
},
}
}
18 changes: 17 additions & 1 deletion providers/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ func getSDKConfig() (*SDKConfig, error) {
}

func (p *Provider) addProductPath(product string) {
p.join(product)
switch product {
case "appengine":
p.join(product)
case "bigquery":
p.join(product)
var db, table string
if db = p.GetCtxString("database"); db != "" {
param := url.Values{}
Expand All @@ -127,6 +128,7 @@ func (p *Provider) addProductPath(product string) {
p.URL.RawQuery = param.Encode()
}
case "kubernetes":
p.join(product)
var region, name string
if region = p.GetCtxString("region"); region != "" {
p.join(fmt.Sprintf("details/%s", region))
Expand All @@ -135,6 +137,7 @@ func (p *Provider) addProductPath(product string) {
}
}
case "spanner":
p.join(product)
var instance, db, scheme string
if instance = p.GetCtxString("instance"); instance != "" {
p.join(fmt.Sprintf("instances/%s", instance))
Expand All @@ -146,12 +149,14 @@ func (p *Provider) addProductPath(product string) {
}
}
case "gcr":
p.join(product)
var name string
p.join(fmt.Sprintf("images/%s/", p.SDKConfig.Core.Project))
if name = p.GetCtxString("name"); name != "" {
p.join(fmt.Sprintf("GLOBAL/%s", name))
}
case "run", "functions":
p.join(product)
var region, name string
if region = p.GetCtxString("region"); region != "" {
p.join(fmt.Sprintf("details/%s", region))
Expand All @@ -166,6 +171,17 @@ func (p *Provider) addProductPath(product string) {
case "functions":
}
case "logs":
p.join(product)
case "iam":
p.join("iam-admin")
case "sql":
p.join(product)
case "pubsub":
p.join("cloudpubsub")
case "storage":
p.join(product)
case "dataflow":
p.join(product)
default:
p.join("home/dashboard")
}
Expand Down

0 comments on commit b9335ce

Please sign in to comment.