Example #1
0
 def _init_client(
     self,
     service_name: str,
     aws_key_id: str = None,
     aws_key: str = None,
     region: str = None,
     use_robocloud_vault: bool = False,
 ):
     if region is None:
         region = self.region
     if use_robocloud_vault:
         vault = Secrets()
         vault_items = vault.get_secret(self.robocloud_vault_name)
         vault_items = {k.upper(): v for (k, v) in vault_items.items()}
         aws_key_id = vault_items["AWS_KEY_ID"]
         aws_key = vault_items["AWS_KEY"]
     else:
         if aws_key_id is None or aws_key_id.strip() == "":
             aws_key_id = required_env("AWS_KEY_ID")
         if aws_key is None or aws_key.strip() == "":
             aws_key = required_env("AWS_KEY")
     if (aws_key_id is None or aws_key_id.strip() == "" or aws_key is None
             or aws_key.strip() == ""):
         raise KeyError("AWS key ID and secret access key are required "
                        " to use AWS cloud service: %s" % service_name)
     client = boto3.client(
         service_name,
         region_name=region,
         aws_access_key_id=aws_key_id,
         aws_secret_access_key=aws_key,
     )
     self._set_service(service_name, client)
Example #2
0
 def _init_client(
     self,
     service_name: str,
     aws_key_id: str = None,
     aws_key: str = None,
     region: str = None,
     use_robocloud_vault: bool = False,
 ):
     if use_robocloud_vault:
         aws_key_id, aws_key, region = self._get_secrets_from_cloud()
     else:
         if aws_key_id is None or aws_key_id.strip() == "":
             aws_key_id = required_env("AWS_KEY_ID")
         if aws_key is None or aws_key.strip() == "":
             aws_key = required_env("AWS_KEY")
         if region is None or region.strip() == "":
             region = os.getenv("AWS_REGION", self.region)
     if (aws_key_id is None or aws_key_id.strip() == "" or aws_key is None
             or aws_key.strip() == ""):
         raise KeyError("AWS key ID and secret access key are required "
                        " to use AWS cloud service: %s" % service_name)
     self.logger.info("Using region: %s", region)
     client = boto3.client(
         service_name,
         region_name=region,
         aws_access_key_id=aws_key_id,
         aws_secret_access_key=aws_key,
     )
     self._set_service(service_name, client)
Example #3
0
    def login(
        self,
        account: str = None,
        email: str = None,
        password: str = None,
        role: str = None,
        appid: str = None,
    ) -> None:
        """Login to Netsuite with credentials from environment variables

        Parameters are not logged into Robot Framework log.

        :param account: parameter or environment variable `NS_ACCOUNT`
        :param email: parameter or environment variable `NS_EMAIL`
        :param password: parameter or environment variable `NS_PASSWORD`
        :param role: parameter or environment variable `NS_ROLE`
        :param appid: parameter or environment variable `NS_APPID`
        """
        if account is None:
            account = required_env("NS_ACCOUNT", self.account)
        if account is None:
            raise NetsuiteAuthenticationError("Authentication is not completed")
        NS_EMAIL = required_env("NS_EMAIL", email)
        NS_PASSWORD = required_env("NS_PASSWORD", password)
        NS_ROLE = required_env("NS_ROLE", role)
        NS_APPID = required_env("NS_APPID", appid)

        if self.client is None:
            self.client = NetSuiteClient(account=account)
        self.client.login(
            email=NS_EMAIL, password=NS_PASSWORD, role=NS_ROLE, application_id=NS_APPID,
        )
