コード例 #1
0
    def create(self, props):
        """ This method basically first check whether or not a group exist for a given organization if so it outputs group_id
                and a message that group already exist.
                If the group does not exist we just simply create one and outputs group_id and a message that new group
                created """

        # Here first we check there are there any errors that have came from check method if so we print out that
        # issues
        if 'errors' in props:
            for error in props['errors']:
                if 'group_id' in error:
                    return CreateResult(error['group_id'], {
                        'group_id': error['group_id'],
                        'message': error['message']
                    })

        create_group_response = client.create_group(
            OrganizationId=props['organization_id'], Name=props['group_name'])

        group_id = create_group_response['GroupId']

        register_workmail_response = client.register_to_work_mail(
            OrganizationId=props['organization_id'],
            EntityId=group_id,
            Email=props['group_email'])

        return CreateResult(
            group_id, {
                'group_id': group_id,
                'message': 'New Group Created',
                'organization_id': props['organization_id']
            })
コード例 #2
0
    def create(self, props):
        service = get_service("analytics", "v3", SCOPES, props["key_location"])

        properties = (
            service.management()
            .webproperties()
            .list(accountId=props["account_id"], fields="items")
            .execute()
        )

        if properties.get("items"):
            # check if property already exists then simply return tracking code from property
            for p in properties.get("items"):
                if props["site_name"] == p.get("name"):
                    return CreateResult(
                        id_=props["account_id"], outs={"tracking_id": p["id"], **props},
                    )
        web_property = (
            service.management()
            .webproperties()
            .insert(
                accountId=props["account_id"],
                fields="id",
                body={"websiteUrl": props["site_url"], "name": props["site_name"]},
            )
            .execute()
        )

        return CreateResult(
            id_=props["account_id"], outs={"tracking_id": web_property["id"], **props},
        )
コード例 #3
0
    def create(self, props):
        service = get_service("tagmanager", "v2", SCOPES, props['key_location'])
        account_path = f"accounts/{props['account_id']}"
        container = (
            service.accounts()
            .containers()
            .create(
                parent=account_path,
                body={"name": props["container_name"], "usage_context": ["web"]},
            )
            .execute()
        )

        container_public_id = container["publicId"]

        with open("./dynamic_providers/templates/gtm_tag.html") as f:
            template = Template(f.read())
            gtm_tag = template.render(container_public_id=container_public_id)

        with open("./dynamic_providers/templates/gtm_tag_noscript.html") as f:
            template = Template(f.read())
            gtm_tag_noscript = template.render(container_public_id=container_public_id)

        return CreateResult(
            id_=props["account_id"],
            outs={
                "container_id": container["containerId"],
                "gtm_tag_noscript": gtm_tag_noscript,
                "gtm_tag": gtm_tag,
                **props,
                **container,
            },
        )
コード例 #4
0
    def create(self, inputs):

        # Validate inputs
        self._check_required_attributes(inputs)
        validated_name = self._get_validated_autogenerated_name(inputs)
        attributes_with_values = list(
            filter(lambda a: inputs.get(a.name) is not None, self.attributes))

        # Perform SQL command to create object
        sql_statements = self._generate_sql_create_statement(
            attributes_with_values, validated_name, inputs)
        sql_bindings = self._generate_sql_create_bindings(
            attributes_with_values, inputs)
        self._execute_sql(sql_statements, sql_bindings)

        # Generate provisional outputs from attributes.  Provisional because the call to generate_outputs below allows
        # subclasses to modify them if necessary.
        provisional_outputs = {
            "name": validated_name,
            **self._generate_outputs_from_attributes(inputs)
        }

        return CreateResult(id_=validated_name,
                            outs=self._generate_outputs(
                                validated_name, inputs, provisional_outputs))
コード例 #5
0
    def create(self, inputs):

        info(f"Creating object {self.resource_type}...")

        # Validate inputs
        if inputs.get("name") is None and inputs.get("resource_name") is None:
            raise Exception(
                "At least one of 'name' or 'resource_name' must be provided")

        validated_name = self._get_autogenerated_name(inputs)

        # Perform SQL command to create object
        environment = self._create_jinja_environment()
        sql_statement = self.generate_sql_create_statement(
            validated_name, inputs, environment)
        self._execute_sql(sql_statement)

        # Generate provisional outputs from inputs.  Provisional because the call to generate_outputs below allows
        # subclasses to modify them if necessary.
        provisional_outputs = {
            "name": validated_name,
            **self._generate_outputs_from_inputs(inputs)
        }

        info(
            f"Creation of {self.resource_type} with name {validated_name} successful"
        )

        return CreateResult(id_=validated_name,
                            outs=self._generate_outputs(
                                validated_name, inputs, provisional_outputs))
コード例 #6
0
    def create(self, props):
        service = get_service("tagmanager", "v2", SCOPES,
                              props['key_location'])
        tag_body = self._get_tag_body(props)
        tag = (service.accounts().containers().workspaces().tags().create(
            parent=props["workspace_path"], body=tag_body).execute())

        return CreateResult(id_=props["workspace_path"], outs={**props, **tag})
