* Begin API updating * Update scope and user providers * Update group resource * Update to TF plugin SDK v2 * Finish recovery KMS workflow This also modifies groups tests to use it. It's easy to verify from the controller output that it's being used since it causes warnings to be printed. * Finish porting group resource to proposed new paradigm * Minor cleanup * Allow specifying a particular token for auth * base_url -> addr * Add test using token * Add set calls to Update * Update SDK * Update SDK * Update user and scope * Half of host catalog and some consolidation * Finish host catalog * Add host resource * Add host set resource * Update targets * Some updates to newer API * Start updating to response map standards * Finish updating already ported resources to new paradigm * Finish existing resource porting * Update target to exercise default port * Adapt target to using json.Number * Add auth method and account resources
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
// Helpers for dealing with file paths and their contents
|
|
//
|
|
// Originally from Terraform; see
|
|
// https://www.terraform.io/docs/extend/guides/v2-upgrade-guide.html#removal-of-helper-pathorcontents-package
|
|
package provider
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/mitchellh/go-homedir"
|
|
)
|
|
|
|
// If the argument is a path, Read loads it and returns the contents,
|
|
// otherwise the argument is assumed to be the desired contents and is simply
|
|
// returned.
|
|
//
|
|
// The boolean second return value can be called `wasPath` - it indicates if a
|
|
// path was detected and a file loaded.
|
|
func ReadPathOrContents(poc string) (string, bool, error) {
|
|
if len(poc) == 0 {
|
|
return poc, false, nil
|
|
}
|
|
|
|
path := poc
|
|
if path[0] == '~' {
|
|
var err error
|
|
path, err = homedir.Expand(path)
|
|
if err != nil {
|
|
return path, true, err
|
|
}
|
|
}
|
|
|
|
if _, err := os.Stat(path); err == nil {
|
|
contents, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return string(contents), true, err
|
|
}
|
|
return string(contents), true, nil
|
|
}
|
|
|
|
return poc, false, nil
|
|
}
|