resources: Polish the password PoC and build out send/recv
This polishes the password resource so that it can actually avoid writing the password to disk, and so that the work actually happens in CheckApply where it can properly interact with the graph. This resource now re-generates the password when it receives a notification. The send/recv plumbing has been extended so that receivers can detect when they're receiving new values. This is particularly important if they might otherwise not expect those values to change and cache them for efficiency purposes.
This commit is contained in:
@@ -19,6 +19,7 @@ package resources
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -68,12 +69,11 @@ func (obj *DiskBool) Get() (bool, error) {
|
||||
return false, errwrap.Wrapf(err, "could not read token")
|
||||
}
|
||||
defer file.Close()
|
||||
str := obj.str()
|
||||
data := make([]byte, len(str)) // data + newline
|
||||
if _, err := file.Read(data); err != nil {
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return false, errwrap.Wrapf(err, "could not read from file")
|
||||
}
|
||||
return strings.TrimSpace(string(data)) == strings.TrimSpace(str), nil
|
||||
return strings.TrimSpace(string(data)) == strings.TrimSpace(obj.str()), nil
|
||||
}
|
||||
|
||||
// Set stores the true boolean value, if no error setting the value occurs.
|
||||
|
||||
Reference in New Issue
Block a user