Esempio n. 1
0
    def fetch(
        self,
        fields: Optional[List[str]] = None,
        update: bool = True,
        fetch_aa_data: bool = False,
    ) -> None:
        if self._dirty:
            raise IntegrityError(
                "role object has unsaved modifications, fetching may overwrite changes"
            )

        if self.role_id:
            stored_role_data = get_role_by_id(self.role_id, fields=fields)
        elif self.arn:
            stored_role_data = get_role_by_arn(self.arn, fields=fields)
        else:
            # TODO: we can pull role_name and account from an ARN, support that too
            raise ModelError(
                "missing role_id or role_name and account on Role instance")

        if update:
            self.update(stored_role_data, store=False, dirty=False)
            self._updated_fields - set(stored_role_data.keys())
            if fetch_aa_data:
                self.fetch_aa_data()
Esempio n. 2
0
    def fetch(self,
              fields: Optional[List[str]] = None,
              update: bool = True) -> None:
        if self._dirty:
            raise IntegrityError(
                "role object has unsaved modifications, fetching may overwrite changes"
            )

        if self.role_id:
            stored_role_data = get_role_by_id(self.role_id, fields=fields)
        elif self.role_name and self.account:
            stored_role_data = get_role_by_name(self.account,
                                                self.role_name,
                                                fields=fields)
        else:
            raise ModelError(
                "missing role_id or role_name and account on Role instance")

        if update:
            self.update(stored_role_data, store=False)
            self._updated_fields - set(stored_role_data.keys())