Skip to content

Commit

Permalink
Merge e5141bf into f93c9ab
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Apr 20, 2018
2 parents f93c9ab + e5141bf commit a22d66c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,39 @@ func (c *configuration) ValidateConfigFile(configFilePath string) error {
},
"config_templates":{
"type": "object",
"additionalProperties":false
"patternProperties": {
"^[a-z0-9]*$":{
"type":"object",
"additionalProperties":false,
"required": ["filepath", "content"],
"properties": {
"filepath": {
"type": "string"
},
"content": {
"type": "string"
}
}
}
}
},
"extra_templates":{
"type": "object",
"additionalProperties":false
"patternProperties": {
"^[a-z0-9]*$":{
"type":"object",
"additionalProperties":false,
"required": ["filepath","content"],
"properties": {
"filepath": {
"type": "string"
},
"content": {
"type": "string"
}
}
}
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,21 @@ func TestConfiguration_ReadConfig_DuplicateActiveTemplates(t *testing.T) {
//assert
require.Error(t, err, "should return an error if there is an duplicate active template")
}

func TestConfiguration_ReadConfig_OverrideDefaultConfigTemplate(t *testing.T) {
t.Parallel()

//setup
testConfig, _ := config.Create()

//test
err := testConfig.ReadConfig(path.Join("testdata", "valid_config_template.yaml"))
require.NoError(t, err, "should allow overriding default config template.")

configTmpl, err := testConfig.GetActiveConfigTemplate()

//assert
require.NoError(t, err, "should allow overriding default config template.")
require.Equal(t,"{{.environment}}-{{.username}}", configTmpl.FilePath)

}
19 changes: 19 additions & 0 deletions pkg/config/testdata/valid_config_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
options:
pem_dir: '~/.ssh/drawbridge/pem'
config_templates:
default:
filepath: '{{.environment}}-{{.username}}'
content: |
ForwardAgent yes
ForwardX11 no
HashKnownHosts yes
IdentitiesOnly yes
StrictHostKeyChecking no
Host bastion
Hostname bastion.example.com
User {{.username}}
IdentityFile {{.pem_dir}}/{{.pem_filename}}
LocalForward localhost:{{uniquePort .}} localhost:8080
UserKnownHostsFile=/dev/null
StrictHostKeyChecking=no
Empty file.

0 comments on commit a22d66c

Please sign in to comment.