in servicecatalog_factory/template_builder/builders.py [0:0]
def build_source_stage(self, tpl, stages, source):
if source.get("Provider", "").lower() == "custom":
if source.get("Configuration").get("GitWebHookIpAddress") is not None:
webhook = codepipeline.Webhook(
"Webhook",
Authentication="IP",
TargetAction="Source",
AuthenticationConfiguration=codepipeline.WebhookAuthConfiguration(
AllowedIPRange=source.get("Configuration").get(
"GitWebHookIpAddress"
)
),
Filters=[
codepipeline.WebhookFilterRule(
JsonPath="$.changes[0].ref.id",
MatchEquals="refs/heads/{Branch}",
)
],
TargetPipelineVersion=1,
TargetPipeline=t.Sub("${AWS::StackName}-pipeline"),
)
tpl.add_resource(webhook)
values_for_sub = {
"GitUrl": source.get("Configuration").get("GitUrl"),
"WebhookUrl": t.GetAtt(webhook, "Url"),
}
else:
values_for_sub = {
"GitUrl": source.get("Configuration").get("GitUrl"),
"WebhookUrl": "GitWebHookIpAddress was not defined in manifests Configuration",
}
output_to_add = t.Output("WebhookUrl")
output_to_add.Value = t.Sub("${GitUrl}||${WebhookUrl}", **values_for_sub)
output_to_add.Export = t.Export(t.Sub("${AWS::StackName}-pipeline"))
tpl.add_output(output_to_add)
stages.append(
codepipeline.Stages(
Name="Source",
Actions=[
dict(
codecommit=codepipeline.Actions(
RunOrder=1,
RoleArn=t.Sub(
"arn:${AWS::Partition}:iam::${AWS::AccountId}:role/servicecatalog-product-factory/SourceRole"
),
ActionTypeId=codepipeline.ActionTypeId(
Category="Source",
Owner="AWS",
Version="1",
Provider="CodeCommit",
),
OutputArtifacts=[
codepipeline.OutputArtifacts(
Name=base_template.SOURCE_OUTPUT_ARTIFACT
)
],
Configuration={
"RepositoryName": source.get("Configuration").get(
"RepositoryName"
),
"BranchName": source.get("Configuration").get(
"BranchName"
),
"PollForSourceChanges": source.get("Configuration").get(
"PollForSourceChanges", True
),
},
Name="Source",
),
github=codepipeline.Actions(
RunOrder=1,
ActionTypeId=codepipeline.ActionTypeId(
Category="Source",
Owner="ThirdParty",
Version="1",
Provider="GitHub",
),
OutputArtifacts=[
codepipeline.OutputArtifacts(
Name=base_template.SOURCE_OUTPUT_ARTIFACT
)
],
Configuration={
"Owner": source.get("Configuration").get("Owner"),
"Repo": source.get("Configuration").get("Repo"),
"Branch": source.get("Configuration").get("Branch"),
"OAuthToken": t.Join(
"",
[
"{{resolve:secretsmanager:",
source.get("Configuration").get(
"SecretsManagerSecret"
),
":SecretString:OAuthToken}}",
],
),
"PollForSourceChanges": source.get("Configuration").get(
"PollForSourceChanges"
),
},
Name="Source",
),
codestarsourceconnection=codepipeline.Actions(
RunOrder=1,
RoleArn=t.Sub(
"arn:${AWS::Partition}:iam::${AWS::AccountId}:role/servicecatalog-product-factory/SourceRole"
),
ActionTypeId=codepipeline.ActionTypeId(
Category="Source",
Owner="AWS",
Version="1",
Provider="CodeStarSourceConnection",
),
OutputArtifacts=[
codepipeline.OutputArtifacts(
Name=base_template.SOURCE_OUTPUT_ARTIFACT
)
],
Configuration={
"ConnectionArn": source.get("Configuration").get(
"ConnectionArn"
),
"FullRepositoryId": source.get("Configuration").get(
"FullRepositoryId"
),
"BranchName": source.get("Configuration").get(
"BranchName"
),
"OutputArtifactFormat": source.get("Configuration").get(
"OutputArtifactFormat"
),
},
Name="Source",
),
s3=codepipeline.Actions(
RunOrder=1,
ActionTypeId=codepipeline.ActionTypeId(
Category="Source",
Owner="AWS",
Version="1",
Provider="S3",
),
OutputArtifacts=[
codepipeline.OutputArtifacts(
Name=base_template.SOURCE_OUTPUT_ARTIFACT
)
],
Configuration={
"S3Bucket": t.Sub(
source.get("Configuration").get(
"S3Bucket",
source.get("Configuration").get("BucketName"),
)
),
"S3ObjectKey": t.Sub(
source.get("Configuration").get("S3ObjectKey")
),
"PollForSourceChanges": source.get("Configuration").get(
"PollForSourceChanges", True
),
},
Name="Source",
),
custom=codepipeline.Actions(
RunOrder=1,
ActionTypeId=codepipeline.ActionTypeId(
Category="Source",
Owner="Custom",
Version=source.get("Configuration", {}).get(
"CustomActionTypeVersion", "CustomVersion1"
),
Provider=source.get("Configuration", {}).get(
"CustomActionTypeProvider", "CustomProvider1"
),
),
OutputArtifacts=[
codepipeline.OutputArtifacts(
Name=base_template.SOURCE_OUTPUT_ARTIFACT
)
],
Configuration={
"GitUrl": source.get("Configuration").get("GitUrl"),
"Branch": source.get("Configuration").get("Branch"),
"PipelineName": t.Sub("${AWS::StackName}-pipeline"),
},
Name="Source",
),
).get(source.get("Provider", "").lower())
],
),
)