diff --git a/lib/browser_manager/initialize.go b/lib/browser_manager/initialize.go index fb42885..2e97bc2 100644 --- a/lib/browser_manager/initialize.go +++ b/lib/browser_manager/initialize.go @@ -3,7 +3,6 @@ package browser_manager import ( "context" "fmt" - "os" log "github.com/Zomato/espresso/lib/logger" "github.com/go-rod/rod" @@ -14,12 +13,8 @@ var ( Browser *rod.Browser ) -func Init(ctx context.Context, tabPool int) error { +func Init(ctx context.Context, tabPool int, browserPath string) error { log.Logger.Info(ctx, "Initializing Browser...", nil) - browserPath := os.Getenv("ROD_BROWSER_BIN") - if browserPath == "" { - return fmt.Errorf("ROD_BROWSER_BIN environment variable not set") - } launcher := launcher.New().Bin(browserPath). Headless(true). diff --git a/lib/certmanager/certmanager.go b/lib/certmanager/certmanager.go index 6ec4ed9..dafd478 100644 --- a/lib/certmanager/certmanager.go +++ b/lib/certmanager/certmanager.go @@ -19,9 +19,9 @@ type SigningCredentials struct { PrivateKey crypto.Signer } type CertificateConfig struct { - CertFilePath string - KeyFilePath string - KeyPassword string + CertFilePath string `mapstructure:"cert_file_path"` + KeyFilePath string `mapstructure:"key_file_path"` + KeyPassword string `mapstructure:"key_password"` } // LoadSigningCredentials loads certificate and private key from configured paths diff --git a/lib/certmanager/credentialstore.go b/lib/certmanager/credentialstore.go new file mode 100644 index 0000000..15c33d5 --- /dev/null +++ b/lib/certmanager/credentialstore.go @@ -0,0 +1,30 @@ +package certmanager + +import "context" + +type CredentialStore struct { + credentials map[string]*SigningCredentials +} + +func NewCredentialStore(credentials map[string]CertificateConfig) (*CredentialStore, error) { + + credentialStore := CredentialStore{ + credentials: make(map[string]*SigningCredentials), + } + + for key, config := range credentials { + cred, err := LoadSigningCredentials(context.Background(), &config) + if err != nil { + return nil, err + } + + credentialStore.credentials[key] = cred + } + + return &credentialStore, nil +} + +func (cs *CredentialStore) GetCredential(key string) (*SigningCredentials, bool) { + creds, exists := cs.credentials[key] + return creds, exists +} diff --git a/lib/renderer/renderer_test.go b/lib/renderer/renderer_test.go index 5753da6..c4ce653 100644 --- a/lib/renderer/renderer_test.go +++ b/lib/renderer/renderer_test.go @@ -2,7 +2,6 @@ package renderer import ( "context" - "os" "testing" "time" @@ -15,8 +14,8 @@ import ( func TestGetHtmlPdf(t *testing.T) { ctx := context.Background() - os.Setenv("ROD_BROWSER_BIN", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome") - err := browser_manager.Init(ctx, 1) + browserPath := "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + err := browser_manager.Init(ctx, 1, browserPath) assert.NoError(t, err) concurrency := 2 diff --git a/lib/s3/s3.go b/lib/s3/s3.go index a3db14e..2af5648 100644 --- a/lib/s3/s3.go +++ b/lib/s3/s3.go @@ -18,25 +18,25 @@ import ( ) type Config struct { - Endpoint string - Region string - ForcePathStyle bool - UploaderPartSize int64 - UploaderConcurrency int - DownloaderPartSize int64 - DownloaderConcurrency int - Debug bool - RetryMaxAttempts int - Bucket string - AccessKeyID string - SecretAccessKey string - SessionToken string - UseCustomTransport bool + Endpoint string `mapstructure:"endpoint"` + Region string `mapstructure:"region"` + ForcePathStyle bool `mapstructure:"force_path_style"` + UploaderPartSizeMB int64 `mapstructure:"uploader_part_size_mb"` + UploaderConcurrency int `mapstructure:"uploader_concurrency"` + DownloaderPartSizeMB int64 `mapstructure:"downloader_part_size_mb"` + DownloaderConcurrency int `mapstructure:"downloader_concurrency"` + Debug bool `mapstructure:"debug"` + RetryMaxAttempts int `mapstructure:"retry_max_attempts"` + Bucket string `mapstructure:"bucket"` + AccessKeyID string `mapstructure:"access_key_id"` + SecretAccessKey string `mapstructure:"secret_access_key"` + SessionToken string `mapstructure:"session_token"` + UseCustomTransport bool `mapstructure:"use_custom_transport"` } type AwsCredConfig struct { - AccessKeyID string - SecretAccessKey string - SessionToken string + AccessKeyID string `mapstructure:"access_key_id"` + SecretAccessKey string `mapstructure:"secret_access_key"` + SessionToken string `mapstructure:"session_token"` } type S3Client struct { @@ -101,16 +101,16 @@ func NewS3Client(ctx context.Context, options ...func(*Config)) (*S3Client, erro // https://levyeran.medium.com/high-memory-allocations-and-gc-cycles-while-downloading-large-s3-objects-using-the-aws-sdk-for-go-e776a136c5d0 uploader := manager.NewUploader(awsS3Client, func(u *manager.Uploader) { - u.PartSize = config.UploaderPartSize * 1024 * 1024 + u.PartSize = config.UploaderPartSizeMB * 1024 * 1024 u.Concurrency = config.UploaderConcurrency - u.BufferProvider = manager.NewBufferedReadSeekerWriteToPool(int(config.UploaderPartSize) * 1024 * 1024) + u.BufferProvider = manager.NewBufferedReadSeekerWriteToPool(int(config.UploaderPartSizeMB) * 1024 * 1024) u.LeavePartsOnError = false }) downloader := manager.NewDownloader(awsS3Client, func(d *manager.Downloader) { - d.PartSize = config.DownloaderPartSize * 1024 * 1024 + d.PartSize = config.DownloaderPartSizeMB * 1024 * 1024 d.Concurrency = config.DownloaderConcurrency - d.BufferProvider = manager.NewPooledBufferedWriterReadFromProvider(int(config.DownloaderPartSize) * 1024 * 1024) + d.BufferProvider = manager.NewPooledBufferedWriterReadFromProvider(int(config.DownloaderPartSizeMB) * 1024 * 1024) }) presignClient := s3.NewPresignClient(awsS3Client) @@ -211,7 +211,7 @@ func WithForcePathStyle(forcePathStyle bool) func(*Config) { func WithUploaderPartSize(uploaderPartSize int64) func(*Config) { return func(c *Config) { - c.UploaderPartSize = uploaderPartSize + c.UploaderPartSizeMB = uploaderPartSize } } @@ -229,7 +229,7 @@ func WithDebug(debug bool) func(*Config) { func WithDownloaderPartSize(downloaderPartSize int64) func(*Config) { return func(c *Config) { - c.DownloaderPartSize = downloaderPartSize + c.DownloaderPartSizeMB = downloaderPartSize } } diff --git a/lib/templatestore/templatestore.go b/lib/templatestore/templatestore.go index dc8a6eb..92cf861 100644 --- a/lib/templatestore/templatestore.go +++ b/lib/templatestore/templatestore.go @@ -52,9 +52,9 @@ func TemplateStorageAdapterFactory(conf *StorageConfig) (StorageAdapter, error) s3.WithRegion(conf.S3Config.Region), s3.WithForcePathStyle(conf.S3Config.ForcePathStyle), s3.WithUploaderConcurrency(conf.S3Config.UploaderConcurrency), - s3.WithUploaderPartSize(conf.S3Config.UploaderPartSize), + s3.WithUploaderPartSize(conf.S3Config.UploaderPartSizeMB), s3.WithDownloaderConcurrency(conf.S3Config.DownloaderConcurrency), - s3.WithDownloaderPartSize(conf.S3Config.DownloaderPartSize), + s3.WithDownloaderPartSize(conf.S3Config.DownloaderPartSizeMB), s3.WithRetryMaxAttempts(conf.S3Config.RetryMaxAttempts), s3.WithBucket(conf.S3Config.Bucket), s3.WithCustomTransport(conf.S3Config.UseCustomTransport),