Skip to content

Commit

Permalink
make gihub access token a requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neagu committed Aug 19, 2024
1 parent 4d032a1 commit b24602b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ config.yaml
.env
__pycache__
*.egg-info/
build/
build/
*.ignore.*
3 changes: 2 additions & 1 deletion src/docker_publisher_osparc_services/http_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ async def github_did_last_repo_run_pass(
async with async_client() as client:
repo_path = repo_model.repo.split("github.com/")[1].replace(".git", "")
url = f"https://api.github.com/repos/{repo_path}/actions/runs"
headers = {"Authorization": f"Bearer {repo_model.github.gitlab_token}"}
params = {"per_page": "10"}
associated_run: Optional[Dict[str, Any]] = None

while url:
result = await client.get(url, params=params)
result = await client.get(url, params=params, headers=headers)
runs = result.json()

for run in runs["workflow_runs"]:
Expand Down
23 changes: 17 additions & 6 deletions src/docker_publisher_osparc_services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, List, Optional

from envyaml import EnvYAML
from pydantic import BaseModel, Field, SecretStr, root_validator
from pydantic import BaseModel, Field, SecretStr, root_validator, validator


class HostType(str, Enum):
Expand Down Expand Up @@ -71,13 +71,13 @@ class GitLabModel(BaseModel):
deploy_token_password: SecretStr


class GitHubModel(BaseModel):
gitlab_token: str


class RepoModel(BaseModel):
address: str = Field(..., description="clone address https")
gitlab: Optional[GitLabModel] = Field(
None, description="GitLab credentials to clone and access the v4 API"
)
branch: str
host_type: HostType
registry: RegistryTargetModel
clone_path: Optional[Path] = Field(
None, description="Used internally to specify directory where to clone"
Expand All @@ -95,13 +95,24 @@ class RepoModel(BaseModel):
description="a list of commands to execute before running the docker build command",
)

host_type: HostType
gitlab: Optional[GitLabModel] = Field(
None, description="GitLab credentials to clone and access the v4 API"
)
github: Optional[GitHubModel] = None

@classmethod
@root_validator()
def require_access_token_for_gitlab(cls, values):
def require_access_token(cls, values):
if values["host_type"] == HostType.GITLAB and values["gitlab"] is None:
raise ValueError(
f"Provide a valid 'gitlab' field for {HostType.GITLAB} repo"
)
if values["host_type"] == HostType.GITHUB and values["github"] is None:
raise ValueError(
f"Provide a valid 'gitlab' field for {HostType.GITHUB} repo"
)

return values

def _format_repo(
Expand Down

0 comments on commit b24602b

Please sign in to comment.