rename atc/template package to vars

this fixes auto-import conflicts with text/template and moves it
somewhere central so fly doesn't have to import it from the atc

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
This commit is contained in:
Alex Suraci 2019-07-22 13:48:28 -04:00
parent 0e66d3f615
commit b1683c58c4
38 changed files with 138 additions and 129 deletions

View File

@ -11,7 +11,7 @@ import (
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/exec"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
"github.com/ghodss/yaml"
"github.com/hashicorp/go-multierror"
"github.com/tedsuo/rata"
@ -140,7 +140,7 @@ func (s *Server) SaveConfig(w http.ResponseWriter, r *http.Request) {
}
// Simply validate that the credentials exist; don't do anything with the actual secrets
func validateCredParams(credMgrVars creds.Variables, config atc.Config, session lager.Logger) error {
func validateCredParams(credMgrVars vars.Variables, config atc.Config, session lager.Logger) error {
var errs error
for _, resourceType := range config.ResourceTypes {
@ -186,7 +186,7 @@ func validateCredParams(credMgrVars creds.Variables, config atc.Config, session
} else if plan.TaskConfig != nil {
// embedded task - we can fully validate it, interpolating with cred mgr variables
var taskConfigSource exec.TaskConfigSource
embeddedTaskVars := []template.Variables{credMgrVars}
embeddedTaskVars := []vars.Variables{credMgrVars}
taskConfigSource = exec.StaticConfigSource{Config: plan.TaskConfig}
taskConfigSource = exec.InterpolateTemplateConfigSource{ConfigSource: taskConfigSource, Vars: embeddedTaskVars}
taskConfigSource = exec.ValidatingConfigSource{ConfigSource: taskConfigSource}

View File

@ -13,7 +13,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/api/accessor/accessorfakes"
"github.com/concourse/concourse/atc/creds"
@ -21,6 +20,7 @@ import (
"github.com/concourse/concourse/atc/db/dbfakes"
"github.com/concourse/concourse/atc/radar/radarfakes"
"github.com/concourse/concourse/atc/resource"
"github.com/concourse/concourse/vars"
)
var _ = Describe("Resources API", func() {
@ -28,7 +28,7 @@ var _ = Describe("Resources API", func() {
fakePipeline *dbfakes.FakePipeline
resource1 *dbfakes.FakeResource
fakeaccess = new(accessorfakes.FakeAccess)
variables creds.Variables
variables vars.Variables
)
BeforeEach(func() {
@ -1340,7 +1340,7 @@ var _ = Describe("Resources API", func() {
Context("when authorized", func() {
BeforeEach(func() {
variables = template.StaticVariables{
variables = vars.StaticVariables{
"webhook-token": "fake-token",
}
token, err := creds.NewString(variables, "((webhook-token))").Evaluate()

View File

@ -3,19 +3,19 @@ package creds
import (
"encoding/json"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
"github.com/ghodss/yaml"
)
func evaluate(variablesResolver Variables, in, out interface{}) error {
func evaluate(variablesResolver vars.Variables, in, out interface{}) error {
byteParams, err := json.Marshal(in)
if err != nil {
return err
}
tpl := template.NewTemplate(byteParams)
tpl := vars.NewTemplate(byteParams)
bytes, err := tpl.Evaluate(variablesResolver, template.EvaluateOpts{
bytes, err := tpl.Evaluate(variablesResolver, vars.EvaluateOpts{
ExpectAllKeys: true,
})
if err != nil {

View File

@ -2,14 +2,15 @@ package creds
import (
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/vars"
)
type Params struct {
variablesResolver Variables
variablesResolver vars.Variables
rawParams atc.Params
}
func NewParams(variables Variables, params atc.Params) Params {
func NewParams(variables vars.Variables, params atc.Params) Params {
return Params{
variablesResolver: variables,
rawParams: params,

View File

@ -2,12 +2,13 @@ package creds_test
import (
"fmt"
"github.com/concourse/concourse/atc/template"
"time"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/creds/credsfakes"
"github.com/concourse/concourse/vars"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"time"
)
func makeFlakySecretManager(numberOfFails int) creds.Secrets {
@ -28,7 +29,7 @@ var _ = Describe("Re-retrieval of secrets on retryable errors", func() {
It("should retry receiving a parameter in case of retryable error", func() {
flakySecretManager := makeFlakySecretManager(3)
retryableSecretManager := creds.NewRetryableSecrets(flakySecretManager, creds.SecretRetryConfig{Attempts: 5, Interval: time.Millisecond})
varDef := template.VariableDefinition{Name: "somevar"}
varDef := vars.VariableDefinition{Name: "somevar"}
value, found, err := creds.NewVariables(retryableSecretManager, "team", "pipeline").Get(varDef)
Expect(value).To(BeEquivalentTo("received value"))
Expect(found).To(BeTrue())
@ -38,7 +39,7 @@ var _ = Describe("Re-retrieval of secrets on retryable errors", func() {
It("should not receive a parameter if the number of retryable errors exceeded the number of allowed attempts", func() {
flakySecretManager := makeFlakySecretManager(10)
retryableSecretManager := creds.NewRetryableSecrets(flakySecretManager, creds.SecretRetryConfig{Attempts: 5, Interval: time.Millisecond})
varDef := template.VariableDefinition{Name: "somevar"}
varDef := vars.VariableDefinition{Name: "somevar"}
value, found, err := creds.NewVariables(retryableSecretManager, "team", "pipeline").Get(varDef)
Expect(value).To(BeNil())
Expect(found).To(BeFalse())

View File

@ -1,7 +1,7 @@
package creds
import (
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
)
type VariableLookupFromSecrets struct {
@ -9,14 +9,14 @@ type VariableLookupFromSecrets struct {
LookupPaths []SecretLookupPath
}
func NewVariables(secrets Secrets, teamName string, pipelineName string) template.Variables {
func NewVariables(secrets Secrets, teamName string, pipelineName string) vars.Variables {
return VariableLookupFromSecrets{
Secrets: secrets,
LookupPaths: secrets.NewSecretLookupPaths(teamName, pipelineName),
}
}
func (sl VariableLookupFromSecrets) Get(varDef template.VariableDefinition) (interface{}, bool, error) {
func (sl VariableLookupFromSecrets) Get(varDef vars.VariableDefinition) (interface{}, bool, error) {
// try to find a secret according to our var->secret lookup paths
if len(sl.LookupPaths) > 0 {
for _, rule := range sl.LookupPaths {
@ -41,6 +41,6 @@ func (sl VariableLookupFromSecrets) Get(varDef template.VariableDefinition) (int
}
}
func (sl VariableLookupFromSecrets) List() ([]template.VariableDefinition, error) {
func (sl VariableLookupFromSecrets) List() ([]vars.VariableDefinition, error) {
return nil, nil
}

View File

@ -1,7 +1,6 @@
package creds
import (
"github.com/concourse/concourse/atc/template"
"time"
)
@ -21,5 +20,3 @@ type Secrets interface {
// NewSecretLookupPaths returns an instance of lookup policy, which can transform pipeline ((var)) into one or more secret paths, based on team name and pipeline name
NewSecretLookupPaths(string, string) []SecretLookupPath
}
type Variables = template.Variables

View File

@ -11,7 +11,7 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface"
vars "github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
. "github.com/concourse/concourse/atc/creds/secretsmanager"
. "github.com/onsi/ginkgo"
@ -39,7 +39,7 @@ func (mock *MockSecretsManagerService) GetSecretValue(input *secretsmanager.GetS
var _ = Describe("SecretsManager", func() {
var secretAccess *SecretsManager
var variables creds.Variables
var variables vars.Variables
var varDef vars.VariableDefinition
var mockService MockSecretsManagerService

View File

@ -2,14 +2,15 @@ package creds
import (
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/vars"
)
type Source struct {
variablesResolver Variables
variablesResolver vars.Variables
rawSource atc.Source
}
func NewSource(variables Variables, source atc.Source) Source {
func NewSource(variables vars.Variables, source atc.Source) Source {
return Source{
variablesResolver: variables,
rawSource: source,

View File

@ -1,9 +1,9 @@
package creds_test
import (
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/vars"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -13,7 +13,7 @@ var _ = Describe("Evaluate", func() {
var source creds.Source
BeforeEach(func() {
variables := template.StaticVariables{
variables := vars.StaticVariables{
"some-param": "lol",
}
source = creds.NewSource(variables, atc.Source{

View File

@ -13,7 +13,7 @@ import (
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/aws-sdk-go/service/ssm/ssmiface"
. "github.com/concourse/concourse/atc/creds/ssm"
vars "github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -86,7 +86,7 @@ func (mock *MockSsmService) GetParametersByPathPages(input *ssm.GetParametersByP
var _ = Describe("Ssm", func() {
var ssmAccess *Ssm
var variables creds.Variables
var variables vars.Variables
var varDef vars.VariableDefinition
var mockService MockSsmService

View File

@ -1,11 +1,13 @@
package creds
import "github.com/concourse/concourse/vars"
type String struct {
variablesResolver Variables
variablesResolver vars.Variables
rawCredString string
}
func NewString(variables Variables, credString string) String {
func NewString(variables vars.Variables, credString string) String {
return String{
variablesResolver: variables,
rawCredString: credString,

View File

@ -1,13 +1,16 @@
package creds
import "github.com/concourse/concourse/atc"
import (
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/vars"
)
type TaskParamsValidator struct {
variablesResolver Variables
variablesResolver vars.Variables
rawTaskParams atc.Params
}
func NewTaskParamsValidator(variables Variables, params atc.Params) TaskParamsValidator {
func NewTaskParamsValidator(variables vars.Variables, params atc.Params) TaskParamsValidator {
return TaskParamsValidator{
variablesResolver: variables,
rawTaskParams: params,
@ -20,11 +23,11 @@ func (s TaskParamsValidator) Validate() error {
}
type TaskVarsValidator struct {
variablesResolver Variables
variablesResolver vars.Variables
rawTaskVars atc.Params
}
func NewTaskVarsValidator(variables Variables, taskVars atc.Params) TaskVarsValidator {
func NewTaskVarsValidator(variables vars.Variables, taskVars atc.Params) TaskVarsValidator {
return TaskVarsValidator{
variablesResolver: variables,
rawTaskVars: taskVars,

View File

@ -6,7 +6,7 @@ import (
"github.com/concourse/concourse/atc/creds"
)
// The vaultFactory will return a vault implementation of creds.Variables.
// The vaultFactory will return a vault implementation of vars.Variables.
type vaultFactory struct {
sr SecretReader
prefix string

View File

@ -1,9 +1,9 @@
package vault_test
import (
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/creds/vault"
"github.com/concourse/concourse/vars"
vaultapi "github.com/hashicorp/vault/api"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -33,7 +33,7 @@ func (msr *MockSecretReader) Read(lookupPath string) (*vaultapi.Secret, error) {
var _ = Describe("Vault", func() {
var v *vault.Vault
var variables creds.Variables
var variables vars.Variables
var msr *MockSecretReader
JustBeforeEach(func() {
@ -66,7 +66,7 @@ var _ = Describe("Vault", func() {
},
}},
}
value, found, err := variables.Get(template.VariableDefinition{Name: "foo"})
value, found, err := variables.Get(vars.VariableDefinition{Name: "foo"})
Expect(value).To(BeEquivalentTo("bar"))
Expect(found).To(BeTrue())
Expect(err).To(BeNil())
@ -81,7 +81,7 @@ var _ = Describe("Vault", func() {
},
}},
}
value, found, err := variables.Get(template.VariableDefinition{Name: "foo"})
value, found, err := variables.Get(vars.VariableDefinition{Name: "foo"})
Expect(value).To(BeEquivalentTo("bar"))
Expect(found).To(BeTrue())
Expect(err).To(BeNil())
@ -96,7 +96,7 @@ var _ = Describe("Vault", func() {
},
}},
}
value, found, err := variables.Get(template.VariableDefinition{Name: "foo"})
value, found, err := variables.Get(vars.VariableDefinition{Name: "foo"})
Expect(value).To(BeEquivalentTo("bar"))
Expect(found).To(BeTrue())
Expect(err).To(BeNil())
@ -117,7 +117,7 @@ var _ = Describe("Vault", func() {
},
}},
}
value, found, err := variables.Get(template.VariableDefinition{Name: "foo"})
value, found, err := variables.Get(vars.VariableDefinition{Name: "foo"})
Expect(value).To(BeEquivalentTo("bar"))
Expect(found).To(BeTrue())
Expect(err).To(BeNil())

View File

@ -1,6 +1,9 @@
package creds
import "github.com/concourse/concourse/atc"
import (
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/vars"
)
type VersionedResourceType struct {
atc.VersionedResourceType
@ -10,7 +13,7 @@ type VersionedResourceType struct {
type VersionedResourceTypes []VersionedResourceType
func NewVersionedResourceTypes(variables Variables, rawTypes atc.VersionedResourceTypes) VersionedResourceTypes {
func NewVersionedResourceTypes(variables vars.Variables, rawTypes atc.VersionedResourceTypes) VersionedResourceTypes {
var types VersionedResourceTypes
for _, t := range rawTypes {
types = append(types, VersionedResourceType{

View File

@ -12,7 +12,7 @@ import (
"github.com/concourse/baggageclaim"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/exec/artifact"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
"github.com/ghodss/yaml"
)
@ -158,7 +158,7 @@ func (configSource OverrideParamsConfigSource) Warnings() []string {
// InterpolateTemplateConfigSource represents a config source interpolated by template vars
type InterpolateTemplateConfigSource struct {
ConfigSource TaskConfigSource
Vars []template.Variables
Vars []vars.Variables
}
// FetchConfig returns the interpolated configuration
@ -174,7 +174,7 @@ func (configSource InterpolateTemplateConfigSource) FetchConfig(logger lager.Log
}
// process task config using the provided variables
byteConfig, err = template.NewTemplateResolver(byteConfig, configSource.Vars).Resolve(true, true)
byteConfig, err = vars.NewTemplateResolver(byteConfig, configSource.Vars).Resolve(true, true)
if err != nil {
return atc.TaskConfig{}, fmt.Errorf("failed to interpolate task config: %s", err)
}

View File

@ -9,8 +9,8 @@ import (
. "github.com/concourse/concourse/atc/exec"
"github.com/concourse/concourse/atc/exec/artifact"
"github.com/concourse/concourse/atc/exec/execfakes"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc/worker/workerfakes"
"github.com/concourse/concourse/vars"
"github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -412,7 +412,7 @@ run: {path: a/file}
JustBeforeEach(func() {
configSource = StaticConfigSource{Config: &taskConfig}
configSource = InterpolateTemplateConfigSource{ConfigSource: configSource, Vars: []template.Variables{template.StaticVariables(taskVars)}}
configSource = InterpolateTemplateConfigSource{ConfigSource: configSource, Vars: []vars.Variables{vars.StaticVariables(taskVars)}}
fetchedConfig, fetchErr = configSource.FetchConfig(logger, repo)
})

View File

@ -14,13 +14,13 @@ import (
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagerctx"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/db/lock"
"github.com/concourse/concourse/atc/exec/artifact"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/vars"
)
const taskProcessID = "task"
@ -137,20 +137,20 @@ func (step *TaskStep) Run(ctx context.Context, state RunState) error {
}
var taskConfigSource TaskConfigSource
var taskVars []template.Variables
var taskVars []vars.Variables
if step.plan.ConfigPath != "" {
// external task - construct a source which reads it from file
taskConfigSource = FileConfigSource{ConfigPath: step.plan.ConfigPath}
// for interpolation - use 'vars' from the pipeline, and then fill remaining with cred variables
taskVars = []template.Variables{template.StaticVariables(step.plan.Vars), variables}
taskVars = []vars.Variables{vars.StaticVariables(step.plan.Vars), variables}
} else {
// embedded task - first we take it
taskConfigSource = StaticConfigSource{Config: step.plan.Config}
// for interpolation - use just cred variables
taskVars = []template.Variables{variables}
taskVars = []vars.Variables{variables}
}
// override params

View File

@ -8,16 +8,16 @@ import (
"github.com/concourse/concourse/atc/pipelines"
"github.com/concourse/concourse/atc/radar"
"github.com/concourse/concourse/atc/scheduler"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
)
type FakeRadarSchedulerFactory struct {
BuildScanRunnerFactoryStub func(db.Pipeline, string, template.Variables, radar.Notifications) radar.ScanRunnerFactory
BuildScanRunnerFactoryStub func(db.Pipeline, string, vars.Variables, radar.Notifications) radar.ScanRunnerFactory
buildScanRunnerFactoryMutex sync.RWMutex
buildScanRunnerFactoryArgsForCall []struct {
arg1 db.Pipeline
arg2 string
arg3 template.Variables
arg3 vars.Variables
arg4 radar.Notifications
}
buildScanRunnerFactoryReturns struct {
@ -41,13 +41,13 @@ type FakeRadarSchedulerFactory struct {
invocationsMutex sync.RWMutex
}
func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactory(arg1 db.Pipeline, arg2 string, arg3 template.Variables, arg4 radar.Notifications) radar.ScanRunnerFactory {
func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactory(arg1 db.Pipeline, arg2 string, arg3 vars.Variables, arg4 radar.Notifications) radar.ScanRunnerFactory {
fake.buildScanRunnerFactoryMutex.Lock()
ret, specificReturn := fake.buildScanRunnerFactoryReturnsOnCall[len(fake.buildScanRunnerFactoryArgsForCall)]
fake.buildScanRunnerFactoryArgsForCall = append(fake.buildScanRunnerFactoryArgsForCall, struct {
arg1 db.Pipeline
arg2 string
arg3 template.Variables
arg3 vars.Variables
arg4 radar.Notifications
}{arg1, arg2, arg3, arg4})
fake.recordInvocation("BuildScanRunnerFactory", []interface{}{arg1, arg2, arg3, arg4})
@ -68,13 +68,13 @@ func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactoryCallCount() int {
return len(fake.buildScanRunnerFactoryArgsForCall)
}
func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactoryCalls(stub func(db.Pipeline, string, template.Variables, radar.Notifications) radar.ScanRunnerFactory) {
func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactoryCalls(stub func(db.Pipeline, string, vars.Variables, radar.Notifications) radar.ScanRunnerFactory) {
fake.buildScanRunnerFactoryMutex.Lock()
defer fake.buildScanRunnerFactoryMutex.Unlock()
fake.BuildScanRunnerFactoryStub = stub
}
func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactoryArgsForCall(i int) (db.Pipeline, string, template.Variables, radar.Notifications) {
func (fake *FakeRadarSchedulerFactory) BuildScanRunnerFactoryArgsForCall(i int) (db.Pipeline, string, vars.Variables, radar.Notifications) {
fake.buildScanRunnerFactoryMutex.RLock()
defer fake.buildScanRunnerFactoryMutex.RUnlock()
argsForCall := fake.buildScanRunnerFactoryArgsForCall[i]

View File

@ -5,7 +5,6 @@ import (
"code.cloudfoundry.org/clock"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/radar"
"github.com/concourse/concourse/atc/resource"
@ -15,11 +14,13 @@ import (
"github.com/concourse/concourse/atc/scheduler/inputmapper/inputconfig"
"github.com/concourse/concourse/atc/scheduler/maxinflight"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/vars"
)
//go:generate counterfeiter . RadarSchedulerFactory
type RadarSchedulerFactory interface {
BuildScanRunnerFactory(dbPipeline db.Pipeline, externalURL string, variables creds.Variables, notifications radar.Notifications) radar.ScanRunnerFactory
BuildScanRunnerFactory(dbPipeline db.Pipeline, externalURL string, variables vars.Variables, notifications radar.Notifications) radar.ScanRunnerFactory
BuildScheduler(pipeline db.Pipeline) scheduler.BuildScheduler
}
@ -50,7 +51,7 @@ func NewRadarSchedulerFactory(
}
}
func (rsf *radarSchedulerFactory) BuildScanRunnerFactory(dbPipeline db.Pipeline, externalURL string, variables creds.Variables, notifications radar.Notifications) radar.ScanRunnerFactory {
func (rsf *radarSchedulerFactory) BuildScanRunnerFactory(dbPipeline db.Pipeline, externalURL string, variables vars.Variables, notifications radar.Notifications) radar.ScanRunnerFactory {
return radar.NewScanRunnerFactory(
rsf.pool,
rsf.resourceFactory,

View File

@ -15,6 +15,7 @@ import (
"github.com/concourse/concourse/atc/metric"
"github.com/concourse/concourse/atc/resource"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/vars"
)
var GlobalResourceCheckTimeout time.Duration
@ -27,7 +28,7 @@ type resourceScanner struct {
defaultInterval time.Duration
dbPipeline db.Pipeline
externalURL string
variables creds.Variables
variables vars.Variables
strategy worker.ContainerPlacementStrategy
}
@ -39,7 +40,7 @@ func NewResourceScanner(
defaultInterval time.Duration,
dbPipeline db.Pipeline,
externalURL string,
variables creds.Variables,
variables vars.Variables,
strategy worker.ContainerPlacementStrategy,
) Scanner {
return &resourceScanner{

View File

@ -8,9 +8,7 @@ import (
"code.cloudfoundry.org/clock/fakeclock"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagertest"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/db/dbfakes"
"github.com/concourse/concourse/atc/db/lock"
@ -18,6 +16,7 @@ import (
"github.com/concourse/concourse/atc/radar"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/atc/worker/workerfakes"
"github.com/concourse/concourse/vars"
. "github.com/concourse/concourse/atc/radar"
"github.com/concourse/concourse/atc/resource"
@ -40,7 +39,7 @@ var _ = Describe("ResourceScanner", func() {
fakeDBPipeline *dbfakes.FakePipeline
fakeClock *fakeclock.FakeClock
interval time.Duration
variables creds.Variables
variables vars.Variables
fakeResourceType *dbfakes.FakeResourceType
interpolatedResourceTypes atc.VersionedResourceTypes
@ -62,7 +61,7 @@ var _ = Describe("ResourceScanner", func() {
fakeLock = &lockfakes.FakeLock{}
interval = 1 * time.Minute
GlobalResourceCheckTimeout = 1 * time.Hour
variables = template.StaticVariables{
variables = vars.StaticVariables{
"source-params": "some-secret-sauce",
}

View File

@ -12,6 +12,7 @@ import (
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/resource"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/vars"
)
type resourceTypeScanner struct {
@ -22,7 +23,7 @@ type resourceTypeScanner struct {
defaultInterval time.Duration
dbPipeline db.Pipeline
externalURL string
variables creds.Variables
variables vars.Variables
strategy worker.ContainerPlacementStrategy
}
@ -34,7 +35,7 @@ func NewResourceTypeScanner(
defaultInterval time.Duration,
dbPipeline db.Pipeline,
externalURL string,
variables creds.Variables,
variables vars.Variables,
strategy worker.ContainerPlacementStrategy,
) Scanner {
return &resourceTypeScanner{

View File

@ -8,9 +8,7 @@ import (
"code.cloudfoundry.org/clock/fakeclock"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagertest"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/db/dbfakes"
"github.com/concourse/concourse/atc/db/lock"
@ -19,6 +17,7 @@ import (
"github.com/concourse/concourse/atc/resource"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/atc/worker/workerfakes"
"github.com/concourse/concourse/vars"
rfakes "github.com/concourse/concourse/atc/resource/resourcefakes"
. "github.com/onsi/ginkgo"
@ -40,8 +39,8 @@ var _ = Describe("ResourceTypeScanner", func() {
fakeResourceConfigScope *dbfakes.FakeResourceConfigScope
fakeClock *fakeclock.FakeClock
interval time.Duration
variables creds.Variables
metadata db.ContainerMetadata
variables vars.Variables
metadata db.ContainerMetadata
fakeResourceType *dbfakes.FakeResourceType
interpolatedResourceTypes atc.VersionedResourceTypes
@ -55,7 +54,7 @@ var _ = Describe("ResourceTypeScanner", func() {
BeforeEach(func() {
fakeLock = &lockfakes.FakeLock{}
interval = 1 * time.Minute
variables = template.StaticVariables{
variables = vars.StaticVariables{
"source-params": "some-secret-sauce",
}
@ -594,7 +593,7 @@ var _ = Describe("ResourceTypeScanner", func() {
Expect(resourceSource).To(Equal(atc.Source{"custom": "some-secret-sauce"}))
Expect(resourceTypes).To(Equal(interpolatedResourceTypes))
_, _, owner, containerSpec, workerSpec, _ := fakePool.FindOrChooseWorkerForContainerArgsForCall(0)
_, _, owner, containerSpec, workerSpec, _ := fakePool.FindOrChooseWorkerForContainerArgsForCall(0)
Expect(owner).To(Equal(db.NewResourceConfigCheckSessionContainerOwner(fakeResourceConfig, ContainerExpiries)))
Expect(containerSpec.ImageSpec).To(Equal(worker.ImageSpec{
ResourceType: "registry-image",

View File

@ -3,10 +3,10 @@ package radar
import (
"time"
"github.com/concourse/concourse/atc/creds"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/resource"
"github.com/concourse/concourse/atc/worker"
"github.com/concourse/concourse/vars"
"code.cloudfoundry.org/clock"
"code.cloudfoundry.org/lager"
@ -35,7 +35,7 @@ func NewScanRunnerFactory(
dbPipeline db.Pipeline,
clock clock.Clock,
externalURL string,
variables creds.Variables,
variables vars.Variables,
strategy worker.ContainerPlacementStrategy,
notifications Notifications,
) ScanRunnerFactory {

View File

@ -5,8 +5,8 @@ import (
"io/ioutil"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/concourse/vars"
"github.com/ghodss/yaml"
)
@ -47,17 +47,17 @@ func (yamlTemplate YamlTemplateWithParams) Evaluate(
}
}
var params []template.Variables
var params []vars.Variables
// first, we take explicitly specified variables on the command line
vars := template.StaticVariables{}
flagVars := vars.StaticVariables{}
for _, f := range yamlTemplate.templateVariables {
vars[f.Name] = f.Value
flagVars[f.Name] = f.Value
}
for _, f := range yamlTemplate.yamlTemplateVariables {
vars[f.Name] = f.Value
flagVars[f.Name] = f.Value
}
params = append(params, vars)
params = append(params, flagVars)
// second, we take all files. with values in the files specified later on command line taking precedence over the
// same values in the files specified earlier on command line
@ -68,7 +68,7 @@ func (yamlTemplate YamlTemplateWithParams) Evaluate(
return nil, fmt.Errorf("could not read template variables file (%s): %s", string(path), err.Error())
}
var staticVars template.StaticVariables
var staticVars vars.StaticVariables
err = yaml.Unmarshal(templateVars, &staticVars)
if err != nil {
return nil, fmt.Errorf("could not unmarshal template variables (%s): %s", string(path), err.Error())
@ -77,7 +77,7 @@ func (yamlTemplate YamlTemplateWithParams) Evaluate(
params = append(params, staticVars)
}
evaluatedConfig, err := template.NewTemplateResolver(config, params).Resolve(false, allowEmpty)
evaluatedConfig, err := vars.NewTemplateResolver(config, params).Resolve(false, allowEmpty)
if err != nil {
return nil, err
}

View File

@ -1,4 +1,4 @@
package template
package vars
type MultiVars struct {
varss []Variables

View File

@ -1,4 +1,4 @@
package template_test
package vars_test
import (
"errors"
@ -6,7 +6,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/concourse/concourse/atc/template"
. "github.com/concourse/concourse/vars"
)
var _ = Describe("MultiVariables", func() {

View File

@ -1,4 +1,4 @@
package template
package vars
import (
"strings"

View File

@ -1,10 +1,10 @@
package template_test
package vars_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/concourse/concourse/atc/template"
. "github.com/concourse/concourse/vars"
)
var _ = Describe("StaticVariables", func() {

View File

@ -1,4 +1,4 @@
package template_test
package vars_test
import (
"testing"
@ -6,7 +6,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/concourse/concourse/atc/template"
. "github.com/concourse/concourse/vars"
)
func TestReg(t *testing.T) {

View File

@ -1,4 +1,4 @@
package template
package vars
import (
"fmt"

View File

@ -1,4 +1,4 @@
package template
package vars
import (
"encoding/json"

View File

@ -1,7 +1,7 @@
package template_test
package vars_test
import (
"github.com/concourse/concourse/atc/template"
"github.com/concourse/concourse/vars"
"github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -11,7 +11,7 @@ var _ = Describe("Template", func() {
var (
paramPayload []byte
configPayload []byte
staticVars template.StaticVariables
staticVars vars.StaticVariables
)
BeforeEach(func() {
@ -56,10 +56,10 @@ jobs:
})
It("evaluates all params", func() {
evaluatedContent1, err := template.NewTemplateResolver(configPayload, []template.Variables{staticVars}).Resolve(false, true)
evaluatedContent1, err := vars.NewTemplateResolver(configPayload, []vars.Variables{staticVars}).Resolve(false, true)
Expect(err).NotTo(HaveOccurred())
evaluatedContent2, err := template.NewTemplateResolver(configPayload, []template.Variables{staticVars}).Resolve(true, true)
evaluatedContent2, err := vars.NewTemplateResolver(configPayload, []vars.Variables{staticVars}).Resolve(true, true)
Expect(err).NotTo(HaveOccurred())
Expect(evaluatedContent1).To(Equal(evaluatedContent2))
@ -102,7 +102,7 @@ resources:
})
It("evaluates only given params if expectAllKeys = false", func() {
evaluatedContent, err := template.NewTemplateResolver(configPayload, []template.Variables{staticVars}).Resolve(false, true)
evaluatedContent, err := vars.NewTemplateResolver(configPayload, []vars.Variables{staticVars}).Resolve(false, true)
Expect(err).NotTo(HaveOccurred())
Expect(evaluatedContent).To(MatchYAML([]byte(`
resources:
@ -119,14 +119,14 @@ resources:
})
It("fails with an error if expectAllKeys = true", func() {
_, err := template.NewTemplateResolver(configPayload, []template.Variables{staticVars}).Resolve(true, true)
_, err := vars.NewTemplateResolver(configPayload, []vars.Variables{staticVars}).Resolve(true, true)
Expect(err).To(HaveOccurred())
})
})
Context("when multiple variable sources are given", func() {
var staticVars2 template.StaticVariables
var staticVars2 vars.StaticVariables
BeforeEach(func() {
configPayload = []byte(`
@ -162,7 +162,7 @@ env: some-env-override
It("evaluates params using param sources in the given order", func() {
// forward order
evaluatedContent1, err := template.NewTemplateResolver(configPayload, []template.Variables{staticVars, staticVars2}).Resolve(false, true)
evaluatedContent1, err := vars.NewTemplateResolver(configPayload, []vars.Variables{staticVars, staticVars2}).Resolve(false, true)
Expect(err).NotTo(HaveOccurred())
Expect(evaluatedContent1).To(MatchYAML([]byte(`
resources:
@ -186,7 +186,7 @@ jobs:
)))
// reverse order
evaluatedContent2, err := template.NewTemplateResolver(configPayload, []template.Variables{staticVars2, staticVars}).Resolve(false, true)
evaluatedContent2, err := vars.NewTemplateResolver(configPayload, []vars.Variables{staticVars2, staticVars}).Resolve(false, true)
Expect(err).NotTo(HaveOccurred())
Expect(evaluatedContent2).To(MatchYAML([]byte(`
resources:
@ -215,91 +215,91 @@ jobs:
It("can template values into a byte slice", func() {
byteSlice := []byte("{{key}}")
variables := template.StaticVariables{
variables := vars.StaticVariables{
"key": "foo",
}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte(`"foo"`)))
})
It("can template multiple values into a byte slice", func() {
byteSlice := []byte("{{key}}={{value}}")
variables := template.StaticVariables{
variables := vars.StaticVariables{
"key": "foo",
"value": "bar",
}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte(`"foo"="bar"`)))
})
It("can template unicode values into a byte slice", func() {
byteSlice := []byte("{{Ω}}")
variables := template.StaticVariables{
variables := vars.StaticVariables{
"Ω": "☃",
}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte(`"☃"`)))
})
It("can template keys with dashes and underscores into a byte slice", func() {
byteSlice := []byte("{{with-a-dash}} = {{with_an_underscore}}")
variables := template.StaticVariables{
variables := vars.StaticVariables{
"with-a-dash": "dash",
"with_an_underscore": "underscore",
}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte(`"dash" = "underscore"`)))
})
It("can template the same value multiple times into a byte slice", func() {
byteSlice := []byte("{{key}}={{key}}")
variables := template.StaticVariables{
variables := vars.StaticVariables{
"key": "foo",
}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte(`"foo"="foo"`)))
})
It("can template values with strange newlines", func() {
byteSlice := []byte("{{key}}")
variables := template.StaticVariables{
variables := vars.StaticVariables{
"key": "this\nhas\nmany\nlines",
}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte(`"this\nhas\nmany\nlines"`)))
})
It("raises an error for each variable that is undefined", func() {
byteSlice := []byte("{{not-specified-one}}{{not-specified-two}}")
variables := template.StaticVariables{}
variables := vars.StaticVariables{}
errorMsg := `2 errors occurred:
* unbound variable in template: 'not-specified-one'
* unbound variable in template: 'not-specified-two'
`
_, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
_, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(errorMsg))
})
It("ignores an invalid input", func() {
byteSlice := []byte("{{}")
variables := template.StaticVariables{}
variables := vars.StaticVariables{}
result, err := template.NewTemplateResolver(byteSlice, []template.Variables{variables}).ResolveDeprecated(false)
result, err := vars.NewTemplateResolver(byteSlice, []vars.Variables{variables}).ResolveDeprecated(false)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal([]byte("{{}")))
})

View File

@ -1,4 +1,4 @@
package template_test
package vars_test
import (
"errors"
@ -6,7 +6,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/concourse/concourse/atc/template"
. "github.com/concourse/concourse/vars"
)
var _ = Describe("Template", func() {

View File

@ -1,4 +1,4 @@
package template
package vars
type Variables interface {
Get(VariableDefinition) (interface{}, bool, error)