Skip to content

Commit

Permalink
Merge pull request #246 from IBM-Cloud/dev
Browse files Browse the repository at this point in the history
promote dev to master
  • Loading branch information
boyang9527 authored Apr 9, 2021
2 parents 4cf1c7d + 50b2a46 commit 14d20d6
Show file tree
Hide file tree
Showing 11 changed files with 1,032 additions and 125 deletions.
2 changes: 1 addition & 1 deletion bin/generate-language-resources
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

go get github.com/jteeuwen/go-bindata/...
go-bindata -nometadata -pkg resources -o resources/i18n_resources.go i18n/resources/*.all.json
go-bindata -nometadata -nocompress -pkg resources -o resources/i18n_resources.go i18n/resources/*.all.json

pushd resources
go fmt ./...
Expand Down
5 changes: 4 additions & 1 deletion bluemix/terminal/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ func readPassword(fd int) (string, error) {

go func() {
<-c
terminal.Restore(fd, oldState)
err := terminal.Restore(fd, oldState)
if err != nil {
fmt.Println(err.Error())
}
os.Exit(2)
}()

Expand Down
3 changes: 2 additions & 1 deletion bluemix/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"os"
"path/filepath"
"regexp"
"strings"

Expand Down Expand Up @@ -83,7 +84,7 @@ func NewStdLogger() PrinterCloser {

// NewFileLogger creates a printer that writes to the given file path.
func NewFileLogger(path string) PrinterCloser {
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0600)
file, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_RDWR|os.O_APPEND, 0600)
if err != nil {
logger := NewStdLogger()
logger.Printf(T("An error occurred when creating log file '{{.Path}}':\n{{.Error}}\n\n", map[string]interface{}{"Path": path, "Error": err.Error()}))
Expand Down
4 changes: 2 additions & 2 deletions common/downloader/file_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func (d *FileDownloader) DownloadTo(url string, outputName string) (dest string,
}
dest = filepath.Join(d.SaveDir, outputName)

f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
f, err := os.OpenFile(filepath.Clean(dest), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
return dest, 0, err
}
defer f.Close()
defer func() { _ = f.Close() }()

var r io.Reader = resp.Body
if d.ProxyReader != nil {
Expand Down
9 changes: 6 additions & 3 deletions common/file_helpers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func CopyFile(src string, dest string) (err error) {
if err != nil {
return
}
defer srcFile.Close()
defer func() { _ = srcFile.Close() }()

srcStat, err := srcFile.Stat()
if err != nil {
Expand All @@ -51,9 +51,12 @@ func CopyFile(src string, dest string) (err error) {
if err != nil {
return
}
defer destFile.Close()
defer func() { _ = destFile.Close() }()

destFile.Chmod(srcStat.Mode())
err = destFile.Chmod(srcStat.Mode())
if err != nil {
return
}

_, err = io.Copy(destFile, srcFile)
return
Expand Down
6 changes: 3 additions & 3 deletions common/file_helpers/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func ExtractTgz(src string, dest string) error {
if err != nil {
return err
}
defer fd.Close()
defer func() { _ = fd.Close() }()

gReader, err := gzip.NewReader(fd)
if err != nil {
Expand Down Expand Up @@ -48,7 +48,7 @@ func ExtractTgz(src string, dest string) error {

func extractFileInArchive(r io.Reader, hdr *tar.Header, dest string) error {
fi := hdr.FileInfo()
path := filepath.Join(dest, hdr.Name)
path := filepath.Join(filepath.Clean(dest), filepath.Clean(hdr.Name))

if fi.IsDir() {
return os.MkdirAll(path, fi.Mode())
Expand All @@ -62,7 +62,7 @@ func extractFileInArchive(r io.Reader, hdr *tar.Header, dest string) error {
if err != nil {
return err
}
defer f.Close()
defer func() { _ = f.Close() }()

_, err = io.Copy(f, r)
return err
Expand Down
5 changes: 4 additions & 1 deletion common/rest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ func (r *Request) buildFormMultipart() (io.Reader, error) {
for _, f := range files {
defer func() {
if f, ok := f.Content.(io.ReadCloser); ok {
f.Close()
err := f.Close()
if err != nil {
fmt.Println(err.Error())
}
}
}()

Expand Down
5 changes: 4 additions & 1 deletion plugin/plugin_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func StartWithArgs(plugin Plugin, args []string) {
if err != nil {
panic(err)
}
os.Stdout.Write(json)
_, err = os.Stdout.Write(json)
if err != nil {
panic(err)
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion plugin_examples/list_plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"regexp"
"time"
"fmt"

bhttp "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/http"
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
Expand Down Expand Up @@ -92,7 +93,10 @@ func NewHTTPClient(context plugin.PluginContext) *http.Client {
}

func DefaultHeader(cf plugin.CFContext) http.Header {
cf.RefreshUAAToken()
_, err := cf.RefreshUAAToken()
if err != nil {
fmt.Println(err.Error())
}

h := http.Header{}
h.Add("Authorization", cf.UAAToken())
Expand Down
Loading

0 comments on commit 14d20d6

Please sign in to comment.