From ce0fa9b931087b89f96e80ee96ba07b16d8e1381 Mon Sep 17 00:00:00 2001 From: x0Yukthi Date: Tue, 19 Aug 2025 00:09:50 -0700 Subject: [PATCH 1/5] IAM service accounts --- gcloud/roleslist.go | 11 +++++++++++ searchers/iam/account.go | 30 ++++++++++++++++++++++++++++++ searchers/iam/dto.go | 30 ++++++++++++++++++++++++++++++ searchers/searcher.go | 1 + 4 files changed, 72 insertions(+) create mode 100644 searchers/iam/account.go diff --git a/gcloud/roleslist.go b/gcloud/roleslist.go index 8361f9e..7d2adb1 100644 --- a/gcloud/roleslist.go +++ b/gcloud/roleslist.go @@ -10,3 +10,14 @@ func ListIAMRoles(config *Config) ([]IAMRole, error) { return runGCloudCmd[[]IAMRole](config, "iam", "roles", "list", "--format=json(description,name,title)") } + +type IAMServiceAccount struct { + DisplayName string `json:"displayName"` + Email string `json:"email"` + UniqueID string `json:"uniqueId"` +} + +func ListIAMServiceAccount(config *Config) ([]IAMServiceAccount, error) { + return runGCloudCmd[[]IAMServiceAccount](config, + "iam", "service-accounts", "list", "--format=json(displayName,email,uniqueId)") +} diff --git a/searchers/iam/account.go b/searchers/iam/account.go new file mode 100644 index 0000000..2a572f2 --- /dev/null +++ b/searchers/iam/account.go @@ -0,0 +1,30 @@ +package iam + +import ( + aw "github.com/deanishe/awgo" + + gc "github.com/dineshgowda24/alfred-gcp-workflow/gcloud" + "github.com/dineshgowda24/alfred-gcp-workflow/parser" + "github.com/dineshgowda24/alfred-gcp-workflow/services" + "github.com/dineshgowda24/alfred-gcp-workflow/workflow/resource" +) + +type AccountSearcher struct{} + +func (s *AccountSearcher) Search( + wf *aw.Workflow, svc *services.Service, cfg *gc.Config, q *parser.Result, +) error { + builder := resource.NewBuilder( + "iam_service_accounts", + wf, + cfg, + q, + gc.ListIAMServiceAccount, + func(wf *aw.Workflow, account gc.IAMServiceAccount) { + sb := FromGCloudIAMServiceAccount(&account) + resource.NewItem(wf, cfg, sb, svc.Icon()) + }, + ) + + return builder.Build() +} diff --git a/searchers/iam/dto.go b/searchers/iam/dto.go index dda69d3..08981a9 100644 --- a/searchers/iam/dto.go +++ b/searchers/iam/dto.go @@ -41,3 +41,33 @@ func FromGCloudIAMRoles(roles *gcloud.IAMRole) Role { DisplayTitle: roles.Title, } } + +type Account struct { + DisplayName string + Email string + UniqueID string +} + +func (a Account) Title() string { + return a.DisplayName +} + +func (a Account) Subtitle() string { + return a.Email +} + +func (a Account) UID() string { + return a.UniqueID +} + +func (a Account) URL(config *gcloud.Config) string { + return "https://console.cloud.google.com/iam-admin/serviceaccounts/details/" + a.UID() + "?project=" + config.Project +} + +func FromGCloudIAMServiceAccount(accounts *gcloud.IAMServiceAccount) Account { + return Account{ + DisplayName: accounts.DisplayName, + Email: accounts.Email, + UniqueID: accounts.UniqueID, + } +} diff --git a/searchers/searcher.go b/searchers/searcher.go index 17ed2fc..74377bb 100644 --- a/searchers/searcher.go +++ b/searchers/searcher.go @@ -80,6 +80,7 @@ func GetDefaultRegistry() *Registry { "vpc/networks": &vpc.NetworkSearcher{}, "vpc/routes": &vpc.RouteSearcher{}, "iam/roles": &iam.RoleSearcher{}, + "iam/serviceaccounts": &iam.AccountSearcher{}, }, } } From 8fa3361c542bde200c3530d169df7b806f0554ed Mon Sep 17 00:00:00 2001 From: x0Yukthi Date: Tue, 19 Aug 2025 00:26:44 -0700 Subject: [PATCH 2/5] IAM service accounts --- gcloud/roleslist.go | 2 +- searchers/iam/dto.go | 20 ++++++++++---------- searchers/iam/serviceaccount.go | 30 ++++++++++++++++++++++++++++++ searchers/searcher.go | 2 +- 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 searchers/iam/serviceaccount.go diff --git a/gcloud/roleslist.go b/gcloud/roleslist.go index 7d2adb1..08a47fe 100644 --- a/gcloud/roleslist.go +++ b/gcloud/roleslist.go @@ -17,7 +17,7 @@ type IAMServiceAccount struct { UniqueID string `json:"uniqueId"` } -func ListIAMServiceAccount(config *Config) ([]IAMServiceAccount, error) { +func ListIAMServiceAccounts(config *Config) ([]IAMServiceAccount, error) { return runGCloudCmd[[]IAMServiceAccount](config, "iam", "service-accounts", "list", "--format=json(displayName,email,uniqueId)") } diff --git a/searchers/iam/dto.go b/searchers/iam/dto.go index 08981a9..da7ef6a 100644 --- a/searchers/iam/dto.go +++ b/searchers/iam/dto.go @@ -42,32 +42,32 @@ func FromGCloudIAMRoles(roles *gcloud.IAMRole) Role { } } -type Account struct { +type ServiceAccount struct { DisplayName string Email string UniqueID string } -func (a Account) Title() string { +func (a ServiceAccount) Title() string { return a.DisplayName } -func (a Account) Subtitle() string { +func (a ServiceAccount) Subtitle() string { return a.Email } -func (a Account) UID() string { +func (a ServiceAccount) UID() string { return a.UniqueID } -func (a Account) URL(config *gcloud.Config) string { +func (a ServiceAccount) URL(config *gcloud.Config) string { return "https://console.cloud.google.com/iam-admin/serviceaccounts/details/" + a.UID() + "?project=" + config.Project } -func FromGCloudIAMServiceAccount(accounts *gcloud.IAMServiceAccount) Account { - return Account{ - DisplayName: accounts.DisplayName, - Email: accounts.Email, - UniqueID: accounts.UniqueID, +func FromGCloudIAMServiceAccount(account *gcloud.IAMServiceAccount) ServiceAccount { + return ServiceAccount{ + DisplayName: account.DisplayName, + Email: account.Email, + UniqueID: account.UniqueID, } } diff --git a/searchers/iam/serviceaccount.go b/searchers/iam/serviceaccount.go new file mode 100644 index 0000000..d05f9f8 --- /dev/null +++ b/searchers/iam/serviceaccount.go @@ -0,0 +1,30 @@ +package iam + +import ( + aw "github.com/deanishe/awgo" + + gc "github.com/dineshgowda24/alfred-gcp-workflow/gcloud" + "github.com/dineshgowda24/alfred-gcp-workflow/parser" + "github.com/dineshgowda24/alfred-gcp-workflow/services" + "github.com/dineshgowda24/alfred-gcp-workflow/workflow/resource" +) + +type ServiceAccountSearcher struct{} + +func (s *ServiceAccountSearcher) Search( + wf *aw.Workflow, svc *services.Service, cfg *gc.Config, q *parser.Result, +) error { + builder := resource.NewBuilder( + "iam_service_accounts", + wf, + cfg, + q, + gc.ListIAMServiceAccounts, + func(wf *aw.Workflow, account gc.IAMServiceAccount) { + sb := FromGCloudIAMServiceAccount(&account) + resource.NewItem(wf, cfg, sb, svc.Icon()) + }, + ) + + return builder.Build() +} diff --git a/searchers/searcher.go b/searchers/searcher.go index 74377bb..b69bb03 100644 --- a/searchers/searcher.go +++ b/searchers/searcher.go @@ -80,7 +80,7 @@ func GetDefaultRegistry() *Registry { "vpc/networks": &vpc.NetworkSearcher{}, "vpc/routes": &vpc.RouteSearcher{}, "iam/roles": &iam.RoleSearcher{}, - "iam/serviceaccounts": &iam.AccountSearcher{}, + "iam/serviceaccounts": &iam.ServiceAccountSearcher{}, }, } } From 0b7198803f08cc5e08f49c80dadad2b7e6b2eecb Mon Sep 17 00:00:00 2001 From: x0Yukthi Date: Wed, 20 Aug 2025 00:00:31 -0700 Subject: [PATCH 3/5] IAM service accounts --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c33ca2..2b87e99 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Here are the GCP resources currently searchable through the workflow: | 🏃‍♂️ Cloud Run | Functions (Gen1), Services (Gen2) | | 📋 Cloud Tasks | Queues | | 📊 Monitoring | Dashboards | -| 🔐 IAM | Role | +| 🔐 IAM | Role | Service Accounts | ## Contributing From 57796790474f6953bbb4d43626b259304eb7dde6 Mon Sep 17 00:00:00 2001 From: x0Yukthi Date: Wed, 20 Aug 2025 10:16:19 -0700 Subject: [PATCH 4/5] IAM service accounts --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b87e99..36dd13d 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Here are the GCP resources currently searchable through the workflow: | 🏃‍♂️ Cloud Run | Functions (Gen1), Services (Gen2) | | 📋 Cloud Tasks | Queues | | 📊 Monitoring | Dashboards | -| 🔐 IAM | Role | Service Accounts | +| 🔐 IAM | Role, Service Accounts | ## Contributing From e903a77b960ea887ad16a5ffc48d3c2f29f1f5a9 Mon Sep 17 00:00:00 2001 From: x0Yukthi Date: Wed, 20 Aug 2025 10:22:25 -0700 Subject: [PATCH 5/5] deleting account.go --- searchers/iam/account.go | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 searchers/iam/account.go diff --git a/searchers/iam/account.go b/searchers/iam/account.go deleted file mode 100644 index 2a572f2..0000000 --- a/searchers/iam/account.go +++ /dev/null @@ -1,30 +0,0 @@ -package iam - -import ( - aw "github.com/deanishe/awgo" - - gc "github.com/dineshgowda24/alfred-gcp-workflow/gcloud" - "github.com/dineshgowda24/alfred-gcp-workflow/parser" - "github.com/dineshgowda24/alfred-gcp-workflow/services" - "github.com/dineshgowda24/alfred-gcp-workflow/workflow/resource" -) - -type AccountSearcher struct{} - -func (s *AccountSearcher) Search( - wf *aw.Workflow, svc *services.Service, cfg *gc.Config, q *parser.Result, -) error { - builder := resource.NewBuilder( - "iam_service_accounts", - wf, - cfg, - q, - gc.ListIAMServiceAccount, - func(wf *aw.Workflow, account gc.IAMServiceAccount) { - sb := FromGCloudIAMServiceAccount(&account) - resource.NewItem(wf, cfg, sb, svc.Icon()) - }, - ) - - return builder.Build() -}