Update includes template to use STEPPATH as the replace var

This commit is contained in:
max furman 2021-11-10 14:53:44 -08:00
parent 74eea88343
commit 9d4a7cf9fc
2 changed files with 10 additions and 7 deletions

View file

@ -249,6 +249,9 @@ type Output struct {
// Write writes the Output to the filesystem as a directory, file or snippet. // Write writes the Output to the filesystem as a directory, file or snippet.
func (o *Output) Write() error { func (o *Output) Write() error {
// Replace ${STEPPATH} with the base step path.
o.Path = strings.Replace(o.Path, "${STEPPATH}", step.BasePath(), -1)
path := step.Abs(o.Path) path := step.Abs(o.Path)
if o.Type == Directory { if o.Type == Directory {
return mkdir(path, 0700) return mkdir(path, 0700)

View file

@ -29,10 +29,10 @@ var DefaultSSHTemplates = SSHTemplates{
Comment: "#", Comment: "#",
}, },
{ {
Name: "include.tpl", Name: "includes.tpl",
Type: Line, Type: Line,
TemplatePath: "templates/ssh/include.tpl", TemplatePath: "templates/ssh/includes.tpl",
Path: "~/.ssh/include", Path: "${STEPPATH}/ssh/includes",
Comment: "#", Comment: "#",
}, },
{ {
@ -77,22 +77,22 @@ var DefaultSSHTemplateData = map[string]string{
"base_config.tpl": `Host * "base_config.tpl": `Host *
{{- if or .User.GOOS "none" | eq "windows" }} {{- if or .User.GOOS "none" | eq "windows" }}
{{- if .User.Authority }} {{- if .User.Authority }}
Include "{{ .User.Home | replace "\\" "/" | trimPrefix "C:" }}/.ssh/include" Include "{{ .User.StepBasePath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
{{- else }} {{- else }}
Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config" Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"
{{- end }} {{- end }}
{{- else }} {{- else }}
{{- if .User.Authority }} {{- if .User.Authority }}
Include "{{.User.Home}}/.ssh/include" Include "{{.User.StepBasePath}}/ssh/includes"
{{- else }} {{- else }}
Include "{{.User.StepPath}}/ssh/config" Include "{{.User.StepPath}}/ssh/config"
{{- end }} {{- end }}
{{- end }}`, {{- end }}`,
// include.tpl adds the step ssh config file. // includes.tpl adds the step ssh config file.
// //
// Note: on windows `Include C:\...` is treated as a relative path. // Note: on windows `Include C:\...` is treated as a relative path.
"include.tpl": `{{- if or .User.GOOS "none" | eq "windows" }}Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"{{- else }}Include "{{.User.StepPath}}/ssh/config"{{- end }}`, "includes.tpl": `{{- if or .User.GOOS "none" | eq "windows" }}Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"{{- else }}Include "{{.User.StepPath}}/ssh/config"{{- end }}`,
// config.tpl is the step ssh config file, it includes the Match rule and // config.tpl is the step ssh config file, it includes the Match rule and
// references the step known_hosts file. // references the step known_hosts file.