47fec079e5
Demo prep + Fix client sync * firstversion * clientsync * configlint * fixtests
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package textract
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
awsc "queryorchestration/internal/serviceconfig/aws"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
|
"github.com/aws/aws-sdk-go-v2/service/textract"
|
|
)
|
|
|
|
type ConfigProvider interface {
|
|
awsc.ConfigProvider
|
|
SetTextractClient(context.Context) error
|
|
SetTextractClientWithCfg(context.Context, aws.Config)
|
|
SetTextractClientWithProfile(context.Context, awsc.Profile) error
|
|
GetTextractClient() TextractClient
|
|
SetTextractEndpoint(string)
|
|
GetTextractEndpoint() string
|
|
}
|
|
|
|
type TextractConfig struct {
|
|
AWSEndpointUrlTextract string `env:"AWS_ENDPOINT_URL_TEXTRACT"`
|
|
AWSTextractAccessKeyId string `env:"AWS_ACCESS_KEY_ID_TEXTRACT"`
|
|
AWSTextractSecretAccessKey string `env:"AWS_SECRET_ACCESS_KEY_TEXTRACT"`
|
|
AWSTextractSessionToken string `env:"AWS_SESSION_TOKEN_TEXTRACT"`
|
|
AWSTextractRegion string `env:"AWS_REGION_TEXTRACT"`
|
|
TextractClient TextractClient
|
|
}
|
|
|
|
func (c *TextractConfig) SetTextractClientWithCfg(ctx context.Context, cfg aws.Config) {
|
|
c.TextractClient = textract.NewFromConfig(cfg)
|
|
}
|
|
|
|
func (c *TextractConfig) SetTextractClientWithProfile(ctx context.Context, profile awsc.Profile) error {
|
|
cfg, err := awsc.GetAWSConfigWithProfile(ctx, profile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.SetTextractClientWithCfg(ctx, cfg)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *TextractConfig) SetTextractClient(ctx context.Context) error {
|
|
cfg, err := awsc.GetAWSConfig(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if c.AWSTextractAccessKeyId != "" && c.AWSTextractSecretAccessKey != "" {
|
|
cfg.Credentials = credentials.NewStaticCredentialsProvider(c.AWSTextractAccessKeyId, c.AWSTextractSecretAccessKey, c.AWSTextractSessionToken)
|
|
|
|
if c.AWSTextractRegion != "" {
|
|
cfg.Region = c.AWSTextractRegion
|
|
}
|
|
slog.Debug("textract specific credentials", "key_id", c.AWSTextractAccessKeyId, "region", c.AWSTextractRegion)
|
|
}
|
|
|
|
c.SetTextractClientWithCfg(ctx, cfg)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *TextractConfig) GetTextractClient() TextractClient {
|
|
return c.TextractClient
|
|
}
|
|
|
|
func (c *TextractConfig) GetTextractEndpoint() string {
|
|
return c.AWSEndpointUrlTextract
|
|
}
|
|
|
|
func (c *TextractConfig) SetTextractEndpoint(e string) {
|
|
c.AWSEndpointUrlTextract = e
|
|
}
|