2022-05-03 22:38:32 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/dustin/go-humanize"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ArtifactConfig is the internal readonly copy of the client agent's
|
|
|
|
// ArtifactConfig.
|
|
|
|
type ArtifactConfig struct {
|
|
|
|
HTTPReadTimeout time.Duration
|
|
|
|
HTTPMaxBytes int64
|
|
|
|
|
|
|
|
GCSTimeout time.Duration
|
|
|
|
GitTimeout time.Duration
|
|
|
|
HgTimeout time.Duration
|
|
|
|
S3Timeout time.Duration
|
2022-12-08 18:29:23 +00:00
|
|
|
|
2023-02-14 15:28:39 +00:00
|
|
|
DecompressionLimitFileCount int
|
|
|
|
DecompressionLimitSize int64
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
DisableFilesystemIsolation bool
|
2022-12-09 21:46:07 +00:00
|
|
|
SetEnvironmentVariables string
|
2022-05-03 22:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ArtifactConfigFromAgent creates a new internal readonly copy of the client
|
|
|
|
// agent's ArtifactConfig. The config should have already been validated.
|
|
|
|
func ArtifactConfigFromAgent(c *config.ArtifactConfig) (*ArtifactConfig, error) {
|
2022-12-08 18:29:23 +00:00
|
|
|
httpReadTimeout, err := time.ParseDuration(*c.HTTPReadTimeout)
|
2022-05-03 22:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing HTTPReadTimeout: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
httpMaxSize, err := humanize.ParseBytes(*c.HTTPMaxSize)
|
2022-05-03 22:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing HTTPMaxSize: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
gcsTimeout, err := time.ParseDuration(*c.GCSTimeout)
|
2022-05-03 22:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing GCSTimeout: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
gitTimeout, err := time.ParseDuration(*c.GitTimeout)
|
2022-05-03 22:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing GitTimeout: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
hgTimeout, err := time.ParseDuration(*c.HgTimeout)
|
2022-05-03 22:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing HgTimeout: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
s3Timeout, err := time.ParseDuration(*c.S3Timeout)
|
2022-05-03 22:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing S3Timeout: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-02-14 15:28:39 +00:00
|
|
|
decompressionSizeLimit, err := humanize.ParseBytes(*c.DecompressionSizeLimit)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing DecompressionLimitSize: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:29:23 +00:00
|
|
|
return &ArtifactConfig{
|
2023-02-14 15:28:39 +00:00
|
|
|
HTTPReadTimeout: httpReadTimeout,
|
|
|
|
HTTPMaxBytes: int64(httpMaxSize),
|
|
|
|
GCSTimeout: gcsTimeout,
|
|
|
|
GitTimeout: gitTimeout,
|
|
|
|
HgTimeout: hgTimeout,
|
|
|
|
S3Timeout: s3Timeout,
|
|
|
|
DecompressionLimitFileCount: *c.DecompressionFileCountLimit,
|
|
|
|
DecompressionLimitSize: int64(decompressionSizeLimit),
|
|
|
|
DisableFilesystemIsolation: *c.DisableFilesystemIsolation,
|
|
|
|
SetEnvironmentVariables: *c.SetEnvironmentVariables,
|
2022-12-08 18:29:23 +00:00
|
|
|
}, nil
|
2022-05-03 22:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ArtifactConfig) Copy() *ArtifactConfig {
|
|
|
|
if a == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
newCopy := *a
|
|
|
|
return &newCopy
|
|
|
|
}
|