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

feat: ensure Bitbucket repo URLs use HTTPS scheme #406

Merged
merged 2 commits into from
Mar 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/phylum/ci/ci_bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,16 @@ def repo_url(self) -> Optional[str]:
# This is the "URL for the origin", which uses `HTTP:` instead of
# `HTTPS:`, even though the value redirects to the `HTTPS:` site.
# Ref: https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
return os.getenv("BITBUCKET_GIT_HTTP_ORIGIN")
origin_url = os.getenv("BITBUCKET_GIT_HTTP_ORIGIN")
if origin_url is None:
LOG.warning("Repository URL not found at `BITBUCKET_GIT_HTTP_ORIGIN`")
return None

# Ensure the repository URL uses the HTTPS scheme
parsed_url = urllib.parse.urlparse(origin_url)
if parsed_url.scheme == "http":
parsed_url = parsed_url._replace(scheme="https")
return parsed_url.geturl()

def post_output(self) -> None:
"""Post the output of the analysis.
Expand Down
11 changes: 6 additions & 5 deletions src/phylum/init/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def get_archive_url(tag_name: str, archive_name: str) -> str:
return archive_url


def is_token_set(phylum_settings_path, token=None):
def is_token_set(phylum_settings_path: Path, token: Optional[str] = None) -> bool:
"""Check if any token is already set in the given CLI configuration file.

Optionally, check if a specific given `token` is set.
Expand All @@ -260,13 +260,14 @@ def is_token_set(phylum_settings_path, token=None):
return False

yaml = YAML()
settings_dict = yaml.load(settings_data)
configured_token = settings_dict.get("auth_info", {}).get("offline_access")
settings_dict: dict = yaml.load(settings_data)
auth_info_dict: dict = settings_dict.get("auth_info", {})
configured_token = auth_info_dict.get("offline_access")

if configured_token is None:
return False
if token is not None and token != configured_token:
return False
if token is not None:
return token == configured_token

return True

Expand Down
Loading