MCPcopy Create free account
hub / github.com/encoder-run/operator / postgresStorageStorer

Function postgresStorageStorer

cmd/repositoryembedder/main.go:465–525  ·  view source on GitHub ↗
(c client.Client, s *v1alpha1.Storage, nsPrefix string)

Source from the content-addressed store, hash-verified

463}
464
465func postgresStorageStorer(c client.Client, s *v1alpha1.Storage, nsPrefix string) (storage.Storer, *gorm.DB, error) {
466 // get the password from the postgres secret
467 secret := &corev1.Secret{}
468 if err := c.Get(context.TODO(), client.ObjectKey{Name: s.Name, Namespace: s.Namespace}, secret); err != nil {
469 return nil, nil, err
470 }
471
472 hostBytes, ok := secret.Data["host"]
473 if !ok {
474 return nil, nil, errors.New("host not found in secret")
475 }
476 host := string(hostBytes)
477
478 usernameBytes, ok := secret.Data["username"]
479 if !ok {
480 return nil, nil, errors.New("username not found in secret")
481 }
482 username := string(usernameBytes)
483
484 passwordBytes, ok := secret.Data["password"]
485 if !ok {
486 return nil, nil, errors.New("password not found in secret")
487 }
488 password := string(passwordBytes)
489
490 databaseBytes, ok := secret.Data["database"]
491 if !ok {
492 return nil, nil, errors.New("database not found in secret")
493 }
494 db := string(databaseBytes)
495
496 portBytes, ok := secret.Data["port"]
497 if !ok {
498 return nil, nil, errors.New("port not found in secret")
499 }
500 port := string(portBytes)
501
502 sslModeBytes, ok := secret.Data["ssl_mode"]
503 if !ok {
504 return nil, nil, errors.New("ssl_mode not found in secret")
505 }
506 sslMode := string(sslModeBytes)
507
508 timezoneBytes, ok := secret.Data["timezone"]
509 if !ok {
510 return nil, nil, errors.New("timezone not found in secret")
511 }
512 timezone := string(timezoneBytes)
513
514 // Construct the DSN
515
516 dsn := database.ConstructPostgresDSN(host, username, password, db, port, sslMode, timezone)
517
518 dbClient, err := database.GetPostgresClient(dsn)
519 if err != nil {
520 return nil, nil, err
521 }
522

Callers 1

mainFunction · 0.85

Calls 2

ConstructPostgresDSNFunction · 0.92
GetPostgresClientFunction · 0.92

Tested by

no test coverage detected