コード例 #1
0
ファイル: cli.py プロジェクト: up42/up42-py
def up42(ctx, project_id, project_api_key, cfg_file, env):
    ctx.ensure_object(dict)
    if project_id and project_api_key:
        ctx.obj = Auth(project_id=project_id,
                       project_api_key=project_api_key,
                       env=env)
    elif cfg_file:
        ctx.obj = Auth(cfg_file=cfg_file, env=env)
コード例 #2
0
    def place(cls, auth: Auth, data_provider_name: str,
              order_params: Dict) -> "Order":
        """
        Places an order.

        Args:
            auth (Auth): An authentication object.
            data_provider_name (str): The data provider name. Currently only `oneatlas` is a supported provider.
            order_params (Dict): Order definition, including `id` and `aoi`.

        Returns:
            Order: The placed order.
        """
        assert (
            data_provider_name in DATA_PROVIDERS
        ), f"Currently only {DATA_PROVIDERS} are supported as a data provider."
        order_payload = {
            "dataProviderName": data_provider_name,
            "orderParams": order_params,
        }
        url = f"{auth._endpoint()}/workspaces/{auth.workspace_id}/orders"
        response_json = auth._request(request_type="POST",
                                      url=url,
                                      data=order_payload)
        try:
            order_id = response_json["data"]["id"]  # type: ignore
        except KeyError as e:
            raise ValueError(f"Order was not placed: {response_json}") from e
        order = cls(auth=auth, order_id=order_id, payload=order_payload)
        logger.info(f"Order {order.order_id} is now {order.status}.")
        return order
コード例 #3
0
ファイル: cli.py プロジェクト: up42/up42-py
def config(auth, env):
    """
    Create a config file.
    """
    if auth:
        config_path = Path("./config.json").resolve()
        logger.info("Saving config to {}".format(config_path))

        json_config = {
            "project_id": auth.project_id,
            "project_api_key": auth.project_api_key,
        }

        with open(config_path, "w") as cfg:
            json.dump(json_config, cfg)

        auth = Auth(cfg_file=str(config_path), env=env)
        logger.info(
            "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
        logger.info(
            "Run the following command to persist with this authentication:")
        logger.info("export UP42_CFG_FILE={}".format(auth.cfg_file))
        logger.info(
            "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    else:
        logger.error(
            "Unable to authenticate! Check project keys or config file.")
コード例 #4
0
    def estimate(auth: Auth, data_provider_name: str,
                 order_params: Dict) -> int:
        """
        Returns an estimation of the cost of an order.

        Args:
            auth (Auth): An authentication object.
            data_provider_name (str): The data provider name. Currently only `oneatlas` is a supported provider.
            order_params (Dict): Order definition, including `id` and `aoi`.

        Returns:
            int: The estimated cost of the order
        """
        assert (
            data_provider_name in DATA_PROVIDERS
        ), f"Currently only {DATA_PROVIDERS} are supported as a data provider."
        url = f"{auth._endpoint()}/workspaces/{auth.workspace_id}/orders/estimate"
        payload = {
            "dataProviderName": data_provider_name,
            "orderParams": order_params,
        }

        response_json = auth._request(request_type="POST",
                                      url=url,
                                      data=payload)
        estimated_credits: int = response_json["data"][
            "credits"]  # type: ignore
        logger.info(
            f"Order with order parameters {payload} is estimated to cost {estimated_credits} UP42 credits."
        )
        return estimated_credits
コード例 #5
0
ファイル: __init__.py プロジェクト: stasSajinDD/up42-py
def authenticate(
    cfg_file: Union[str, Path] = None,
    project_id: str = None,
    project_api_key: str = None,
    **kwargs,
):
    global _auth  # pylint: disable=global-statement
    _auth = Auth(
        cfg_file=cfg_file,
        project_id=project_id,
        project_api_key=project_api_key,
        **kwargs,
    )