From 6e524907067e5976c8a58f03245b2240b8a35eba Mon Sep 17 00:00:00 2001 From: joeduffy Date: Sat, 9 Jun 2018 11:33:45 -0700 Subject: [PATCH] Fix a bunch of lint warnings --- sdk/go/pulumi/asset/asset.go | 21 ++++++++++++++++++--- sdk/go/pulumi/context.go | 2 +- sdk/go/pulumi/properties.go | 12 ++++++------ sdk/go/pulumi/rpc.go | 15 ++++++++------- sdk/go/pulumi/run.go | 8 +++++--- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/sdk/go/pulumi/asset/asset.go b/sdk/go/pulumi/asset/asset.go index e544dd2f2..f7c2ff432 100644 --- a/sdk/go/pulumi/asset/asset.go +++ b/sdk/go/pulumi/asset/asset.go @@ -37,21 +37,29 @@ type asset struct { uri string } +// NewFileAsset creates an asset backed by a file and specified by that file's path. func NewFileAsset(path string) Asset { return &asset{path: path} } +// NewStringAsset creates an asset backed by a piece of in-memory text. func NewStringAsset(text string) Asset { 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 { 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 } + +// 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) URI() string { return a.uri } + +// 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 } // Archive represents a collection of Assets. type Archive interface { @@ -82,14 +90,21 @@ func NewAssetArchive(assets map[string]interface{}) Archive { return &archive{assets: assets} } +// NewFileArchive creates an archive backed by a file and specified by that file's path. func NewFileArchive(path string) Archive { 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 { 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) Path() string { return a.path } -func (a *archive) URI() string { return a.uri } + +// 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 } + +// 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 } diff --git a/sdk/go/pulumi/context.go b/sdk/go/pulumi/context.go index e9274904a..3c79440d7 100644 --- a/sdk/go/pulumi/context.go +++ b/sdk/go/pulumi/context.go @@ -212,7 +212,7 @@ func (ctx *Context) RegisterResource( reject(err) } } 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)) if resolveID != nil { resolveID(ID(resp.Id)) diff --git a/sdk/go/pulumi/properties.go b/sdk/go/pulumi/properties.go index 92f5d8091..13e4cf551 100644 --- a/sdk/go/pulumi/properties.go +++ b/sdk/go/pulumi/properties.go @@ -151,7 +151,7 @@ func (out *Output) Asset() (asset.Asset, error) { 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) { v, err := out.Value() if err != nil { @@ -250,7 +250,7 @@ func (out *Output) String() (string, error) { 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) { v, err := out.Value() if err != nil { @@ -259,7 +259,7 @@ func (out *Output) Uint() (uint, error) { 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) { v, err := out.Value() if err != nil { @@ -268,7 +268,7 @@ func (out *Output) Uint8() (uint8, error) { 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) { v, err := out.Value() if err != nil { @@ -277,7 +277,7 @@ func (out *Output) Uint16() (uint16, error) { 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) { v, err := out.Value() if err != nil { @@ -286,7 +286,7 @@ func (out *Output) Uint32() (uint32, error) { 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) { v, err := out.Value() if err != nil { diff --git a/sdk/go/pulumi/rpc.go b/sdk/go/pulumi/rpc.go index bfdacee71..4f9c65470 100644 --- a/sdk/go/pulumi/rpc.go +++ b/sdk/go/pulumi/rpc.go @@ -61,6 +61,7 @@ func marshalInputs(props map[string]interface{}) ([]string, *structpb.Struct, [] } const ( + // nolint: gas, linter thinks these are creds, but they aren't. rpcTokenSpecialSigKey = "4dabf18193072939515e22adb298388d" rpcTokenSpecialAssetSig = "c44067f5952c0a294b673a41bacd8c17" rpcTokenSpecialArchiveSig = "0def7320c3a5731c473e5ecbe6d01bc7" @@ -106,12 +107,12 @@ func marshalInput(v interface{}) (interface{}, []Resource, error) { }, nil, nil case *Output: // Await the value and return its raw value. - v, err := t.Value() + ov, err := t.Value() if err != nil { return nil, nil, err } // TODO: unknownValue - e, d, err := marshalInput(v) + e, d, err := marshalInput(ov) if err != nil { 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())) } value := rv.MapIndex(key) - v, d, err := marshalInput(value.Interface()) + mv, d, err := marshalInput(value.Interface()) if err != nil { return nil, nil, err } - obj[k] = v + obj[k] = mv deps = append(deps, d...) } return obj, deps, nil @@ -243,19 +244,19 @@ func unmarshalOutput(v interface{}) (interface{}, error) { return arr, nil case reflect.Map: // 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() { k, ok := key.Interface().(string) if !ok { return nil, errors.Errorf("expected map keys to be strings; got %v", reflect.TypeOf(key.Interface())) } value := rv.MapIndex(key) - v, err := unmarshalOutput(value) + mv, err := unmarshalOutput(value) if err != nil { return nil, err } - obj[k] = v + obj[k] = mv } return obj, nil } diff --git a/sdk/go/pulumi/run.go b/sdk/go/pulumi/run.go index af2a0c932..976c57224 100644 --- a/sdk/go/pulumi/run.go +++ b/sdk/go/pulumi/run.go @@ -22,6 +22,8 @@ import ( "github.com/hashicorp/go-multierror" "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 @@ -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. func RunErr(body RunFunc) error { // 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 { return err } - defer ctx.Close() + defer contract.IgnoreClose(ctx) // Create a root stack resource that we'll parent everything to. reg, err := ctx.RegisterResource( @@ -75,7 +77,7 @@ func RunErr(body RunFunc) error { } // 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