Example #4
0
    def authorize(
        self,
        consumer_key: str = None,
        consumer_secret: str = None,
        access_token: str = None,
        access_token_secret: str = None,
    ) -> None:
        """Authorize to Twitter API

        :param consumer_key: app consumer key
        :param consumer_secret: app consumer secret
        :param access_token: user access token
        :param access_token_secret: user access token secret
        """
        if consumer_key is None:
            consumer_key = required_env("TWITTER_CONSUMER_KEY")
        if consumer_secret is None:
            consumer_secret = required_env("TWITTER_CONSUMER_SECRET")
        if access_token is None:
            access_token = required_env("TWITTER_ACCESS_TOKEN")
        if access_token_secret is None:
            access_token_secret = required_env("TWITTER_ACCESS_TOKEN_SECRET")
        self._auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        self._auth.set_access_token(access_token, access_token_secret)
        self.api = tweepy.API(self._auth, wait_on_rate_limit=True)
        try:
            self.api.verify_credentials()
            self.logger.info("Twitter authentication success")
            self._me = self.api.me()
        except TweepError as e:
            self.logger.error("Error during Twitter authentication: %s",
                              str(e))
            raise TweepError(e)
Example #5
0
    def connect(
        self,
        account: str = None,
        consumer_key: str = None,
        consumer_secret: str = None,
        token_key: str = None,
        token_secret: str = None,
    ) -> None:
        """ Connect to Netsuite with credentials from environment
        variables.

        Parameters are not logged into Robot Framework log.

        :param account: parameter or environment variable `NS_ACCOUNT`
        :param consumer_key:  parameter or environment variable `NS_CONSUMER_KEY`
        :param consumer_secret: parameter or environment variable `NS_CONSUMER_SECRET`
        :param token_key: parameter or environment variable `NS_TOKEN_KEY`
        :param token_secret: parameter or environment variable `NS_TOKEN_SECRET`
        """
        if account is None:
            self.account = required_env("NS_ACCOUNT")
        else:
            self.account = account

        NS_CONSUMER_KEY = required_env("NS_CONSUMER_KEY", consumer_key)
        NS_CONSUMER_SECRET = required_env("NS_CONSUMER_SECRET", consumer_secret)
        NS_TOKEN_KEY = required_env("NS_TOKEN_KEY", token_key)
        NS_TOKEN_SECRET = required_env("NS_TOKEN_SECRET", token_secret)
        self.client = NetSuiteConnection(
            account=self.account,
            consumer_key=NS_CONSUMER_KEY,
            consumer_secret=NS_CONSUMER_SECRET,
            token_key=NS_TOKEN_KEY,
            token_secret=NS_TOKEN_SECRET,
        )
Example #6
0
 def __init__(self, *args, **kwargs):
     # pylint: disable=unused-argument
     self.logger = logging.getLogger(__name__)
     # Environment variables set by runner
     self._host = required_env("RC_API_SECRET_HOST")
     self._token = required_env("RC_API_SECRET_TOKEN")
     self._workspace = required_env("RC_WORKSPACE_ID")
     # Generated lazily on request
     self.__private_key = None
     self.__public_bytes = None
Example #7
0
    def load_work_item_from_environment(self):
        """Load current work item defined by the runtime environment.

        The corresponding environment variables are:

        * RC_WORKSPACE_ID
        * RC_WORKITEM_ID
        """
        workspace_id = required_env("RC_WORKSPACE_ID")
        item_id = required_env("RC_WORKITEM_ID")
        return self.load_work_item(workspace_id, item_id)
Example #8
0
 def _load_adapter(self, default):
     """Load adapter by name, using env or given default."""
     adapter = required_env("RPA_WORKITEMS_ADAPTER", default)
     if isinstance(adapter, str):
         self.adapter = import_by_name(adapter, __name__)
     else:
         self.adapter = adapter
     assert issubclass(
         self.adapter,
         BaseAdapter), "Adapter does not inherit from BaseAdapter"
Example #9
0
    def __init__(self, *args, **kwargs):
        self.logger = logging.getLogger(__name__)

        default = kwargs.pop("default_adapter", RobocloudVault)
        adapter = required_env("RPA_SECRET_MANAGER", default)

        self._adapter_factory = self._create_factory(adapter, args, kwargs)
        self._adapter = None

        try:
            BuiltIn().import_library("RPA.RobotLogListener")
        except RobotNotRunningError:
            pass
