Change function return style

Signed-off-by: mudler <mudler@c3os.io>
This commit is contained in:
mudler 2023-01-24 16:19:33 +01:00
parent a95436bf16
commit 968ff53267

View File

@ -80,7 +80,7 @@ func (c *Client) generatePass(postEndpoint string, p *block.Partition) error {
return conn.WriteJSON(payload.Data{Passphrase: bpass, GeneratedBy: constants.TPMSecret}) return conn.WriteJSON(payload.Data{Passphrase: bpass, GeneratedBy: constants.TPMSecret})
} }
func (c *Client) waitPass(p *block.Partition, attempts int) (pass string, err error) { func (c *Client) waitPass(p *block.Partition, attempts int) (string, error) {
// IF we don't have any server configured, just do local // IF we don't have any server configured, just do local
if c.Config.Kcrypt.Challenger.Server == "" { if c.Config.Kcrypt.Challenger.Server == "" {
return localPass(c.Config) return localPass(c.Config)
@ -91,12 +91,12 @@ func (c *Client) waitPass(p *block.Partition, attempts int) (pass string, err er
for tries := 0; tries < attempts; tries++ { for tries := 0; tries < attempts; tries++ {
var generated bool var generated bool
pass, generated, err = getPass(challengeEndpoint, p) pass, generated, err := getPass(challengeEndpoint, p)
if err == errPartNotFound { if err == errPartNotFound {
// IF server doesn't have a pass for us, then we generate one and we set it // IF server doesn't have a pass for us, then we generate one and we set it
err = c.generatePass(postEndpoint, p) err = c.generatePass(postEndpoint, p)
if err != nil { if err != nil {
return return "", err
} }
// Attempt to fetch again - validate that the server has it now // Attempt to fetch again - validate that the server has it now
tries = 0 tries = 0
@ -106,14 +106,14 @@ func (c *Client) waitPass(p *block.Partition, attempts int) (pass string, err er
return c.decryptPassphrase(pass) return c.decryptPassphrase(pass)
} }
if err == nil || err == errPartNotFound { // passphrase not encrypted or not available if err == nil { // passphrase avilable, no errors
return return "", err
} }
time.Sleep(1 * time.Second) // network errors? retry time.Sleep(1 * time.Second) // network errors? retry
} }
return return "", fmt.Errorf("could not get passphrase from remote endpoint")
} }
// decryptPassphrase decodes (base64) and decrypts the passphrase returned // decryptPassphrase decodes (base64) and decrypts the passphrase returned