forked from TrueCloudLab/certificates
PR fixes
- Line -> PrependLine - dont' overwrite profileDefaults - update ssh/config.tpl to always include includes file
This commit is contained in:
parent
3e9830e363
commit
43cba993bb
3 changed files with 22 additions and 17 deletions
|
@ -950,7 +950,11 @@ func (p *PKI) Save(opt ...ConfigOption) error {
|
||||||
return errs.FileError(err, p.defaults)
|
return errs.FileError(err, p.defaults)
|
||||||
}
|
}
|
||||||
if p.profileDefaults != "" {
|
if p.profileDefaults != "" {
|
||||||
if err = fileutil.WriteFile(p.profileDefaults, []byte("{}"), 0644); err != nil {
|
if _, err := os.Stat(p.profileDefaults); os.IsNotExist(err) {
|
||||||
|
if err = fileutil.WriteFile(p.profileDefaults, []byte("{}"), 0644); err != nil {
|
||||||
|
return errs.FileError(err, p.profileDefaults)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
return errs.FileError(err, p.profileDefaults)
|
return errs.FileError(err, p.profileDefaults)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,9 @@ type TemplateType string
|
||||||
const (
|
const (
|
||||||
// Snippet will mark a template as a part of a file.
|
// Snippet will mark a template as a part of a file.
|
||||||
Snippet TemplateType = "snippet"
|
Snippet TemplateType = "snippet"
|
||||||
// Line is a template for a single line in a file.
|
// PrependLine is a template for prepending a single line to a file. If the
|
||||||
Line TemplateType = "line"
|
// line already exists in the file it will be removed first.
|
||||||
|
PrependLine TemplateType = "prepend-line"
|
||||||
// File will mark a templates as a full file.
|
// File will mark a templates as a full file.
|
||||||
File TemplateType = "file"
|
File TemplateType = "file"
|
||||||
// Directory will mark a template as a directory.
|
// Directory will mark a template as a directory.
|
||||||
|
@ -120,8 +121,8 @@ func (t *Template) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
case t.Name == "":
|
case t.Name == "":
|
||||||
return errors.New("template name cannot be empty")
|
return errors.New("template name cannot be empty")
|
||||||
case t.Type != Snippet && t.Type != File && t.Type != Directory && t.Type != Line:
|
case t.Type != Snippet && t.Type != File && t.Type != Directory && t.Type != PrependLine:
|
||||||
return errors.Errorf("invalid template type %s, it must be %s, %s, %s, or %s", t.Type, Snippet, Line, File, Directory)
|
return errors.Errorf("invalid template type %s, it must be %s, %s, %s, or %s", t.Type, Snippet, PrependLine, File, Directory)
|
||||||
case t.TemplatePath == "" && t.Type != Directory && len(t.Content) == 0:
|
case t.TemplatePath == "" && t.Type != Directory && len(t.Content) == 0:
|
||||||
return errors.New("template template cannot be empty")
|
return errors.New("template template cannot be empty")
|
||||||
case t.TemplatePath != "" && t.Type == Directory:
|
case t.TemplatePath != "" && t.Type == Directory:
|
||||||
|
@ -267,7 +268,7 @@ func (o *Output) Write() error {
|
||||||
return fileutil.WriteFile(path, o.Content, 0600)
|
return fileutil.WriteFile(path, o.Content, 0600)
|
||||||
case Snippet:
|
case Snippet:
|
||||||
return fileutil.WriteSnippet(path, o.Content, 0600)
|
return fileutil.WriteSnippet(path, o.Content, 0600)
|
||||||
case Line:
|
case PrependLine:
|
||||||
return fileutil.PrependLine(path, o.Content, 0600)
|
return fileutil.PrependLine(path, o.Content, 0600)
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("unexpected output template type %s", string(o.Type))
|
return errors.Errorf("unexpected output template type %s", string(o.Type))
|
||||||
|
|
|
@ -22,23 +22,23 @@ type StepSSH struct {
|
||||||
var DefaultSSHTemplates = SSHTemplates{
|
var DefaultSSHTemplates = SSHTemplates{
|
||||||
User: []Template{
|
User: []Template{
|
||||||
{
|
{
|
||||||
Name: "base_config.tpl",
|
Name: "config.tpl",
|
||||||
Type: Snippet,
|
Type: Snippet,
|
||||||
TemplatePath: "templates/ssh/base_config.tpl",
|
TemplatePath: "templates/ssh/config.tpl",
|
||||||
Path: "~/.ssh/config",
|
Path: "~/.ssh/config",
|
||||||
Comment: "#",
|
Comment: "#",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "includes.tpl",
|
Name: "step_includes.tpl",
|
||||||
Type: Line,
|
Type: PrependLine,
|
||||||
TemplatePath: "templates/ssh/includes.tpl",
|
TemplatePath: "templates/ssh/step_includes.tpl",
|
||||||
Path: "${STEPPATH}/ssh/includes",
|
Path: "${STEPPATH}/ssh/includes",
|
||||||
Comment: "#",
|
Comment: "#",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "config.tpl",
|
Name: "step_config.tpl",
|
||||||
Type: File,
|
Type: File,
|
||||||
TemplatePath: "templates/ssh/config.tpl",
|
TemplatePath: "templates/ssh/step_config.tpl",
|
||||||
Path: "ssh/config",
|
Path: "ssh/config",
|
||||||
Comment: "#",
|
Comment: "#",
|
||||||
},
|
},
|
||||||
|
@ -76,16 +76,16 @@ var DefaultSSHTemplateData = map[string]string{
|
||||||
// Note: on windows `Include C:\...` is treated as a relative path.
|
// Note: on windows `Include C:\...` is treated as a relative path.
|
||||||
"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.StepBasePath }}
|
||||||
Include "{{ .User.StepBasePath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
|
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/includes"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- if .User.Authority }}
|
{{- if .User.StepBasePath }}
|
||||||
Include "{{.User.StepBasePath}}/ssh/includes"
|
Include "{{.User.StepBasePath}}/ssh/includes"
|
||||||
{{- else }}
|
{{- else }}
|
||||||
Include "{{.User.StepPath}}/ssh/config"
|
Include "{{.User.StepPath}}/ssh/includes"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}`,
|
{{- end }}`,
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue