Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,15 @@ func profileFromFile(filePath string) (*Profile, error) {
if err != nil {
return nil, trace.ConvertSystemError(err)
}
var p *Profile
var p Profile
if err := yaml.Unmarshal(bytes, &p); err != nil {
return nil, trace.Wrap(err)
}

if p.Name() == "" {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to suggestions for better ways to detect this.

We could check if bytes is empty, if p is the zero value, or look at some field other than name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet there's plenty of things in the profile yaml that could make the profile unusable if wrong; do we want to catch them all, or is it just an advisory check here?

If it's the latter I think that checking the name should be enough.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the latter. 👍

return nil, trace.NotFound("invalid or empty profile at %q", filePath)
}

p.Dir = filepath.Dir(filePath)

// Older versions of tsh did not always store the cluster name in the
Expand All @@ -371,7 +376,7 @@ func profileFromFile(filePath string) (*Profile, error) {
if p.SiteName == "" {
p.SiteName = p.Name()
}
return p, nil
return &p, nil
}

// SaveToDir saves this profile to the specified directory.
Expand Down