Skip to content

Conversation

@Nik08
Copy link
Contributor

@Nik08 Nik08 commented Aug 30, 2021

Signed-off-by: Nikita Mathur nikita.mathur@chef.io

Description

Fix url fetcher when default git profile branch is not master

Needs strict code review on this

Related Issue

Fixes #5635

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@Nik08 Nik08 self-assigned this Aug 30, 2021
@Nik08 Nik08 requested a review from a team as a code owner August 30, 2021 13:46
@netlify
Copy link

netlify bot commented Aug 30, 2021

✔️ Deploy Preview for chef-inspec ready!

🔨 Explore the source changes: ca19914

🔍 Inspect the deploy log: https://app.netlify.com/sites/chef-inspec/deploys/612ddd73506d610008b555dc

😎 Browse the preview: https://deploy-preview-5638--chef-inspec.netlify.app

"https://github.com/#{m[:user]}/#{m[:repo]}/archive/#{m[:commit]}.tar.gz"
elsif m = BITBUCKET_URL_REGEX.match(target) # rubocop:disable Lint/AssignmentInCondition
"https://bitbucket.org/#{m[:user]}/#{m[:repo]}/get/master.tar.gz"
default_branch = default_ref(m)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_ref assumes a github address, but here it is being used on a bitbucket repo - this will fail for bitbucket repos.


class << self
def default_ref(match_data)
remote_url = "https://github.com/#{match_data[:user]}/#{match_data[:repo]}.git"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where default ref assumes a github address.

Copy link
Collaborator

@aaronlippold aaronlippold Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we just make the whole URI part of the variable.. what if it is a git on gitlab ... like gitlab.mitre.org?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have the whole uri of the repo when we put it in the cli command right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we put the whole uri in the inpsec.yml - basically every time we reference a git repo we do so via a full uri right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code was applying transformations to fetch tarballs, if possible, by recognizing github and bitbucket URLs. We can't do that in a generic basis, as we don't know what transformation may need to be applied. There may be a transformation that works for gitlab, but the user can always just supply the correct tarball URL in the first place.

As this is a hotfix PR, to fix an urgent problem, we will not be expanding any functionality on this PR. If you'd like to explore expanding the transformation logic, feel free to do so, but we need to ship this fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I will open an issue, as I know we have customers using InSpec with other git platforms - GitLab mostly - which we should allow for. In theory, I would have guessed that given the user has to give the full git repo URI that we could use that.

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
29.0% 29.0% Duplication

@aaronlippold
Copy link
Collaborator

So this will work reguardless of the default branch name?

Copy link
Contributor

@clintoncwolfe clintoncwolfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Nik08, looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git fetchers need to assume default branch is now named "main"

4 participants