Example #10
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        #: Endpoint for old work items API
        self.workitem_host = required_env("RC_API_WORKITEM_HOST")
        self.workitem_token = required_env("RC_API_WORKITEM_TOKEN")

        #: Endpoint for new process API
        self.process_host = required_env("RC_API_PROCESS_HOST")
        self.process_token = required_env("RC_API_PROCESS_TOKEN")

        #: Current execution IDs
        self.workspace_id = required_env("RC_WORKSPACE_ID")
        self.process_id = required_env("RC_PROCESS_ID")
        self.process_run_id = required_env("RC_PROCESS_RUN_ID")
        self.step_run_id = required_env("RC_ACTIVITY_RUN_ID")

        #: Input queue of work items
        self._initial_item_id: Optional[str] = required_env("RC_WORKITEM_ID")
Example #11
0
    def __init__(self, secret_file="secrets.json"):
        self.logger = logging.getLogger(__name__)

        path = required_env("RPA_SECRET_FILE", secret_file)
        self.logger.info("Resolving path: %s", path)
        self.path = resolve_path(path)

        extension = self.path.suffix
        serializer = self.SERIALIZERS.get(extension)
        # NOTE(cmin764): This will raise instead of returning an empty secrets object
        #  because it is wrong starting from the "env.json" configuration level.
        if not serializer:
            raise ValueError(
                f"Not supported local vault secrets file extension {extension!r}"
            )
        self._loader, self._dumper = serializer

        self.data = self.load()
Example #12
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # pylint: disable=invalid-envvar-default
        old_path = os.getenv("RPA_WORKITEMS_PATH", UNDEFINED_VAR)
        if old_path is not UNDEFINED_VAR:
            deprecation(
                "Work items load - Old path style usage detected, please use the "
                "'RPA_INPUT_WORKITEM_PATH' env var "
                "(more details under documentation: https://robocorp.com/docs/development-guide/control-room/data-pipeline#developing-with-work-items-locally)"  # noqa: E501
            )
        path = required_env("RPA_INPUT_WORKITEM_PATH", default=old_path)
        logging.info("Resolving path: %s", path)
        self.path = resolve_path(path)
        self._output_path = None

        self.inputs: List[Dict[str, Any]] = self.load_database()
        self.outputs: List[Dict[str, Any]] = []
        self.index: int = 0
Example #13
0
    def __init__(self, *args, **kwargs):
        """The selected adapter can be set with the environment
        variable ``RPA_SECRET_MANAGER``, or the keyword argument ``default_adapter``.
        Defaults to Robocloud Vault if not defined.

        All other library arguments are passed to the adapter.

        :param default_adapter: Override default secret adapter
        """
        self.logger = logging.getLogger(__name__)

        default = kwargs.pop("default_adapter", RobocloudVault)
        adapter = required_env("RPA_SECRET_MANAGER", default)

        self._adapter_factory = self._create_factory(adapter, args, kwargs)
        self._adapter = None

        try:
            BuiltIn().import_library("RPA.RobotLogListener")
        except RobotNotRunningError:
            pass
Example #14
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.host = required_env("RC_API_WORKITEM_HOST")
     self.token = required_env("RC_API_WORKITEM_TOKEN")
Example #15
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.path = required_env("RPA_WORKITEMS_PATH")
Example #16
0
 def __init__(self):
     self.host = required_env("RC_API_WORKITEM_HOST")
     self.token = required_env("RC_API_WORKITEM_TOKEN")
Example #17
0
 def __init__(self, secret_file="secrets.json"):
     self.logger = logging.getLogger(__name__)
     self.path = required_env("RPA_SECRET_FILE", secret_file)
     self.data = self.load(self.path)
Example #18
0
 def __init__(self):
     self.path = required_env("RPA_WORKITEMS_PATH")