Skip to content

Commit 43cba99

Browse files
committed
PR fixes
- Line -> PrependLine - dont' overwrite profileDefaults - update ssh/config.tpl to always include includes file
1 parent 3e9830e commit 43cba99

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

pki/pki.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,11 @@ func (p *PKI) Save(opt ...ConfigOption) error {
950950
return errs.FileError(err, p.defaults)
951951
}
952952
if p.profileDefaults != "" {
953-
if err = fileutil.WriteFile(p.profileDefaults, []byte("{}"), 0644); err != nil {
953+
if _, err := os.Stat(p.profileDefaults); os.IsNotExist(err) {
954+
if err = fileutil.WriteFile(p.profileDefaults, []byte("{}"), 0644); err != nil {
955+
return errs.FileError(err, p.profileDefaults)
956+
}
957+
} else if err != nil {
954958
return errs.FileError(err, p.profileDefaults)
955959
}
956960
}

templates/templates.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ type TemplateType string
2020
const (
2121
// Snippet will mark a template as a part of a file.
2222
Snippet TemplateType = "snippet"
23-
// Line is a template for a single line in a file.
24-
Line TemplateType = "line"
23+
// PrependLine is a template for prepending a single line to a file. If the
24+
// line already exists in the file it will be removed first.
25+
PrependLine TemplateType = "prepend-line"
2526
// File will mark a templates as a full file.
2627
File TemplateType = "file"
2728
// Directory will mark a template as a directory.
@@ -120,8 +121,8 @@ func (t *Template) Validate() error {
120121
return nil
121122
case t.Name == "":
122123
return errors.New("template name cannot be empty")
123-
case t.Type != Snippet && t.Type != File && t.Type != Directory && t.Type != Line:
124-
return errors.Errorf("invalid template type %s, it must be %s, %s, %s, or %s", t.Type, Snippet, Line, File, Directory)
124+
case t.Type != Snippet && t.Type != File && t.Type != Directory && t.Type != PrependLine:
125+
return errors.Errorf("invalid template type %s, it must be %s, %s, %s, or %s", t.Type, Snippet, PrependLine, File, Directory)
125126
case t.TemplatePath == "" && t.Type != Directory && len(t.Content) == 0:
126127
return errors.New("template template cannot be empty")
127128
case t.TemplatePath != "" && t.Type == Directory:
@@ -267,7 +268,7 @@ func (o *Output) Write() error {
267268
return fileutil.WriteFile(path, o.Content, 0600)
268269
case Snippet:
269270
return fileutil.WriteSnippet(path, o.Content, 0600)
270-
case Line:
271+
case PrependLine:
271272
return fileutil.PrependLine(path, o.Content, 0600)
272273
default:
273274
return errors.Errorf("unexpected output template type %s", string(o.Type))

templates/values.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ type StepSSH struct {
2222
var DefaultSSHTemplates = SSHTemplates{
2323
User: []Template{
2424
{
25-
Name: "base_config.tpl",
25+
Name: "config.tpl",
2626
Type: Snippet,
27-
TemplatePath: "templates/ssh/base_config.tpl",
27+
TemplatePath: "templates/ssh/config.tpl",
2828
Path: "~/.ssh/config",
2929
Comment: "#",
3030
},
3131
{
32-
Name: "includes.tpl",
33-
Type: Line,
34-
TemplatePath: "templates/ssh/includes.tpl",
32+
Name: "step_includes.tpl",
33+
Type: PrependLine,
34+
TemplatePath: "templates/ssh/step_includes.tpl",
3535
Path: "${STEPPATH}/ssh/includes",
3636
Comment: "#",
3737
},
3838
{
39-
Name: "config.tpl",
39+
Name: "step_config.tpl",
4040
Type: File,
41-
TemplatePath: "templates/ssh/config.tpl",
41+
TemplatePath: "templates/ssh/step_config.tpl",
4242
Path: "ssh/config",
4343
Comment: "#",
4444
},
@@ -76,16 +76,16 @@ var DefaultSSHTemplateData = map[string]string{
7676
// Note: on windows `Include C:\...` is treated as a relative path.
7777
"base_config.tpl": `Host *
7878
{{- if or .User.GOOS "none" | eq "windows" }}
79-
{{- if .User.Authority }}
79+
{{- if .User.StepBasePath }}
8080
Include "{{ .User.StepBasePath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
8181
{{- else }}
82-
Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"
82+
Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
8383
{{- end }}
8484
{{- else }}
85-
{{- if .User.Authority }}
85+
{{- if .User.StepBasePath }}
8686
Include "{{.User.StepBasePath}}/ssh/includes"
8787
{{- else }}
88-
Include "{{.User.StepPath}}/ssh/config"
88+
Include "{{.User.StepPath}}/ssh/includes"
8989
{{- end }}
9090
{{- end }}`,
9191

0 commit comments

Comments
 (0)