Read will load and read the origin cert.pem to load the user credentials
(originCertPath string, log *zerolog.Logger)
| 64 | |
| 65 | // Read will load and read the origin cert.pem to load the user credentials |
| 66 | func 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 | } |