コード例 #7
0
    def create(self, props):

        # Here first we check there are there any errors that have came from check method if so we print out that
        # issues.
        if 'errors' in props:
            for error in props['errors']:
                if 'group_id' in error and 'alias' in error:
                    return CreateResult(error['alias'], {'alias_email': error['alias'], 'group_id': error['group_id'],
                                                         'message': error['message']})

        client.create_alias(
            OrganizationId=props['organization_id'],
            EntityId=props['group_id'],
            Alias=props['alias_email']
        )

        return CreateResult(props['alias_email'],
                            {'alias_email': props['alias_email'], 'group_id': props['group_id'],
                             'message': 'New Alias Created for Group', 'organization_id': props['organization_id']})
コード例 #8
0
    def create(self, props):
        service = get_service("tagmanager", "v2", SCOPES, props['key_location'])
        workspace = (
            service.accounts()
            .containers()
            .workspaces()
            .create(
                parent=props["container_path"], body={"name": props["workspace_name"]}
            )
            .execute()
        )

        return CreateResult(id_=props["container_path"], outs={**props, **workspace})
コード例 #9
0
    def create(self, props):
        service = get_service("tagmanager", "v2", SCOPES,
                              props['key_location'])
        variable_body = self._get_variable_body(props)

        variable = (
            service.accounts().containers().workspaces().variables().create(
                parent=props["workspace_path"], body=variable_body).execute())

        return CreateResult(id_=props["workspace_path"],
                            outs={
                                **props,
                                **variable, "variable_id":
                                variable["variableId"]
                            })
コード例 #10
0
    def create(self, props: Any) -> CreateResult:

        pulumi.info(
            (
                f"Creating {{cookiecutter.initial_resource_slug | pascalcase}} resource "
                f" (param1={props.get('param1')},param2={props.get('param2')})..."
            )
        )
        pulumi.info(
            (
                f"Using provider parameters ({self.provider_params.provider_param1},"
                f"{self.provider_params.provider_param2})"
            )
        )

        return CreateResult(
            id_="resource_id_12345", outs={**props, "output_param": "my_output_value"}
        )
コード例 #11
0
    def create(self, _news: Any) -> CreateResult:
        """
        Creates new UserLoginProfile resource

        :param _news:
        :return:
        """

        iam = client("iam", _news)
        username = _news['username']
        password = _news['password']
        login_profile = iam.LoginProfile(user_name=username)
        login_profile.create(Password=password, PasswordResetRequired=True)

        return CreateResult(username,
                            outs={
                                **_news, 'password_reset_required': True
                            })
コード例 #12
0
    def create(self, props):
        service = get_service("tagmanager", "v2", SCOPES,
                              props['key_location'])
        tag_body = {
            "name":
            props["tag_name"],
            "type":
            "ua",
            "parameter": [{
                "key": "trackingId",
                "type": "template",
                "value": str(props["tracking_id"]),
            }],
        }

        tag = (service.accounts().containers().workspaces().tags().create(
            parent=props["workspace_path"], body=tag_body).execute())

        return CreateResult(id_=props["workspace_path"], outs={**props, **tag})
コード例 #13
0
    def create(self, props):
        service = get_service("tagmanager", "v2", SCOPES,
                              props['key_location'])

        create_version = (
            service.accounts().containers().workspaces().create_version(
                path=props["workspace_path"]).execute())

        publish_result = (service.accounts().containers().versions().publish(
            path=create_version["containerVersion"]["path"]).execute())

        return CreateResult(
            id_=props["workspace_path"],
            outs={
                **props,
                **create_version, "container_version_id":
                create_version["containerVersion"]["containerVersionId"],
                "container_version_path":
                create_version["containerVersion"]["path"]
            })
コード例 #14
0
 def create(self, inputs):
     time.sleep(inputs["delay_time"])
     return CreateResult(self.resource_name, inputs)
コード例 #15
0
 def create(self, props: Any) -> CreateResult:
     print("CREATE has been called")
     time.sleep(5)
     self._write_content(props["path"], props["content"])
     return CreateResult(id_=uuid4().hex, outs=props)
コード例 #16
0
ファイル: __main__.py プロジェクト: ckaur2409/Pulumi
 def create(self, props):
     val = binascii.b2a_hex(os.urandom(15)).decode("ascii")
     return CreateResult(val, {"val": val})
コード例 #17
0
 def create(self, inputs):
     global current_id
     current_id += 1
     return CreateResult(str(current_id),
                         {"additional": inputs["additional"]})
コード例 #18
0
 def create(self, inputs):
     return CreateResult("0", {"output": "a", "output2": "b"})
コード例 #19
0
ファイル: __main__.py プロジェクト: zebulonj/pulumi
 def create(self, props):
     return CreateResult("0", props)
コード例 #20
0
 def create(self, props):
     return CreateResult("resource-id", {})
コード例 #21
0
ファイル: __main__.py プロジェクト: zebulonj/pulumi
 def create(self, props):
     return CreateResult("1", {"prefix": props["prefix"]})
コード例 #22
0
 def create(self, props: Any) -> CreateResult:
     print(props["comment"], "\n>>> ", f"{props['input']}", "\n---")
     time.sleep(1)
     return CreateResult(id_=uuid4().hex, outs=props)
コード例 #23
0
ファイル: __main__.py プロジェクト: zebulonj/pulumi
 def create(self, inputs):
     global current_id
     current_id += 1
     return CreateResult(str(current_id), inputs)
コード例 #24
0
 def create(self, props: Any) -> CreateResult:
     time.sleep(1)
     return CreateResult(id_=uuid4().hex,
                         outs=props | {"property": uuid4().hex[:4]})