Merged in feature/demo (pull request #116)
Demo prep + Fix client sync * firstversion * clientsync * configlint * fixtests
This commit is contained in:
@@ -2,10 +2,12 @@ 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"
|
||||
)
|
||||
|
||||
@@ -20,8 +22,12 @@ type ConfigProvider interface {
|
||||
}
|
||||
|
||||
type TextractConfig struct {
|
||||
AWSEndpointUrlTextract string `env:"AWS_ENDPOINT_URL_TEXTRACT"`
|
||||
TextractClient TextractClient
|
||||
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) {
|
||||
@@ -45,6 +51,15 @@ func (c *TextractConfig) SetTextractClient(ctx context.Context) error {
|
||||
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
|
||||
|
||||
@@ -21,11 +21,25 @@ func TestGetTextractClient(t *testing.T) {
|
||||
|
||||
func TestTextractClient(t *testing.T) {
|
||||
os.Clearenv()
|
||||
ctx := context.Background()
|
||||
c := textract.TextractConfig{}
|
||||
err := c.SetTextractClient(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, c.TextractClient)
|
||||
t.Run("stndard", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c := textract.TextractConfig{}
|
||||
err := c.SetTextractClient(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, c.TextractClient)
|
||||
})
|
||||
t.Run("textract specific", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c := textract.TextractConfig{
|
||||
AWSTextractAccessKeyId: "not empty",
|
||||
AWSTextractSecretAccessKey: "not empty",
|
||||
AWSTextractSessionToken: "not empty",
|
||||
AWSTextractRegion: "not empty",
|
||||
}
|
||||
err := c.SetTextractClient(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, c.TextractClient)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTextractClientWithProfile(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user