Skip to content

Commit

Permalink
make codestar connection usable if uuid supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmcginty committed Jul 4, 2024
1 parent 957c407 commit 389d80c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
48 changes: 26 additions & 22 deletions src/aibs_informatics_cdk_lib/cicd/pipeline/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,32 @@ def get_pipeline_source(
# So we need to cache the results for a given result if config has same repo name.

if source_config.repository not in self.source_cache:
# TEMPORARY -- we need to use this going forward
# source = pipelines.CodePipelineSource.connection(
# repo_string=github_config.repository,
# branch=github_config.branch,
# connection_arn=build_arn(
# service="codestar-connections",
# resource_type="connection",
# resource_delim="/",
# resource_id=github_config.codestar_connection,
# ),
# code_build_clone_output=True,
# trigger_on_push=True,
# )

source = pipelines.CodePipelineSource.git_hub(
repo_string=source_config.repository,
branch=source_config.branch,
authentication=cdk.SecretValue.secrets_manager(
secret_id=source_config.oauth_secret_name
),
trigger=aws_codepipeline_actions.GitHubTrigger.WEBHOOK,
)
if source_config.codestar_connection:
source = pipelines.CodePipelineSource.connection(
repo_string=source_config.repository,
branch=source_config.branch,
connection_arn=build_arn(
service="codestar-connections",
resource_type="connection",
resource_delim="/",
resource_id=source_config.codestar_connection,
),
code_build_clone_output=True,
trigger_on_push=True,
)
elif source_config.oauth_secret_name:
source = pipelines.CodePipelineSource.git_hub(
repo_string=source_config.repository,
branch=source_config.branch,
authentication=cdk.SecretValue.secrets_manager(
secret_id=source_config.oauth_secret_name
),
trigger=aws_codepipeline_actions.GitHubTrigger.WEBHOOK,
)
else:
raise ValueError(
"Invalid source config. Must have codestar_connection or oauth_secret_name"
)
self.source_cache[source_config.repository] = source
return self.source_cache[source_config.repository]

Expand Down
18 changes: 14 additions & 4 deletions src/aibs_informatics_cdk_lib/project/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"ConfigProvider",
]

import logging
from pathlib import Path
from typing import Annotated, Dict, Generic, MutableMapping, Optional, Type, TypeVar, Union
from typing import Annotated, Dict, Generic, List, MutableMapping, Optional, Type, TypeVar, Union

import yaml
from aibs_informatics_core.collections import DeepChainMap
Expand All @@ -22,7 +23,7 @@
from aibs_informatics_core.utils.file_operations import find_paths
from aibs_informatics_core.utils.os_operations import expandvars
from aibs_informatics_core.utils.tools.dicttools import remove_null_values
from pydantic import BaseModel, PlainSerializer, PlainValidator
from pydantic import BaseModel, PlainSerializer, PlainValidator, model_validator

UniqueIDType = Annotated[
UniqueID, PlainValidator(lambda x: UniqueID(x)), PlainSerializer(lambda x: str(x))
Expand Down Expand Up @@ -84,8 +85,17 @@ class CodePipelineBuildConfig(BaseModel):
class CodePipelineSourceConfig(BaseModel):
repository: str
branch: Annotated[str, PlainValidator(EnvVarStr.validate)]
codestar_connection: UniqueIDType
oauth_secret_name: str
codestar_connection: Optional[UniqueIDType]
oauth_secret_name: Optional[str]

@model_validator(mode="after")
@classmethod
def check_source_config(cls, v):
if not v.codestar_connection and not v.oauth_secret_name:
raise ValueError("Either codestar_connection or oauth_secret_name must be set")
if v.codestar_connection and v.oauth_secret_name:
logging.warning("Only one of codestar_connection or oauth_secret_name can be set")
return v


class CodePipelineNotificationsConfig(BaseModel):
Expand Down

0 comments on commit 389d80c

Please sign in to comment.