Skip to content

Commit 5667bc3

Browse files
Merge pull request #60 from x0Yukthi/main
feat: IAM Role List
2 parents dca24b3 + 370aa51 commit 5667bc3

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

gcloud/roleslist.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package gcloud
2+
3+
type IAMRole struct {
4+
Description string `json:"description"`
5+
Name string `json:"name"`
6+
Title string `json:"title"`
7+
}
8+
9+
func ListIAMRoles(config *Config) ([]IAMRole, error) {
10+
return runGCloudCmd[[]IAMRole](config,
11+
"iam", "roles", "list", "--format=json(description,name,title)")
12+
}

searchers/iam/dto.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package iam
2+
3+
import (
4+
"strings"
5+
6+
"github.com/dineshgowda24/alfred-gcp-workflow/gcloud"
7+
)
8+
9+
type Role struct {
10+
Description string
11+
Name string
12+
DisplayTitle string
13+
}
14+
15+
func (r Role) Details() string {
16+
return r.Name
17+
}
18+
19+
func (r Role) Subtitle() string {
20+
return r.Description
21+
}
22+
23+
func (r Role) Title() string {
24+
return r.DisplayTitle
25+
}
26+
27+
func (r Role) URL(config *gcloud.Config) string {
28+
id := r.ID()
29+
return "https://console.cloud.google.com/iam-admin/roles/details/" + id + "?project=" + config.Project
30+
31+
}
32+
33+
func (r Role) ID() string {
34+
parts := strings.ReplaceAll(r.Name, "/", "%2F")
35+
return parts
36+
}
37+
func FromGCloudIAMRoles(roles *gcloud.IAMRole) Role {
38+
return Role{
39+
Description: roles.Description,
40+
Name: roles.Name,
41+
DisplayTitle: roles.Title,
42+
}
43+
}

searchers/iam/role.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package iam
2+
3+
import (
4+
aw "github.com/deanishe/awgo"
5+
6+
gc "github.com/dineshgowda24/alfred-gcp-workflow/gcloud"
7+
"github.com/dineshgowda24/alfred-gcp-workflow/parser"
8+
"github.com/dineshgowda24/alfred-gcp-workflow/services"
9+
"github.com/dineshgowda24/alfred-gcp-workflow/workflow/resource"
10+
)
11+
12+
type RoleSearcher struct{}
13+
14+
func (s *RoleSearcher) Search(
15+
wf *aw.Workflow, svc *services.Service, cfg *gc.Config, q *parser.Result,
16+
) error {
17+
builder := resource.NewBuilder(
18+
"iam_roles",
19+
wf,
20+
cfg,
21+
q,
22+
gc.ListIAMRoles,
23+
func(wf *aw.Workflow, role gc.IAMRole) {
24+
sb := FromGCloudIAMRoles(&role)
25+
resource.NewItem(wf, cfg, sb, svc.Icon())
26+
},
27+
)
28+
29+
return builder.Build()
30+
}

searchers/searcher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/cloudtask"
1111
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/compute"
1212
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/filestore"
13+
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/iam"
1314
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/k8s"
1415
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/memorystore"
1516
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/monitoring"
@@ -78,6 +79,7 @@ func GetDefaultRegistry() *Registry {
7879
"storage/buckets": &storage.BucketSearcher{},
7980
"vpc/networks": &vpc.NetworkSearcher{},
8081
"vpc/routes": &vpc.RouteSearcher{},
82+
"iam/roles": &iam.RoleSearcher{},
8183
},
8284
}
8385
}

0 commit comments

Comments
 (0)