Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement #10984 #11002

Merged
merged 2 commits into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
changes:
- type: chore
scope: sdk/go
description: Update notes, update the deprecated functions, make some lint.
10 changes: 5 additions & 5 deletions sdk/dotnet/cmd/pulumi-language-dotnet/main.go
Expand Up @@ -372,7 +372,7 @@ func DeterminePluginDependency(packageDir, packageName, packageVersion string) (
case os.IsNotExist(err):
break
case err != nil:
return nil, fmt.Errorf("Failed to read version file: %w", err)
return nil, fmt.Errorf("failed to read version file: %w", err)
}

defaultName := strings.ToLower(strings.TrimPrefix(packageName, "Pulumi."))
Expand Down Expand Up @@ -403,7 +403,7 @@ func DeterminePluginDependency(packageDir, packageName, packageVersion string) (

_, err = semver.ParseTolerant(version)
if err != nil {
return nil, fmt.Errorf("Invalid package version: %w", err)
return nil, fmt.Errorf("invalid package version: %w", err)
}

result := &pulumirpc.PluginDependency{
Expand Down Expand Up @@ -545,7 +545,7 @@ func (w *logWriter) LogToUser(val string) (int, error) {
return len(val), nil
}

// RPC endpoint for LanguageRuntimeServer::Run
// Run is the RPC endpoint for LanguageRuntimeServer::Run
func (host *dotnetLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest) (*pulumirpc.RunResponse, error) {
config, err := host.constructConfig(req)
if err != nil {
Expand Down Expand Up @@ -769,7 +769,7 @@ func (host *dotnetLanguageHost) GetProgramDependencies(
}
cmd := exec.Command(ex, cmdArgs...)
if out, err = cmd.Output(); err != nil {
return nil, fmt.Errorf("Failed to call \"%s\": %w", ex, err)
return nil, fmt.Errorf("failed to call \"%s\": %w", ex, err)
}
lines := strings.Split(strings.ReplaceAll(string(out), "\r\n", "\n"), "\n")
var packages []*pulumirpc.DependencyInfo
Expand All @@ -793,7 +793,7 @@ func (host *dotnetLanguageHost) GetProgramDependencies(
// Transitive package => name version
version = 1
} else {
return nil, fmt.Errorf("Failed to parse \"%s\"", p)
return nil, fmt.Errorf("failed to parse \"%s\"", p)
}
packages = append(packages, &pulumirpc.DependencyInfo{
Name: nameRequiredVersion[0],
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/auto/local_workspace.go
Expand Up @@ -462,7 +462,7 @@ func (l *LocalWorkspace) ImportStack(ctx context.Context, stackName string, stat
return nil
}

// Outputs get the current set of Stack outputs from the last Stack.Up().
// StackOutputs gets the current set of Stack outputs from the last Stack.Up().
func (l *LocalWorkspace) StackOutputs(ctx context.Context, stackName string) (OutputMap, error) {
// standard outputs
outStdout, outStderr, code, err := l.runPulumiCmdSync(ctx, "stack", "output", "--json", "--stack", stackName)
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/auto/optdestroy/optdestroy.go
Expand Up @@ -87,7 +87,7 @@ func UserAgent(agent string) Option {
})
}

// Show config secrets when they appear.
// ShowSecrets configures whether to show config secrets when they appear.
func ShowSecrets(show bool) Option {
return optionFunc(func(opts *Options) {
opts.ShowSecrets = &show
Expand Down
4 changes: 2 additions & 2 deletions sdk/go/auto/opthistory/opthistory.go
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package optup contains functional options to be used with stack history operations
// Package opthistory contains functional options to be used with stack history operations
// github.com/sdk/v3/go/x/auto Stack.History(ctx, pageSize, page, ...opthistory.Option)
package opthistory

// Show config secrets when they appear.
// ShowSecrets configures whether to show config secrets when they appear.
func ShowSecrets(show bool) Option {
return optionFunc(func(opts *Options) {
opts.ShowSecrets = &show
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/auto/optrefresh/optrefresh.go
Expand Up @@ -87,7 +87,7 @@ func UserAgent(agent string) Option {
})
}

// Show config secrets when they appear in the config.
// ShowSecrets configures whether to show config secrets when they appear in the config.
func ShowSecrets(show bool) Option {
return optionFunc(func(opts *Options) {
opts.ShowSecrets = &show
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/auto/optup/optup.go
Expand Up @@ -115,7 +115,7 @@ func Plan(path string) Option {
})
}

// Show config secrets when they appear.
// ShowSecrets configures whether to show config secrets when they appear.
func ShowSecrets(show bool) Option {
return optionFunc(func(opts *Options) {
opts.ShowSecrets = &show
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/auto/workspace.go
Expand Up @@ -107,7 +107,7 @@ type Workspace interface {
// ImportStack imports the specified deployment state into a pre-existing stack.
// This can be combined with ExportStack to edit a stack's state (such as recovery from failed deployments).
ImportStack(context.Context, string, apitype.UntypedDeployment) error
// Outputs get the current set of Stack outputs from the last Stack.Up().
// StackOutputs gets the current set of Stack outputs from the last Stack.Up().
StackOutputs(context.Context, string) (OutputMap, error)
}

Expand Down
6 changes: 2 additions & 4 deletions sdk/go/common/diag/sink.go
Expand Up @@ -17,12 +17,10 @@ package diag
import (
"bytes"
"fmt"
"io"
"io/ioutil"

"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/logging"
"io"
)

// Sink facilitates pluggable diagnostics messages.
Expand Down Expand Up @@ -67,7 +65,7 @@ func DefaultSink(stdout io.Writer, stderr io.Writer, opts FormatOptions) Sink {
contract.Require(stdout != nil, "stdout")
contract.Require(stderr != nil, "stderr")
// Discard debug output by default unless requested.
debug := ioutil.Discard
debug := io.Discard
if opts.Debug {
debug = stdout
}
Expand Down
11 changes: 5 additions & 6 deletions sdk/go/common/diag/sink_test.go
Expand Up @@ -16,7 +16,6 @@ package diag

import (
"io"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -27,11 +26,11 @@ import (
func discardSink() Sink {
// Create a new default sink with /dev/null writers to avoid spamming the test log.
return newDefaultSink(FormatOptions{Color: colors.Never}, map[Severity]io.Writer{
Debug: ioutil.Discard,
Info: ioutil.Discard,
Infoerr: ioutil.Discard,
Error: ioutil.Discard,
Warning: ioutil.Discard,
Debug: io.Discard,
Info: io.Discard,
Infoerr: io.Discard,
Error: io.Discard,
Warning: io.Discard,
})
}

Expand Down
21 changes: 10 additions & 11 deletions sdk/go/common/resource/asset.go
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -303,7 +302,7 @@ func (a *Asset) Bytes() ([]byte, error) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(blob)
return io.ReadAll(blob)
}

// Read begins reading an asset.
Expand Down Expand Up @@ -352,11 +351,11 @@ func (a *Asset) readPath() (*Blob, error) {
}

func (a *Asset) readURI() (*Blob, error) {
url, isurl, err := a.GetURIURL()
url, isURL, err := a.GetURIURL()
if err != nil {
return nil, err
}
contract.Assertf(isurl, "Expected a URI-based asset")
contract.Assertf(isURL, "Expected a URI-based asset")
switch s := url.Scheme; s {
case "http", "https":
resp, err := httputil.GetWithRetry(url.String(), http.DefaultClient)
Expand Down Expand Up @@ -416,7 +415,7 @@ func (blob *Blob) Size() int64 { return blob.sz }
// NewByteBlob creates a new byte blob.
func NewByteBlob(data []byte) *Blob {
return &Blob{
rd: ioutil.NopCloser(bytes.NewReader(data)),
rd: io.NopCloser(bytes.NewReader(data)),
sz: int64(len(data)),
}
}
Expand All @@ -441,7 +440,7 @@ func NewReadCloserBlob(r io.ReadCloser) (*Blob, error) {
}
// Otherwise, read it all in, and create a blob out of that.
defer contract.IgnoreClose(r)
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -886,11 +885,11 @@ func (a *Archive) readPath() (ArchiveReader, error) {

func (a *Archive) readURI() (ArchiveReader, error) {
// To read a URI-based archive, fetch the contents remotely and use the extension to pick the format to use.
url, isurl, err := a.GetURIURL()
url, isURL, err := a.GetURIURL()
if err != nil {
return nil, err
}
contract.Assertf(isurl, "Expected a URI-based asset")
contract.Assertf(isURL, "Expected a URI-based asset")

format := detectArchiveFormat(url.Path)
if format == NotArchive {
Expand Down Expand Up @@ -1052,7 +1051,7 @@ func addNextFileToZIP(r ArchiveReader, zw *zip.Writer, seenFiles map[string]bool
// the ZIP format includes a date representation that starts at 1980. Use `SetModTime` to
// remain compatible with Go 1.9.
// nolint: megacheck
fh.SetModTime(time.Date(1990, time.January, 1, 0, 0, 0, 0, time.UTC))
fh.Modified = time.Date(1990, time.January, 1, 0, 0, 0, 0, time.UTC)

fw, err := zw.CreateHeader(fh)
if err != nil {
Expand Down Expand Up @@ -1188,7 +1187,7 @@ func readArchive(ar io.ReadCloser, format ArchiveFormat) (ArchiveReader, error)
}
ra = f
sz = stat.Size()
} else if data, err := ioutil.ReadAll(ar); err != nil {
} else if data, err := io.ReadAll(ar); err != nil {
return nil, err
} else {
ra = bytes.NewReader(data)
Expand Down Expand Up @@ -1220,7 +1219,7 @@ func (r *tarArchiveReader) Next() (string, *Blob, error) {
case tar.TypeReg:
// Return the tar reader for this file's contents.
data := &Blob{
rd: ioutil.NopCloser(r.tr),
rd: io.NopCloser(r.tr),
sz: file.Size,
}
name := filepath.Clean(file.Name)
Expand Down
25 changes: 12 additions & 13 deletions sdk/go/common/resource/asset_test.go
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -120,7 +119,7 @@ func TestAssetSerialize(t *testing.T) {
t.Run("path asset", func(t *testing.T) {
t.Parallel()

f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
assert.Nil(t, err)
file := f.Name()
asset, err := NewPathAsset(file)
Expand Down Expand Up @@ -422,7 +421,7 @@ func TestArchiveTarFiles(t *testing.T) {
arch, err := NewPathArchive(repoRoot)
assert.Nil(t, err)

err = arch.Archive(TarArchive, ioutil.Discard)
err = arch.Archive(TarArchive, io.Discard)
assert.Nil(t, err)
}

Expand All @@ -436,7 +435,7 @@ func TestArchiveZipFiles(t *testing.T) {
arch, err := NewPathArchive(repoRoot)
assert.Nil(t, err)

err = arch.Archive(ZIPArchive, ioutil.Discard)
err = arch.Archive(ZIPArchive, io.Discard)
assert.Nil(t, err)
}

Expand All @@ -445,12 +444,12 @@ func TestNestedArchive(t *testing.T) {
t.Parallel()

// Create temp dir and place some files.
dirName, err := ioutil.TempDir("", "")
dirName, err := os.MkdirTemp("", "")
assert.Nil(t, err)
assert.NoError(t, os.MkdirAll(filepath.Join(dirName, "foo", "bar"), 0777))
assert.NoError(t, ioutil.WriteFile(filepath.Join(dirName, "foo", "a.txt"), []byte("a"), 0777))
assert.NoError(t, ioutil.WriteFile(filepath.Join(dirName, "foo", "bar", "b.txt"), []byte("b"), 0777))
assert.NoError(t, ioutil.WriteFile(filepath.Join(dirName, "c.txt"), []byte("c"), 0777))
assert.NoError(t, os.WriteFile(filepath.Join(dirName, "foo", "a.txt"), []byte("a"), 0777))
assert.NoError(t, os.WriteFile(filepath.Join(dirName, "foo", "bar", "b.txt"), []byte("b"), 0777))
assert.NoError(t, os.WriteFile(filepath.Join(dirName, "c.txt"), []byte("c"), 0777))

// Construct an AssetArchive with a nested PathArchive.
innerArch, err := NewPathArchive(filepath.Join(dirName, "./foo"))
Expand All @@ -464,7 +463,7 @@ func TestNestedArchive(t *testing.T) {
assert.Nil(t, err)

// Write a ZIP of the AssetArchive to disk.
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
fileName := tmpFile.Name()
assert.Nil(t, err)
err = arch.Archive(ZIPArchive, tmpFile)
Expand All @@ -488,10 +487,10 @@ func TestFileReferencedThroughMultiplePaths(t *testing.T) {
t.Parallel()

// Create temp dir and place some files.
dirName, err := ioutil.TempDir("", "")
dirName, err := os.MkdirTemp("", "")
assert.Nil(t, err)
assert.NoError(t, os.MkdirAll(filepath.Join(dirName, "foo", "bar"), 0777))
assert.NoError(t, ioutil.WriteFile(filepath.Join(dirName, "foo", "bar", "b.txt"), []byte("b"), 0777))
assert.NoError(t, os.WriteFile(filepath.Join(dirName, "foo", "bar", "b.txt"), []byte("b"), 0777))

// Construct an AssetArchive with a nested PathArchive.
outerArch, err := NewPathArchive(filepath.Join(dirName, "./foo"))
Expand All @@ -505,7 +504,7 @@ func TestFileReferencedThroughMultiplePaths(t *testing.T) {
assert.Nil(t, err)

// Write a ZIP of the AssetArchive to disk.
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
fileName := tmpFile.Name()
assert.Nil(t, err)
err = arch.Archive(ZIPArchive, tmpFile)
Expand Down Expand Up @@ -545,7 +544,7 @@ func TestInvalidPathArchive(t *testing.T) {
t.Parallel()

// Create a temp file that is not an asset.
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
fileName := tmpFile.Name()
assert.NoError(t, err)
fmt.Fprintf(tmpFile, "foo\n")
Expand Down
6 changes: 3 additions & 3 deletions sdk/go/common/resource/config/key.go
Expand Up @@ -49,7 +49,7 @@ func ParseKey(s string) (Key, error) {
return Key{namespace: s[:idx], name: s[idx+1:]}, nil
case 2:
if mm, err := tokens.ParseModuleMember(s); err == nil {
if mm.Module().Name() == tokens.ModuleName("config") {
if mm.Module().Name() == "config" {
return Key{
namespace: mm.Module().Package().String(),
name: mm.Name().String(),
Expand All @@ -62,11 +62,11 @@ func ParseKey(s string) (Key, error) {
"(configuration keys should be of the form `<namespace>:<name>`)", s)
}

func (k Key) Namespace() string {
func (k *Key) Namespace() string {
return k.namespace
}

func (k Key) Name() string {
func (k *Key) Name() string {
return k.name
}

Expand Down
7 changes: 3 additions & 4 deletions sdk/go/common/resource/plugin/analyzer_plugin.go
Expand Up @@ -222,7 +222,7 @@ func (a *analyzer) AnalyzeStack(resources []AnalyzerStackResource) ([]AnalyzeDia
continue
}

pdeps := []string{}
pdeps := make([]string, 0, 1)
for _, d := range pd {
pdeps = append(pdeps, string(d))
}
Expand Down Expand Up @@ -604,7 +604,7 @@ func convertEnforcementLevel(el pulumirpc.EnforcementLevel) (apitype.Enforcement
return apitype.Disabled, nil

default:
return "", fmt.Errorf("Invalid enforcement level %d", el)
return "", fmt.Errorf("invalid enforcement level %d", el)
}
}

Expand All @@ -615,8 +615,7 @@ func convertConfigSchema(schema *pulumirpc.PolicyConfigSchema) *AnalyzerPolicyCo

props := make(map[string]JSONSchema)
for k, v := range unmarshalMap(schema.GetProperties()) {
s := v.(map[string]interface{})
props[k] = JSONSchema(s)
props[k] = v.(JSONSchema)
}

return &AnalyzerPolicyConfigSchema{
Expand Down