AttachmentRepository creates a cached AttachmentRepository based on configuration
()
| 1572 | |
| 1573 | // AttachmentRepository creates a cached AttachmentRepository based on configuration |
| 1574 | func (container *Container) AttachmentRepository() repositories.AttachmentRepository { |
| 1575 | if container.attachmentRepository != nil { |
| 1576 | return container.attachmentRepository |
| 1577 | } |
| 1578 | |
| 1579 | bucket := os.Getenv("GCS_BUCKET_NAME") |
| 1580 | if bucket != "" { |
| 1581 | container.logger.Debug("creating GoogleCloudStorageAttachmentRepository") |
| 1582 | client, err := storage.NewClient(context.Background(), option.WithAuthCredentialsJSON(option.ServiceAccount, container.FirebaseCredentials())) |
| 1583 | if err != nil { |
| 1584 | container.logger.Fatal(stacktrace.Propagate(err, "cannot create GCS client")) |
| 1585 | } |
| 1586 | container.attachmentRepository = repositories.NewGoogleCloudStorageAttachmentRepository( |
| 1587 | container.Logger(), |
| 1588 | container.Tracer(), |
| 1589 | client, |
| 1590 | bucket, |
| 1591 | ) |
| 1592 | } else { |
| 1593 | container.logger.Debug("creating MemoryAttachmentRepository (GCS_BUCKET_NAME not set)") |
| 1594 | container.attachmentRepository = repositories.NewMemoryAttachmentRepository( |
| 1595 | container.Logger(), |
| 1596 | container.Tracer(), |
| 1597 | ) |
| 1598 | } |
| 1599 | |
| 1600 | return container.attachmentRepository |
| 1601 | } |
| 1602 | |
| 1603 | // APIBaseURL returns the API base URL derived from EVENTS_QUEUE_ENDPOINT |
| 1604 | func (container *Container) APIBaseURL() string { |
no test coverage detected