1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

refactor(api): restructure bolt package (#1981)

* refactor(api): bolt package refactor

* refactor(api): refactor bolt package
This commit is contained in:
Anthony Lapenna 2018-06-19 13:15:10 +02:00 committed by GitHub
parent 6698173bf5
commit d7ff14777f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
89 changed files with 1729 additions and 1791 deletions

View file

@ -201,10 +201,21 @@ func (service *Service) WriteJSONToFile(path string, content interface{}) error
return ioutil.WriteFile(path, jsonContent, 0644)
}
// FileExists checks for the existence of the specified file.
func (service *Service) FileExists(filePath string) (bool, error) {
if _, err := os.Stat(filePath); err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
return true, nil
}
// KeyPairFilesExist checks for the existence of the key files.
func (service *Service) KeyPairFilesExist() (bool, error) {
privateKeyPath := path.Join(service.dataStorePath, PrivateKeyFile)
exists, err := fileExists(privateKeyPath)
exists, err := service.FileExists(privateKeyPath)
if err != nil {
return false, err
}
@ -213,7 +224,7 @@ func (service *Service) KeyPairFilesExist() (bool, error) {
}
publicKeyPath := path.Join(service.dataStorePath, PublicKeyFile)
exists, err = fileExists(publicKeyPath)
exists, err = service.FileExists(publicKeyPath)
if err != nil {
return false, err
}
@ -307,13 +318,3 @@ func (service *Service) getContentFromPEMFile(filePath string) ([]byte, error) {
block, _ := pem.Decode(fileContent)
return block.Bytes, nil
}
func fileExists(filePath string) (bool, error) {
if _, err := os.Stat(filePath); err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
return true, nil
}