Skip to content

Commit 8d42e0a

Browse files
Merge pull request #61 from x0Yukthi/main
feat: Searcher for IAM Service Account
2 parents 03bc439 + e903a77 commit 8d42e0a

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Here are the GCP resources currently searchable through the workflow:
104104
| 🏃‍♂️ Cloud Run | Functions (Gen1), Services (Gen2) |
105105
| 📋 Cloud Tasks | Queues |
106106
| 📊 Monitoring | Dashboards |
107-
| 🔐 IAM | Role |
107+
| 🔐 IAM | Role, Service Accounts |
108108

109109

110110
## Contributing

gcloud/roleslist.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ func ListIAMRoles(config *Config) ([]IAMRole, error) {
1010
return runGCloudCmd[[]IAMRole](config,
1111
"iam", "roles", "list", "--format=json(description,name,title)")
1212
}
13+
14+
type IAMServiceAccount struct {
15+
DisplayName string `json:"displayName"`
16+
Email string `json:"email"`
17+
UniqueID string `json:"uniqueId"`
18+
}
19+
20+
func ListIAMServiceAccounts(config *Config) ([]IAMServiceAccount, error) {
21+
return runGCloudCmd[[]IAMServiceAccount](config,
22+
"iam", "service-accounts", "list", "--format=json(displayName,email,uniqueId)")
23+
}

searchers/iam/dto.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,33 @@ func FromGCloudIAMRoles(roles *gcloud.IAMRole) Role {
4141
DisplayTitle: roles.Title,
4242
}
4343
}
44+
45+
type ServiceAccount struct {
46+
DisplayName string
47+
Email string
48+
UniqueID string
49+
}
50+
51+
func (a ServiceAccount) Title() string {
52+
return a.DisplayName
53+
}
54+
55+
func (a ServiceAccount) Subtitle() string {
56+
return a.Email
57+
}
58+
59+
func (a ServiceAccount) UID() string {
60+
return a.UniqueID
61+
}
62+
63+
func (a ServiceAccount) URL(config *gcloud.Config) string {
64+
return "https://console.cloud.google.com/iam-admin/serviceaccounts/details/" + a.UID() + "?project=" + config.Project
65+
}
66+
67+
func FromGCloudIAMServiceAccount(account *gcloud.IAMServiceAccount) ServiceAccount {
68+
return ServiceAccount{
69+
DisplayName: account.DisplayName,
70+
Email: account.Email,
71+
UniqueID: account.UniqueID,
72+
}
73+
}

searchers/iam/serviceaccount.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 ServiceAccountSearcher struct{}
13+
14+
func (s *ServiceAccountSearcher) Search(
15+
wf *aw.Workflow, svc *services.Service, cfg *gc.Config, q *parser.Result,
16+
) error {
17+
builder := resource.NewBuilder(
18+
"iam_service_accounts",
19+
wf,
20+
cfg,
21+
q,
22+
gc.ListIAMServiceAccounts,
23+
func(wf *aw.Workflow, account gc.IAMServiceAccount) {
24+
sb := FromGCloudIAMServiceAccount(&account)
25+
resource.NewItem(wf, cfg, sb, svc.Icon())
26+
},
27+
)
28+
29+
return builder.Build()
30+
}

searchers/searcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func GetDefaultRegistry() *Registry {
8080
"vpc/networks": &vpc.NetworkSearcher{},
8181
"vpc/routes": &vpc.RouteSearcher{},
8282
"iam/roles": &iam.RoleSearcher{},
83+
"iam/serviceaccounts": &iam.ServiceAccountSearcher{},
8384
},
8485
}
8586
}

0 commit comments

Comments
 (0)