def revoke_token(self, token: str):
        """
        Revokes the given token.
        """
        if token is None:
            raise MissingRequiredParameterException('Missing required parameters')

        return self.client.revoke_token(token)
Ejemplo n.º 2
0
def get_param(name: str, **kwargs):
    """
    Return value of name if name in kwargs; None otherwise.
    Throws MissingRequiredParameterException in case kwargs is empty or not
    provided
    """
    if len(kwargs) == 0:
        raise MissingRequiredParameterException('arg_params is empty')
    return kwargs[name] if name in kwargs else None
    def create_host(self, create_host_data: CreateHostData) -> str:
        """
        Creates a host factory token using the parameters in the 'create_token_data' argument.
        Returns the generated token.
        """
        if create_host_data is None:
            raise MissingRequiredParameterException('Missing required parameters')

        response = self.client.create_host(create_host_data)
        return json.dumps(response, indent=4, sort_keys=True)
Ejemplo n.º 4
0
 def get_username(self):
     """
     Method to fetch the username if the user did not provide one
     """
     if self.credential_data.username is None:
         # pylint: disable=logging-fstring-interpolation,line-too-long
         self.credential_data.username = input(
             "Enter your username: "******"Error: Login name is required")
Ejemplo n.º 5
0
    def from_full_id(cls, full_id: str):
        """
        Factory method for
        """
        id_parts = full_id.split(':', 2)
        if len(id_parts) == 3:
            # If identifier contains also the account part, remove it.
            id_parts.pop(0)
        elif len(id_parts) != 2:
            raise MissingRequiredParameterException(
                f"Resource ID missing 'kind:' prefix: {full_id}")

        return Resource(kind=id_parts[0], identifier=id_parts[1])
Ejemplo n.º 6
0
 def prompt_for_host_id_if_needed(self):
     """
     Method to prompt the user to enter the host id of the
     host whose API key they want to rotate
     """
     if self.host_resource_data.host_to_update is None:
         # pylint: disable=line-too-long
         self.host_resource_data.host_to_update = input(
             "Enter the host id to rotate its API key: ").strip()
         if self.host_resource_data.host_to_update == '':
             # pylint: disable=raise-missing-from
             raise MissingRequiredParameterException(
                 "Error: Host id is required")
Ejemplo n.º 7
0
 def _get_account_info_if_not_exist(self):
     """
     Method to fetch the account from the user
     """
     if self.conjurrc_data.conjur_account is None:
         try:
             self.init_logic.fetch_account_from_server(self.conjurrc_data, self.ssl_verification_data)
         except HttpSslError as ssl_err:
             raise HttpSslError("SSL Error. Make sure Conjur "
                                "server's root certificate is trusted in this machine. "
                                "If this problem continues, visit docs for more help") from ssl_err
         except HttpStatusError as error:
             # Check for catching if the endpoint is exists. If the endpoint does not exist,
             # a 401 status code will be returned.
             # If the endpoint does not exist, the user will be prompted to enter in their account.
             if error.status == http.HTTPStatus.UNAUTHORIZED:
                 self.conjurrc_data.conjur_account = input(
                     "Enter the Conjur account name (required): ").strip()
                 if self.conjurrc_data.conjur_account is None or self.conjurrc_data.conjur_account == '':
                     raise MissingRequiredParameterException("Error: account is required")
             else:
                 raise