Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/browser_manager/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package browser_manager
import (
"context"
"fmt"
"os"

log "github.com/Zomato/espresso/lib/logger"
"github.com/go-rod/rod"
Expand All @@ -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).
Expand Down
6 changes: 3 additions & 3 deletions lib/certmanager/certmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions lib/certmanager/credentialstore.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 2 additions & 3 deletions lib/renderer/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package renderer

import (
"context"
"os"
"testing"
"time"

Expand All @@ -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

Expand Down
46 changes: 23 additions & 23 deletions lib/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the use of the mapstructure tag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used by Viper to map the field name in the configuration file to the name in our Go struct.
For example,
uploader_concurrency from the YAML file should be mapped to UploaderConcurrency in our struct.

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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/templatestore/templatestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down