summaryrefslogtreecommitdiff
path: root/vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go')
-rw-r--r--vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go b/vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go
index ccef527..1640ec1 100644
--- a/vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go
+++ b/vendor/github.com/googleapis/enterprise-certificate-proxy/client/util/util.go
@@ -1,10 +1,23 @@
+// Copyright 2022 Google LLC.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
// Package util provides helper functions for the client.
package util
import (
"encoding/json"
"errors"
- "io/ioutil"
+ "io"
"os"
"os/user"
"path/filepath"
@@ -23,14 +36,21 @@ type Libs struct {
ECP string `json:"ecp"`
}
+// ErrConfigUnavailable is a sentinel error that indicates ECP config is unavailable,
+// possibly due to entire config missing or missing binary path.
+var ErrConfigUnavailable = errors.New("Config is unavailable")
+
// LoadSignerBinaryPath retrieves the path of the signer binary from the config file.
func LoadSignerBinaryPath(configFilePath string) (path string, err error) {
jsonFile, err := os.Open(configFilePath)
if err != nil {
+ if errors.Is(err, os.ErrNotExist) {
+ return "", ErrConfigUnavailable
+ }
return "", err
}
- byteValue, err := ioutil.ReadAll(jsonFile)
+ byteValue, err := io.ReadAll(jsonFile)
if err != nil {
return "", err
}
@@ -41,7 +61,7 @@ func LoadSignerBinaryPath(configFilePath string) (path string, err error) {
}
signerBinaryPath := config.Libs.ECP
if signerBinaryPath == "" {
- return "", errors.New("signer binary path is missing")
+ return "", ErrConfigUnavailable
}
return signerBinaryPath, nil
}