Skip to content

Commit fcc1517

Browse files
committed
Rename templates and create profileConfig dir ahead of time.
1 parent 43cba99 commit fcc1517

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

pki/pki.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,37 +87,43 @@ const (
8787
)
8888

8989
// GetDBPath returns the path where the file-system persistence is stored
90-
// based on the STEPPATH environment variable.
90+
// based on the $(step path).
9191
func GetDBPath() string {
9292
return filepath.Join(step.Path(), dbPath)
9393
}
9494

9595
// GetConfigPath returns the directory where the configuration files are stored
96-
// based on the STEPPATH environment variable.
96+
// based on the $(step path).
9797
func GetConfigPath() string {
9898
return filepath.Join(step.Path(), configPath)
9999
}
100100

101+
// GetProfileConfigPath returns the directory where the profile configuration
102+
// files are stored based on the $(step path).
103+
func GetProfileConfigPath() string {
104+
return filepath.Join(step.ProfilePath(), configPath)
105+
}
106+
101107
// GetPublicPath returns the directory where the public keys are stored based on
102-
// the STEPPATH environment variable.
108+
// the $(step path).
103109
func GetPublicPath() string {
104110
return filepath.Join(step.Path(), publicPath)
105111
}
106112

107113
// GetSecretsPath returns the directory where the private keys are stored based
108-
// on the STEPPATH environment variable.
114+
// on the $(step path).
109115
func GetSecretsPath() string {
110116
return filepath.Join(step.Path(), privatePath)
111117
}
112118

113119
// GetRootCAPath returns the path where the root CA is stored based on the
114-
// STEPPATH environment variable.
120+
// $(step path).
115121
func GetRootCAPath() string {
116122
return filepath.Join(step.Path(), publicPath, "root_ca.crt")
117123
}
118124

119125
// GetOTTKeyPath returns the path where the one-time token key is stored based
120-
// on the STEPPATH environment variable.
126+
// on the $(step path).
121127
func GetOTTKeyPath() string {
122128
return filepath.Join(step.Path(), privatePath, "ott_key")
123129
}
@@ -301,6 +307,7 @@ type PKI struct {
301307

302308
// New creates a new PKI configuration.
303309
func New(o apiv1.Options, opts ...Option) (*PKI, error) {
310+
currentCtx := step.Contexts().GetCurrent()
304311
caService, err := cas.New(context.Background(), o)
305312
if err != nil {
306313
return nil, err
@@ -359,6 +366,9 @@ func New(o apiv1.Options, opts ...Option) (*PKI, error) {
359366
cfg = GetConfigPath()
360367
// Create directories
361368
dirs := []string{public, private, cfg, GetTemplatesPath()}
369+
if currentCtx != nil {
370+
dirs = append(dirs, GetProfileConfigPath())
371+
}
362372
for _, name := range dirs {
363373
if _, err := os.Stat(name); os.IsNotExist(err) {
364374
if err = os.MkdirAll(name, 0700); err != nil {
@@ -416,8 +426,8 @@ func New(o apiv1.Options, opts ...Option) (*PKI, error) {
416426
if p.defaults, err = getPath(cfg, "defaults.json"); err != nil {
417427
return nil, err
418428
}
419-
if c := step.Contexts().GetCurrent(); c != nil {
420-
p.profileDefaults = c.ProfileDefaultsFile()
429+
if currentCtx != nil {
430+
p.profileDefaults = currentCtx.ProfileDefaultsFile()
421431
}
422432

423433
if p.config, err = getPath(cfg, "ca.json"); err != nil {

templates/values.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var DefaultSSHTemplateData = map[string]string{
7474
// base_config.tpl adds the step ssh config file.
7575
//
7676
// Note: on windows `Include C:\...` is treated as a relative path.
77-
"base_config.tpl": `Host *
77+
"config.tpl": `Host *
7878
{{- if or .User.GOOS "none" | eq "windows" }}
7979
{{- if .User.StepBasePath }}
8080
Include "{{ .User.StepBasePath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
@@ -92,13 +92,13 @@ var DefaultSSHTemplateData = map[string]string{
9292
// includes.tpl adds the step ssh config file.
9393
//
9494
// Note: on windows `Include C:\...` is treated as a relative path.
95-
"includes.tpl": `{{- if or .User.GOOS "none" | eq "windows" }}Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"{{- else }}Include "{{.User.StepPath}}/ssh/config"{{- end }}`,
95+
"step_includes.tpl": `{{- if or .User.GOOS "none" | eq "windows" }}Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"{{- else }}Include "{{.User.StepPath}}/ssh/config"{{- end }}`,
9696

9797
// config.tpl is the step ssh config file, it includes the Match rule and
9898
// references the step known_hosts file.
9999
//
100100
// Note: on windows ProxyCommand requires the full path
101-
"config.tpl": `Match exec "step ssh{{- if .User.Context }} --context {{ .User.Context }}{{- end }} check-host %h"
101+
"step_config.tpl": `Match exec "step ssh{{- if .User.Context }} --context {{ .User.Context }}{{- end }} check-host %h"
102102
{{- if .User.User }}
103103
User {{.User.User}}
104104
{{- end }}

0 commit comments

Comments
 (0)