Skip to content

Commit

Permalink
Merge pull request #132 from bluesliverx/main
Browse files Browse the repository at this point in the history
XENG-7766 Fix github file redirects with new global config
  • Loading branch information
bluesliverx authored Mar 27, 2024
2 parents c83b1dc + dafad57 commit 467d492
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion buildrunner/config/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import urllib.parse
from typing import Optional

from ..models import GlobalConfig
from . import github
from . import http
from . import file


def fetch_file(url: str, config: Optional[dict]) -> str:
def fetch_file(url: str, config: Optional[GlobalConfig]) -> str:
"""
Fetch a file from a provider.
"""
Expand Down
4 changes: 3 additions & 1 deletion buildrunner/config/fetch/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import codecs
from typing import Optional

from ..models import GlobalConfig

def fetch_file(parsed_url, _: Optional[dict]):

def fetch_file(parsed_url, _: Optional[GlobalConfig]):
"""
Pull files from the local file system.
"""
Expand Down
18 changes: 9 additions & 9 deletions buildrunner/config/fetch/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
with the terms of the Adobe license agreement accompanying it.
"""

import os
import base64
import requests

from ..models import GlobalConfig, GithubModel
from ...errors import (
BuildRunnerConfigurationError,
BuildRunnerProtocolError,
)


def v3_fetch_file(parsed_url, config):
def v3_fetch_file(parsed_url, gh_config: GithubModel):
"""
Fetch files using Github v3 protocol.
"""

endpoint = config.get("endpoint")
version = config.get("version")
endpoint = gh_config.endpoint
version = gh_config.version

username = config.get("username", os.getenv("USER", os.getenv("LOGNAME")))
username = gh_config.username
if not username:
raise RuntimeError(f"Failed to look up username to access github {endpoint}")

auth = (username, config.get("app_token", ""))
auth = (username, gh_config.app_token)
url = "/".join(
(
endpoint,
Expand Down Expand Up @@ -74,15 +74,15 @@ def v3_fetch_file(parsed_url, config):
return contents


def fetch_file(parsed_url, config: dict):
def fetch_file(parsed_url, config: GlobalConfig):
"""
Fetch a file from Github.
"""

if parsed_url.scheme != "github":
raise ValueError(f'URL scheme must be "github" but is "{parsed_url.github}"')

ghcfg = config.get("github")
ghcfg = config.github
if not ghcfg:
raise BuildRunnerConfigurationError(
"Missing configuration for github in buildrunner.yaml"
Expand All @@ -96,7 +96,7 @@ def fetch_file(parsed_url, config: dict):
f" - known github configurations: {gh_cfgs}"
)

ver = nlcfg.get("version")
ver = nlcfg.version
# NOTE: potentially the v3_fetch_file() works for other github API versions.
if ver == "v3":
contents = v3_fetch_file(parsed_url, nlcfg)
Expand Down
5 changes: 4 additions & 1 deletion buildrunner/config/fetch/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
with the terms of the Adobe license agreement accompanying it.
"""
from typing import Optional

from ..models import GlobalConfig

def fetch_file(parsed_url, config: dict):

def fetch_file(parsed_url, config: Optional[GlobalConfig]):
"""
Fetch files using HTTP.
"""
Expand Down
4 changes: 2 additions & 2 deletions buildrunner/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
class GithubModel(BaseModel, extra="forbid"):
endpoint: str
version: str
username: str
app_token: str
username: str = os.getenv("USER", os.getenv("LOGNAME"))
app_token: str = ""


class SSHKey(BaseModel, extra="forbid"):
Expand Down

0 comments on commit 467d492

Please sign in to comment.