MCPcopy Create free account
hub / github.com/bytebase/bytebase / ListServiceAccounts

Method ListServiceAccounts

backend/store/service_account.go:100–175  ·  view source on GitHub ↗

ListServiceAccounts lists service accounts.

(ctx context.Context, find *FindServiceAccountMessage)

Source from the content-addressed store, hash-verified

98
99// ListServiceAccounts lists service accounts.
100func (s *Store) ListServiceAccounts(ctx context.Context, find *FindServiceAccountMessage) ([]*ServiceAccountMessage, error) {
101 where := qb.Q().Space("workspace = ?", find.Workspace)
102
103 if v := find.Email; v != nil {
104 where.And("email = ?", strings.ToLower(*v))
105 }
106 if !find.ShowDeleted {
107 where.And("deleted = ?", false)
108 }
109 if v := find.Project; v != nil {
110 if *v == "" {
111 where.And("project IS NULL")
112 } else {
113 where.And("project = ?", *v)
114 }
115 }
116 if v := find.FilterQ; v != nil {
117 where.And("?", v)
118 }
119
120 q := qb.Q().Space(`
121 SELECT
122 deleted,
123 email,
124 name,
125 workspace,
126 service_key_hash,
127 project
128 FROM service_account
129 WHERE ?
130 ORDER BY created_at ASC
131 `, where)
132
133 if v := find.Limit; v != nil {
134 q.Space("LIMIT ?", *v)
135 }
136 if v := find.Offset; v != nil {
137 q.Space("OFFSET ?", *v)
138 }
139
140 sqlStr, args, err := q.ToSQL()
141 if err != nil {
142 return nil, errors.Wrapf(err, "failed to build sql")
143 }
144
145 rows, err := s.GetDB().QueryContext(ctx, sqlStr, args...)
146 if err != nil {
147 return nil, err
148 }
149 defer rows.Close()
150
151 var sas []*ServiceAccountMessage
152 for rows.Next() {
153 var sa ServiceAccountMessage
154 var project sql.NullString
155 if err := rows.Scan(
156 &sa.MemberDeleted,
157 &sa.Email,

Callers 1

GetServiceAccountMethod · 0.95

Calls 9

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
AndMethod · 0.80
ToSQLMethod · 0.80
QueryContextMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected