Add codepipeline.get_pipeline
This commit is contained in:
parent
076c8ace5f
commit
c84e465e4c
5 changed files with 187 additions and 7 deletions
|
|
@ -1,21 +1,41 @@
|
|||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from boto3 import Session
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
|
||||
from moto.iam.exceptions import IAMNotFoundException
|
||||
|
||||
from moto.iam import iam_backends
|
||||
|
||||
from moto.codepipeline.exceptions import InvalidStructureException
|
||||
from moto.codepipeline.exceptions import (
|
||||
InvalidStructureException,
|
||||
PipelineNotFoundException,
|
||||
)
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
|
||||
DEFAULT_ACCOUNT_ID = "123456789012"
|
||||
|
||||
|
||||
class CodePipeline(BaseModel):
|
||||
def __init__(self, pipeline):
|
||||
def __init__(self, region, pipeline):
|
||||
self.pipeline = self._add_default_values(pipeline)
|
||||
self.tags = {}
|
||||
|
||||
self._arn = "arn:aws:codepipeline:{0}:{1}:{2}".format(
|
||||
region, DEFAULT_ACCOUNT_ID, pipeline["name"]
|
||||
)
|
||||
self._created = datetime.utcnow()
|
||||
self._updated = datetime.utcnow()
|
||||
|
||||
@property
|
||||
def metadata(self):
|
||||
return {
|
||||
"pipelineArn": self._arn,
|
||||
"created": iso_8601_datetime_with_milliseconds(self._created),
|
||||
"updated": iso_8601_datetime_with_milliseconds(self._updated),
|
||||
}
|
||||
|
||||
def _add_default_values(self, pipeline):
|
||||
for stage in pipeline["stages"]:
|
||||
for action in stage["actions"]:
|
||||
|
|
@ -28,6 +48,8 @@ class CodePipeline(BaseModel):
|
|||
if "inputArtifacts" not in action:
|
||||
action["inputArtifacts"] = []
|
||||
|
||||
return pipeline
|
||||
|
||||
|
||||
class CodePipelineBackend(BaseBackend):
|
||||
def __init__(self):
|
||||
|
|
@ -37,7 +59,7 @@ class CodePipelineBackend(BaseBackend):
|
|||
def iam_backend(self):
|
||||
return iam_backends["global"]
|
||||
|
||||
def create_pipeline(self, pipeline, tags):
|
||||
def create_pipeline(self, region, pipeline, tags):
|
||||
if pipeline["name"] in self.pipelines:
|
||||
raise InvalidStructureException(
|
||||
"A pipeline with the name '{0}' already exists in account '{1}'".format(
|
||||
|
|
@ -64,7 +86,7 @@ class CodePipelineBackend(BaseBackend):
|
|||
"Pipeline has only 1 stage(s). There should be a minimum of 2 stages in a pipeline"
|
||||
)
|
||||
|
||||
self.pipelines[pipeline["name"]] = CodePipeline(pipeline)
|
||||
self.pipelines[pipeline["name"]] = CodePipeline(region, pipeline)
|
||||
|
||||
if tags:
|
||||
new_tags = {tag["key"]: tag["value"] for tag in tags}
|
||||
|
|
@ -72,6 +94,18 @@ class CodePipelineBackend(BaseBackend):
|
|||
|
||||
return pipeline, tags
|
||||
|
||||
def get_pipeline(self, name):
|
||||
codepipeline = self.pipelines.get(name)
|
||||
|
||||
if not codepipeline:
|
||||
raise PipelineNotFoundException(
|
||||
"Account '{0}' does not have a pipeline with name '{1}'".format(
|
||||
DEFAULT_ACCOUNT_ID, name
|
||||
)
|
||||
)
|
||||
|
||||
return codepipeline.pipeline, codepipeline.metadata
|
||||
|
||||
|
||||
codepipeline_backends = {}
|
||||
for region in Session().get_available_regions("codepipeline"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue