Fix a bunch of lint warnings

This commit is contained in:
joeduffy 2018-06-09 11:33:45 -07:00
parent 2e8bbcc9dd
commit 6e52490706
5 changed files with 38 additions and 20 deletions

View file

@ -37,20 +37,28 @@ type asset struct {
uri string uri string
} }
// NewFileAsset creates an asset backed by a file and specified by that file's path.
func NewFileAsset(path string) Asset { func NewFileAsset(path string) Asset {
return &asset{path: path} return &asset{path: path}
} }
// NewStringAsset creates an asset backed by a piece of in-memory text.
func NewStringAsset(text string) Asset { func NewStringAsset(text string) Asset {
return &asset{text: text} return &asset{text: text}
} }
// NewRemoteAsset creates an asset backed by a remote file and specified by that file's URL.
func NewRemoteAsset(uri string) Asset { func NewRemoteAsset(uri string) Asset {
return &asset{uri: uri} return &asset{uri: uri}
} }
// Path returns the asset's file path, if this is a file asset, or an empty string otherwise.
func (a *asset) Path() string { return a.path } func (a *asset) Path() string { return a.path }
// Text returns the asset's textual string, if this is a string asset, or an empty string otherwise.
func (a *asset) Text() string { return a.text } func (a *asset) Text() string { return a.text }
// URI returns the asset's URL, if this is a remote asset, or an empty string otherwise.
func (a *asset) URI() string { return a.uri } func (a *asset) URI() string { return a.uri }
// Archive represents a collection of Assets. // Archive represents a collection of Assets.
@ -82,14 +90,21 @@ func NewAssetArchive(assets map[string]interface{}) Archive {
return &archive{assets: assets} return &archive{assets: assets}
} }
// NewFileArchive creates an archive backed by a file and specified by that file's path.
func NewFileArchive(path string) Archive { func NewFileArchive(path string) Archive {
return &archive{path: path} return &archive{path: path}
} }
// NewRemoteArchive creates an archive backed by a remote file and specified by that file's URL.
func NewRemoteArchive(uri string) Archive { func NewRemoteArchive(uri string) Archive {
return &archive{uri: uri} return &archive{uri: uri}
} }
// Assets returns the archive's asset map, if this is a collection of archives/assets, or nil otherwise.
func (a *archive) Assets() map[string]interface{} { return a.assets } func (a *archive) Assets() map[string]interface{} { return a.assets }
// Path returns the archive's file path, if this is a file archive, or an empty string otherwise.
func (a *archive) Path() string { return a.path } func (a *archive) Path() string { return a.path }
// URI returns the archive's URL, if this is a remote archive, or an empty string otherwise.
func (a *archive) URI() string { return a.uri } func (a *archive) URI() string { return a.uri }

View file

