Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions gcloud/roleslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ListIAMServiceAccounts(config *Config) ([]IAMServiceAccount, error) {
return runGCloudCmd[[]IAMServiceAccount](config,
"iam", "service-accounts", "list", "--format=json(displayName,email,uniqueId)")
}
30 changes: 30 additions & 0 deletions searchers/iam/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ func FromGCloudIAMRoles(roles *gcloud.IAMRole) Role {
DisplayTitle: roles.Title,
}
}

type ServiceAccount struct {
DisplayName string
Email string
UniqueID string
}

func (a ServiceAccount) Title() string {
return a.DisplayName
}

func (a ServiceAccount) Subtitle() string {
return a.Email
}

func (a ServiceAccount) UID() string {
return a.UniqueID
}

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(account *gcloud.IAMServiceAccount) ServiceAccount {
return ServiceAccount{
DisplayName: account.DisplayName,
Email: account.Email,
UniqueID: account.UniqueID,
}
}
30 changes: 30 additions & 0 deletions searchers/iam/serviceaccount.go
Original file line number Diff line number Diff line change
@@ -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()
}
1 change: 1 addition & 0 deletions searchers/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func GetDefaultRegistry() *Registry {
"vpc/networks": &vpc.NetworkSearcher{},
"vpc/routes": &vpc.RouteSearcher{},
"iam/roles": &iam.RoleSearcher{},
"iam/serviceaccounts": &iam.ServiceAccountSearcher{},
},
}
}