Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions infrastructure/file_settings_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func NewFileSettingsSource(
}

func (s *FileSettingsSource) PublicSSHKeyForUsername(string) (string, error) {
if !s.fs.FileExists(s.settingsFilePath) {
return "", bosherr.Errorf("File for settings source does not exist: '%s'", s.settingsFilePath)
}
Comment thread
fmoehler marked this conversation as resolved.
return "", nil
}
Comment thread
fmoehler marked this conversation as resolved.

Expand Down
30 changes: 26 additions & 4 deletions infrastructure/file_settings_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,32 @@ var _ = Describe("FileSettingsSource", func() {
})

Describe("PublicSSHKeyForUsername", func() {
It("returns an empty string", func() {
publicKey, err := source.PublicSSHKeyForUsername("fake-username")
Expect(err).ToNot(HaveOccurred())
Expect(publicKey).To(Equal(""))
Context("when the settings file exists", func() {
BeforeEach(func() {
settingsFileName := "/fake-settings-file-path"
source = infrastructure.NewFileSettingsSource(settingsFileName, fs, logger)
err := fs.WriteFileString(settingsFileName, "{}")
Expect(err).NotTo(HaveOccurred())
})

It("returns an empty string", func() {
publicKey, err := source.PublicSSHKeyForUsername("fake-username")
Expect(err).ToNot(HaveOccurred())
Expect(publicKey).To(Equal(""))
})
})

Context("when the settings file does not exist", func() {
BeforeEach(func() {
source = infrastructure.NewFileSettingsSource("/missing-settings-file-path", fs, logger)
})

It("returns an error with the file path", func() {
_, err := source.PublicSSHKeyForUsername("fake-username")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("File for settings source does not exist"))
Expect(err.Error()).To(ContainSubstring("/missing-settings-file-path"))
})
})
})

Expand Down
1 change: 1 addition & 0 deletions infrastructure/multi_settings_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *MultiSettingsSource) PublicSSHKeyForUsername(username string) (string,
s.selectedSSHKeySource = source
return publicSSHKey, nil
}
s.logger.Warn("multi-settings-source", "Failed to get public SSH key from source: %v", err)
}

return "", bosherr.WrapErrorf(err, "Getting public SSH key for '%s'", username)
Expand Down
10 changes: 10 additions & 0 deletions infrastructure/multi_settings_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ var _ = Describe("MultiSettingsSource", func() {
Expect(err).ToNot(HaveOccurred())
Expect(publicKey).To(Equal("fake-public-key-2"))
})

It("logs a warning for the first source", func() {
_, _ = source.PublicSSHKeyForUsername("fake-username") //nolint:errcheck
Expect(logBuffer.String()).To(ContainSubstring("fake-public-key-err-1"))
})
})

Context("when both sources fail to get ssh key", func() {
Expand All @@ -93,6 +98,11 @@ var _ = Describe("MultiSettingsSource", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-public-key-err-2"))
})

It("logs a warning for the first source", func() {
_, _ = source.PublicSSHKeyForUsername("fake-username") //nolint:errcheck
Expect(logBuffer.String()).To(ContainSubstring("fake-public-key-err-1"))
})
})
})

Expand Down
Loading