Skip to content

Commit

Permalink
Use latest netrcutil package (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborszakacs authored Jul 11, 2023
1 parent 67b0d01 commit b37dd5b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.15
github.com/bitrise-io/go-utils v1.0.1
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.15
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230711084209-91fcd09b2017
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/stretchr/testify v1.8.1
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/bitrise-io/stepman v0.0.0-20210505110307-5c2296bcc558/go.mod h1:WLh58
github.com/bitrise-io/stepman v0.0.0-20210517135458-203f7a48d37a/go.mod h1:WLh58JYBgbD1Z/yyw1AkFz/90F6oBL0HS/luBpUW9dI=
github.com/bitrise-io/xcode-project v0.0.0-20201203153351-7ad13a1dd021/go.mod h1:R2iDrjJlNQtVwIdXT+F9bcx/YTNJPdd0tXfFRJsxHaM=
github.com/bitrise-io/xcode-project v0.0.0-20210302080829-f3e0bfbcd5cb/go.mod h1:t9Gj5Pe/FBDTUrkFmw2lK6PbzESB6o27eE97ukZj8Rs=
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28 h1:Xwe7VK9RT9QhfQ689qD2tFBK3OxeUqgeaiErOybZXGE=
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28/go.mod h1:X1+WYJT3/vJpfeU5gbQwNdAq5Me0TD0ysWpAcXs01Uw=
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230711084209-91fcd09b2017 h1:80dEVNOKqMipUQy6WQH//TbEaKjb7CkPvlrGCN8gKc4=
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230711084209-91fcd09b2017/go.mod h1:X1+WYJT3/vJpfeU5gbQwNdAq5Me0TD0ysWpAcXs01Uw=
github.com/bmatcuk/doublestar/v4 v4.2.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
Expand Down
38 changes: 2 additions & 36 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import (
"fmt"
"net/url"
"strings"
"time"

"github.com/bitrise-io/go-utils/fileutil"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-steplib/steps-authenticate-host-with-netrc/netrcutil"
)

Expand Down Expand Up @@ -44,38 +40,8 @@ func Setup(cfg Config) error {

netRC := netrcutil.New()

// based on https://github.com/bitrise-steplib/steps-authenticate-host-with-netrc/blob/master/main.go
netRC.AddItemModel(netrcutil.NetRCItemModel{Machine: host, Login: username, Password: password})

isExists, err := pathutil.IsPathExists(netRC.OutputPth)
if err != nil {
return fmt.Errorf("failed to check path (%s): %w", netRC.OutputPth, err)
}

if !isExists {
log.Debugf("No .netrc file found at (%s), creating new...", netRC.OutputPth)

if err := netRC.CreateFile(); err != nil {
return fmt.Errorf("failed to create .netrc file: %w", err)
}
} else {
log.Warnf(".netrc file already exists at (%s)", netRC.OutputPth)

backupPth := fmt.Sprintf("%s%s", strings.Replace(netRC.OutputPth, ".netrc", ".bk.netrc", -1), time.Now().Format("2006_01_02_15_04_05"))

if originalContent, err := fileutil.ReadBytesFromFile(netRC.OutputPth); err != nil {
return fmt.Errorf("failed to read file (%s): %w", netRC.OutputPth, err)
} else if err := fileutil.WriteBytesToFile(backupPth, originalContent); err != nil {
return fmt.Errorf("failed to write file (%s): %w", backupPth, err)
} else {
log.Warnf("Backup created at: %s", backupPth)
}

log.Debugf("Appending config to the existing .netrc file...")

if err := netRC.Append(); err != nil {
return fmt.Errorf("failed to append to .netrc file: %w", err)
}
if err := netRC.CreateOrUpdateFile(netrcutil.NetRCItemModel{Machine: host, Login: username, Password: password}); err != nil {
return fmt.Errorf("failed to update .netrc file: %w", err)
}

return nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ github.com/bitrise-io/go-utils/v2/retryhttp
# github.com/bitrise-io/goinp v0.0.0-20210504152833-8559b0680ab1
## explicit; go 1.16
github.com/bitrise-io/goinp/goinp
# github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28
# github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230711084209-91fcd09b2017
## explicit; go 1.17
github.com/bitrise-steplib/steps-authenticate-host-with-netrc/netrcutil
# github.com/davecgh/go-spew v1.1.1
Expand Down

0 comments on commit b37dd5b

Please sign in to comment.