func()

in pkg/dataplane/reloadCredentials.go [147:181]


func (r *reloadingCredential) load(credentialFile string) error {
	// read the file from the filesystem and update the current value we're holding on to if the certificate we read is newer, making sure to not step on the toes of anyone calling GetToken()
	byteValue, err := os.ReadFile(credentialFile)
	if err != nil {
		return fmt.Errorf("failed to read credential file %s: %w", credentialFile, err)
	}

	var credentials UserAssignedIdentityCredentials
	if err := json.Unmarshal(byteValue, &credentials); err != nil {
		return fmt.Errorf("failed to unmarshal credential file %s: %w", credentialFile, err)
	}

	var newCertValue *azidentity.ClientCertificateCredential
	newCertValue, err = GetCredential(r.clientOpts, credentials)
	if err != nil {
		return fmt.Errorf("failed to get client certificate credential: %w", err)
	}

	r.lock.Lock()
	defer r.lock.Unlock()
	if r.notBefore != "" {
		err, ok := isLoadedCredentialNewer(*credentials.NotBefore, r.notBefore)
		if err != nil {
			return fmt.Errorf("failed to determine not_before for credential: %w", err)
		}
		if !ok {
			return nil
		}
	}

	r.currentValue = newCertValue
	r.notBefore = *credentials.NotBefore

	return nil
}