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

Function Read

credentials/credentials.go:66–93  ·  view source on GitHub ↗

Read will load and read the origin cert.pem to load the user credentials

(originCertPath string, log *zerolog.Logger)

Source from the content-addressed store, hash-verified

64
65// Read will load and read the origin cert.pem to load the user credentials
66func Read(originCertPath string, log *zerolog.Logger) (*User, error) {
67 originCertLog := log.With().
68 Str(logFieldOriginCertPath, originCertPath).
69 Logger()
70
71 originCertPath, err := FindOriginCert(originCertPath, &originCertLog)
72 if err != nil {
73 return nil, errors.Wrap(err, "Error locating origin cert")
74 }
75 blocks, err := readOriginCert(originCertPath)
76 if err != nil {
77 return nil, errors.Wrapf(err, "Can't read origin cert from %s", originCertPath)
78 }
79
80 cert, err := decodeOriginCert(blocks)
81 if err != nil {
82 return nil, errors.Wrap(err, "Error decoding origin cert")
83 }
84
85 if cert.AccountID == "" {
86 return nil, errors.Errorf(`Origin certificate needs to be refreshed before creating new tunnels.\nDelete %s and run "cloudflared login" to obtain a new cert.`, originCertPath)
87 }
88
89 return &User{
90 cert: cert,
91 certPath: originCertPath,
92 }, nil
93}

Callers 3

GetManagementTokenFunction · 0.92
credentialMethod · 0.92
TestCredentialsReadFunction · 0.85

Calls 5

FindOriginCertFunction · 0.85
readOriginCertFunction · 0.85
decodeOriginCertFunction · 0.85
LoggerMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestCredentialsReadFunction · 0.68