Skip to content

Commit

Permalink
Merge pull request #97 from brunocous/feature/skip-ssl-git
Browse files Browse the repository at this point in the history
Added skip SSL verification for git driver
  • Loading branch information
vito authored Aug 13, 2019
2 parents 48ea0e4 + e302efd commit 2872779
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The `git` driver works by modifying a file in a repository with every bump. The

* `depth`: *Optional.* If a positive integer is given, shallow clone the repository using the --depth option.

* `skip_ssl_verification`: *Optional.* Skip SSL verification for git endpoint. Useful for git compatible providers using self-signed SSL certificates.

* `commit_message`: *Optional.* If specified overides the default commit message with the one provided. The user can use %version% and %file% to get them replaced automatically with the correct values.

### `s3` Driver
Expand Down
17 changes: 9 additions & 8 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ func FromSource(source models.Source) (Driver, error) {
return &GitDriver{
InitialVersion: initialVersion,

URI: source.URI,
Branch: source.Branch,
PrivateKey: source.PrivateKey,
Username: source.Username,
Password: source.Password,
File: source.File,
GitUser: source.GitUser,
CommitMessage: source.CommitMessage,
URI: source.URI,
Branch: source.Branch,
PrivateKey: source.PrivateKey,
Username: source.Username,
Password: source.Password,
File: source.File,
GitUser: source.GitUser,
CommitMessage: source.CommitMessage,
SkipSSLVerification: source.SkipSSLVerification,
}, nil

case models.DriverSwift:
Expand Down
31 changes: 31 additions & 0 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,34 @@ var _ = Describe("Driver", func() {
})
})
})

var _ = Describe("Driver", func() {
Context("Git", func() {
var src models.Source
BeforeEach(func() {
src = models.Source{
Driver: models.DriverGit,
}
})
It("returns a default git driver", func() {
aDriver, err := driver.FromSource(src)
Expect(err).To(BeNil())
Expect(aDriver).ToNot(BeNil())
gitDriver, ok := aDriver.(*driver.GitDriver)
Expect(ok).To(BeTrue())
Expect(gitDriver.SkipSSLVerification).To(Not(BeNil()))
Expect(gitDriver.SkipSSLVerification).To(BeFalse())
})
It("returns a git driver with a transport that ignores ssl verification", func() {
src.SkipSSLVerification = true
aDriver, err := driver.FromSource(src)
Expect(err).To(BeNil())
Expect(aDriver).ToNot(BeNil())
gitDriver, ok := aDriver.(*driver.GitDriver)
Expect(ok).To(BeTrue())
Expect(gitDriver.SkipSSLVerification).To(Not(BeNil()))
Expect(gitDriver.SkipSSLVerification).To(BeTrue())

})
})
})
47 changes: 38 additions & 9 deletions driver/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ func init() {
type GitDriver struct {
InitialVersion semver.Version

URI string
Branch string
PrivateKey string
Username string
Password string
File string
GitUser string
Depth string
CommitMessage string
URI string
Branch string
PrivateKey string
Username string
Password string
File string
GitUser string
Depth string
CommitMessage string
SkipSSLVerification bool
}

func (driver *GitDriver) Bump(bump version.Bump) (semver.Version, error) {
Expand All @@ -53,6 +54,11 @@ func (driver *GitDriver) Bump(bump version.Bump) (semver.Version, error) {

var newVersion semver.Version

err = driver.skipSSLVerificationIfSet()
if err != nil {
return semver.Version{}, err
}

for {
err = driver.setUpRepo()
if err != nil {
Expand Down Expand Up @@ -90,6 +96,11 @@ func (driver *GitDriver) Set(newVersion semver.Version) error {
return err
}

err = driver.skipSSLVerificationIfSet()
if err != nil {
return err
}

for {
err = driver.setUpRepo()
if err != nil {
Expand Down Expand Up @@ -120,6 +131,11 @@ func (driver *GitDriver) Check(cursor *semver.Version) ([]semver.Version, error)
return nil, err
}

err = driver.skipSSLVerificationIfSet()
if err != nil {
return nil, err
}

currentVersion, exists, err := driver.readVersion()
if err != nil {
return nil, err
Expand Down Expand Up @@ -170,6 +186,19 @@ func (driver *GitDriver) setUpRepo() error {
return nil
}

func (driver *GitDriver) skipSSLVerificationIfNeeded() error {
if driver.SkipSSLVerification {
gitSkipSSLVerification := exec.Command("git", "config", "http.sslVerify", "'false'")
gitSkipSSLVerification.Stdout = os.Stderr
gitSkipSSLVerification.Stderr = os.Stderr
if err := gitSkipSSLVerification.Run(); err != nil {
return err
}
}

return nil
}

func (driver *GitDriver) setUpAuth() error {
_, err := os.Stat(netRcPath)
if err != nil {
Expand Down

0 comments on commit 2872779

Please sign in to comment.