Skip to content

Commit

Permalink
Include guid in presentation format (#11)
Browse files Browse the repository at this point in the history
* include guid in lookups

* ensures service GUID is included in the table
  • Loading branch information
aegershman authored Dec 13, 2019
1 parent 9fd76c4 commit 0673b12
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ cf rsl -s service-instance_4c463943-d421-4f6f-8501-247fba95882d
cf rsl -s service-instance_4c463943-d421-4f6f-8501-247fba95882d -s bbaa77df-52e7-4d6a-8c86-d07a7c93ab82

# optionally, multiple different presentation formats can be specified
cf rsl -s xyz --format json (default)
cf rsl -s xyz --format table
cf rsl -s xyz --format table (default)
cf rsl -s xyz --format json

# or both, why not
cf rsl -s xyz --format table --format json
Expand All @@ -33,29 +33,33 @@ cf rsl -s xyz --format table --format json
`--format json`:

```json
{
"organization": {
"name": "gershman"
},
"service": {
"name": "tiny-turtle-sql",
"space_guid": "4ba83909-cde1-448e-873f-d53b27391604"
},
"space": {
"name": "dev",
"organization_guid": "a297887a-f58f-4266-9ba2-186563eec13a"
[
{
"organization": {
"name": "grundlework"
},
"service": {
"guid": "d6bb8908-a8f8-46b9-9c21-3069cdb939ef",
"name": "small-redis",
"space_guid": "8a90a486-6a40-4709-b65f-efe6705bdc8f"
},
"space": {
"name": "scratchpad",
"organization_guid": "d63feced-41d1-44d7-ba9b-8d062975313b"
}
}
}
]
```

`--format table`:

```txt
+----------+-------+-----------------+
| ORG | SPACE | SERVICE |
+----------+-------+-----------------+
| gershman | dev | tiny-turtle-sql |
+----------+-------+-----------------+
+--------------------------------------+-------------+-------------+------------+
| SERVICE GUID | SERVICE | ORG | SPACE |
+--------------------------------------+-------------+-------------+------------+
| d6bb8908-a8f8-46b9-9c21-3069cdb939ef | small-redis | grundlework | scratchpad |
| a23c6626-2e42-484d-8664-0f6008316f09 | other-redis | otherorgxyz | 123xyspace |
+--------------------------------------+-------------+-------------+------------+
```

## installation
Expand All @@ -64,13 +68,13 @@ If you want to try it out, install it directly from [the github releases tab as

```sh
# osx 64bit
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.4.0/cf-reverse-service-lookup-plugin-darwin
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.5.0/cf-reverse-service-lookup-plugin-darwin

# linux 64bit (32bit and ARM6 also available)
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.4.0/cf-reverse-service-lookup-plugin-amd64
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.5.0/cf-reverse-service-lookup-plugin-amd64

# windows 64bit (32bit also available)
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.4.0/cf-reverse-service-lookup-plugin-windows-amd64.exe
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.5.0/cf-reverse-service-lookup-plugin-windows-amd64.exe
```

## feedback welcome
Expand Down
6 changes: 4 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
version: "2"

silent: true

tasks:
build:
cmds:
Expand All @@ -20,6 +22,6 @@ tasks:
test:
cmds:
- task: install
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b -s db8dba61-32c7-4834-b94b-b3d61240d47b --format table
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b -s db8dba61-32c7-4834-b94b-b3d61240d47b
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b --format json
- task: uninstall
4 changes: 2 additions & 2 deletions cmd/reverseservicelookup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (cmd *reverseServiceLookupCmd) GetMetadata() plugin.PluginMetadata {
Name: "cf-reverse-service-lookup-plugin",
Version: plugin.VersionType{
Major: 0,
Minor: 4,
Minor: 5,
Build: 0,
},
Commands: []plugin.Command{
Expand All @@ -125,7 +125,7 @@ func (cmd *reverseServiceLookupCmd) GetMetadata() plugin.PluginMetadata {
UsageDetails: plugin.Usage{
Usage: "cf rsl [-s service_instance-xyzabc...]",
Options: map[string]string{
"format": "format to present (options: table,json) (default: json)",
"format": "format to present (options: table,json) (default: table)",
"log-level": "(options: info,debug,trace) (default: info)",
"s": "service_instance-GUID to look up. Can be of form 'service_instance-xyzguid123' or just 'xyzguid123'",
"trim-prefix": "if your services are prefixed with something besides BOSH defaults, change this to be the string prefix before the service GUID... also, if you have that use-case, definitely let me know, I'm intrigued. (default: service_instance-)",
Expand Down
2 changes: 1 addition & 1 deletion internal/v2client/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Presenter struct {
// Render -
func (p *Presenter) Render() {
if len(p.Format) == 0 {
p.asJSON()
p.asTable()
}

for _, f := range p.Format {
Expand Down
2 changes: 2 additions & 0 deletions internal/v2client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2client

// Service -
type Service struct {
GUID string `json:"guid"`
Name string `json:"name"`
SpaceGUID string `json:"space_guid"`
}
Expand All @@ -17,6 +18,7 @@ func (s *ServicesService) GetServiceInstanceByGUID(serviceGUID string) (Service,
}

return Service{
GUID: service.Guid,
Name: service.Name,
SpaceGUID: service.SpaceGuid,
}, nil
Expand Down
6 changes: 4 additions & 2 deletions internal/v2client/table_presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import (
func (p *Presenter) asTable() {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"service_guid",
"service",
"org",
"space",
"service",
})

for _, report := range p.ServiceReport {
table.Append([]string{
report.Service.GUID,
report.Service.Name,
report.Organization.Name,
report.Space.Name,
report.Service.Name,
})
}

Expand Down

0 comments on commit 0673b12

Please sign in to comment.