@ -212,7 +212,7 @@ func (ctx *Context) RegisterResource(
reject(err) reject(err)
} }
} else { } else {
glog.V(9).Infof("RegisterResource(%s, %s): success: %s %s %d", resp.Urn, resp.Id, len(outprops)) glog.V(9).Infof("RegisterResource(%s, %s): success: %s %s %d", t, name, resp.Urn, resp.Id, len(outprops))
resolveURN(URN(resp.Urn)) resolveURN(URN(resp.Urn))
if resolveID != nil { if resolveID != nil {
resolveID(ID(resp.Id)) resolveID(ID(resp.Id))

View file

@ -151,7 +151,7 @@ func (out *Output) Asset() (asset.Asset, error) {
return v.(asset.Asset), nil return v.(asset.Asset), nil
} }
/// Bool retrives the underlying value for this output property as a bool. // Bool retrives the underlying value for this output property as a bool.
func (out *Output) Bool() (bool, error) { func (out *Output) Bool() (bool, error) {
v, err := out.Value() v, err := out.Value()
if err != nil { if err != nil {
@ -250,7 +250,7 @@ func (out *Output) String() (string, error) {
return cast.ToString(v), nil return cast.ToString(v), nil
} }
// Uuint retrives the underlying value for this output property as a uint. // Uint retrives the underlying value for this output property as a uint.
func (out *Output) Uint() (uint, error) { func (out *Output) Uint() (uint, error) {
v, err := out.Value() v, err := out.Value()
if err != nil { if err != nil {
@ -259,7 +259,7 @@ func (out *Output) Uint() (uint, error) {
return cast.ToUint(v), nil return cast.ToUint(v), nil
} }
// Uuint8 retrives the underlying value for this output property as a uint8. // Uint8 retrives the underlying value for this output property as a uint8.
func (out *Output) Uint8() (uint8, error) { func (out *Output) Uint8() (uint8, error) {
v, err := out.Value() v, err := out.Value()
if err != nil { if err != nil {
@ -268,7 +268,7 @@ func (out *Output) Uint8() (uint8, error) {
return cast.ToUint8(v), nil return cast.ToUint8(v), nil
} }
// Uuint16 retrives the underlying value for this output property as a uint16. // Uint16 retrives the underlying value for this output property as a uint16.
func (out *Output) Uint16() (uint16, error) { func (out *Output) Uint16() (uint16, error) {
v, err := out.Value() v, err := out.Value()
if err != nil { if err != nil {
@ -277,7 +277,7 @@ func (out *Output) Uint16() (uint16, error) {
return cast.ToUint16(v), nil return cast.ToUint16(v), nil
} }
// Uuint32 retrives the underlying value for this output property as a uint32. // Uint32 retrives the underlying value for this output property as a uint32.
func (out *Output) Uint32() (uint32, error) { func (out *Output) Uint32() (uint32, error) {
v, err := out.Value() v, err := out.Value()
if err != nil { if err != nil {
@ -286,7 +286,7 @@ func (out *Output) Uint32() (uint32, error) {
return cast.ToUint32(v), nil return cast.ToUint32(v), nil
} }
// Uuint64 retrives the underlying value for this output property as a uint64. // Uint64 retrives the underlying value for this output property as a uint64.
func (out *Output) Uint64() (uint64, error) { func (out *Output) Uint64() (uint64, error) {
v, err := out.Value() v, err := out.Value()
if err != nil { if err != nil {

View file

@ -61,6 +61,7 @@ func marshalInputs(props map[string]interface{}) ([]string, *structpb.Struct, []
} }
const ( const (
// nolint: gas, linter thinks these are creds, but they aren't.
rpcTokenSpecialSigKey = "4dabf18193072939515e22adb298388d" rpcTokenSpecialSigKey = "4dabf18193072939515e22adb298388d"
rpcTokenSpecialAssetSig = "c44067f5952c0a294b673a41bacd8c17" rpcTokenSpecialAssetSig = "c44067f5952c0a294b673a41bacd8c17"
rpcTokenSpecialArchiveSig = "0def7320c3a5731c473e5ecbe6d01bc7" rpcTokenSpecialArchiveSig = "0def7320c3a5731c473e5ecbe6d01bc7"
@ -106,12 +107,12 @@ func marshalInput(v interface{}) (interface{}, []Resource, error) {
}, nil, nil }, nil, nil
case *Output: case *Output:
// Await the value and return its raw value. // Await the value and return its raw value.
v, err := t.Value() ov, err := t.Value()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
// TODO: unknownValue // TODO: unknownValue
e, d, err := marshalInput(v) e, d, err := marshalInput(ov)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -153,12 +154,12 @@ func marshalInput(v interface{}) (interface{}, []Resource, error) {
errors.Errorf("expected map keys to be strings; got %v", reflect.TypeOf(key.Interface())) errors.Errorf("expected map keys to be strings; got %v", reflect.TypeOf(key.Interface()))
} }
value := rv.MapIndex(key) value := rv.MapIndex(key)
v, d, err := marshalInput(value.Interface()) mv, d, err := marshalInput(value.Interface())
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
obj[k] = v obj[k] = mv
deps = append(deps, d...) deps = append(deps, d...)
} }
return obj, deps, nil return obj, deps, nil
@ -243,19 +244,19 @@ func unmarshalOutput(v interface{}) (interface{}, error) {
return arr, nil return arr, nil
case reflect.Map: case reflect.Map:
// For maps, only support string-based keys, and recurse into the values. // For maps, only support string-based keys, and recurse into the values.
var obj map[string]interface{} obj := make(map[string]interface{})
for _, key := range rv.MapKeys() { for _, key := range rv.MapKeys() {
k, ok := key.Interface().(string) k, ok := key.Interface().(string)
if !ok { if !ok {
return nil, errors.Errorf("expected map keys to be strings; got %v", reflect.TypeOf(key.Interface())) return nil, errors.Errorf("expected map keys to be strings; got %v", reflect.TypeOf(key.Interface()))
} }
value := rv.MapIndex(key) value := rv.MapIndex(key)
v, err := unmarshalOutput(value) mv, err := unmarshalOutput(value)
if err != nil { if err != nil {
return nil, err return nil, err
} }
obj[k] = v obj[k] = mv
} }
return obj, nil return obj, nil
} }

View file

@ -22,6 +22,8 @@ import (
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/pulumi/pulumi/pkg/util/contract"
) )
// Run executes the body of a Pulumi program, granting it access to a deployment context that it may use // Run executes the body of a Pulumi program, granting it access to a deployment context that it may use
@ -34,7 +36,7 @@ func Run(body RunFunc) {
} }
} }
// Run executes the body of a Pulumi program, granting it access to a deployment context that it may use // RunErr executes the body of a Pulumi program, granting it access to a deployment context that it may use
// to register resources and orchestrate deployment activities. This connects back to the Pulumi engine using gRPC. // to register resources and orchestrate deployment activities. This connects back to the Pulumi engine using gRPC.
func RunErr(body RunFunc) error { func RunErr(body RunFunc) error {
// Parse the info out of environment variables. This is a lame contract with the caller, but helps to keep // Parse the info out of environment variables. This is a lame contract with the caller, but helps to keep
@ -47,7 +49,7 @@ func RunErr(body RunFunc) error {
if err != nil { if err != nil {
return err return err
} }
defer ctx.Close() defer contract.IgnoreClose(ctx)
// Create a root stack resource that we'll parent everything to. // Create a root stack resource that we'll parent everything to.
reg, err := ctx.RegisterResource( reg, err := ctx.RegisterResource(
@ -75,7 +77,7 @@ func RunErr(body RunFunc) error {
} }
// Propagate the error from the body, if any. // Propagate the error from the body, if any.
return err return result
} }
// RunFunc executes the body of a Pulumi program. It may register resources using the deployment context // RunFunc executes the body of a Pulumi program. It may register resources using the deployment context