MCPcopy
hub / github.com/cloudflare/cloudflared / FindOriginCert

Function FindOriginCert

credentials/origin_cert.go:123–150  ·  view source on GitHub ↗

FindOriginCert will check to make sure that the certificate exists at the specified file path.

(originCertPath string, log *zerolog.Logger)

Source from the content-addressed store, hash-verified

121
122// FindOriginCert will check to make sure that the certificate exists at the specified file path.
123func FindOriginCert(originCertPath string, log *zerolog.Logger) (string, error) {
124 if originCertPath == "" {
125 log.Error().Msgf("Cannot determine default origin certificate path. No file %s in %v. You need to specify the origin certificate path by specifying the origincert option in the configuration file, or set TUNNEL_ORIGIN_CERT environment variable", DefaultCredentialFile, config.DefaultConfigSearchDirectories())
126 return "", fmt.Errorf("client didn't specify origincert path")
127 }
128 var err error
129 originCertPath, err = homedir.Expand(originCertPath)
130 if err != nil {
131 log.Err(err).Msgf("Cannot resolve origin certificate path")
132 return "", fmt.Errorf("cannot resolve path %s", originCertPath)
133 }
134 // Check that the user has acquired a certificate using the login command
135 ok := fileExists(originCertPath)
136 if !ok {
137 log.Error().Msgf(`Cannot find a valid certificate for your origin at the path:
138
139 %s
140
141If the path above is wrong, specify the path with the -origincert option.
142If you don't have a certificate signed by Cloudflare, run the command:
143
144 cloudflared login
145`, originCertPath)
146 return "", fmt.Errorf("cannot find a valid certificate at the path %s", originCertPath)
147 }
148
149 return originCertPath, nil
150}
151
152// FileExists checks to see if a file exist at the provided path.
153func fileExists(path string) bool {

Callers 4

PathMethod · 0.92
ReadFunction · 0.85
TestFindOriginCert_ValidFunction · 0.85

Calls 5

fileExistsFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.45
ErrMethod · 0.45

Tested by 2

TestFindOriginCert_ValidFunction · 0.68