MCPcopy Create free account
hub / github.com/cloudbase/garm / GetGithubCredentials

Method GetGithubCredentials

database/sql/github.go:341–372  ·  view source on GitHub ↗
(ctx context.Context, id uint, detailed bool)

Source from the content-addressed store, hash-verified

339}
340
341func (s *sqlDatabase) GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error) {
342 var creds GithubCredentials
343 q := s.conn.Preload("Endpoint")
344
345 if detailed {
346 q = q.
347 Preload("Repositories").
348 Preload("Repositories.Credentials").
349 Preload("Organizations").
350 Preload("Organizations.Credentials").
351 Preload("Enterprises").
352 Preload("Enterprises.Credentials")
353 }
354
355 if !auth.IsAdmin(ctx) {
356 userID, err := getUIDFromContext(ctx)
357 if err != nil {
358 return params.ForgeCredentials{}, fmt.Errorf("error fetching github credentials: %w", err)
359 }
360 q = q.Where("user_id = ?", userID)
361 }
362
363 err := q.Where("id = ?", id).First(&creds).Error
364 if err != nil {
365 if errors.Is(err, gorm.ErrRecordNotFound) {
366 return params.ForgeCredentials{}, fmt.Errorf("github credentials not found: %w", runnerErrors.ErrNotFound)
367 }
368 return params.ForgeCredentials{}, fmt.Errorf("error fetching github credentials: %w", err)
369 }
370
371 return s.sqlToCommonForgeCredentials(creds)
372}
373
374func (s *sqlDatabase) ListGithubCredentials(ctx context.Context) ([]params.ForgeCredentials, error) {
375 q := s.conn.Preload("Endpoint")

Callers

nothing calls this directly

Calls 3

IsAdminFunction · 0.92
getUIDFromContextFunction · 0.85

Tested by

no test coverage detected