def __set_server_keys(client, logging_manager, integration_params, integration_name):
    """Adds server configuration keys using the demisto_client.

    Args:
        client (demisto_client): The configured client to use.
        logging_manager (ParallelLoggingManager): logging manager object.
        integration_params (dict): The values to use for an integration's parameters to configure an instance.
        integration_name (str): The name of the integration which the server configurations keys are related to.

    """
    if 'server_keys' not in integration_params:
        return

    logging_manager.debug(f'Setting server keys for integration: {integration_name}')

    data = {
        'data': {},
        'version': -1
    }

    for key, value in integration_params.get('server_keys').items():
        data['data'][key] = value

    update_server_configuration(
        client=client,
        server_configuration=integration_params.get('server_keys'),
        error_msg='Failed to set server keys',
        logging_manager=logging_manager
    )
Beispiel #2
0
    def upload(self, logger: logging.Logger, client: demisto_client, skip_validation: bool):
        """
        Upload the pack zip to demisto_client,
        from 6.5 server version we have the option to use skip_verify arg instead of server configuration.
        Args:
            logger (logging.Logger): System logger already initialized.
            client: The demisto_client object of the desired XSOAR machine to upload to.
            skip_validation: if true will skip upload packs validation.
        Returns:
            The result of the upload command from demisto_client
        """
        if self.is_server_version_ge(client, '6.6.0') and skip_validation:
            try:
                logger.info('Uploading...')
                return client.upload_content_packs(
                    file=self.path, skip_verify='true', skip_validation='true')  # type: ignore

            except Exception as err:
                raise Exception(f'Failed to upload pack, error: {err}')

        if self.is_server_version_ge(client, '6.5.0'):
            try:
                logger.info('Uploading...')
                return client.upload_content_packs(file=self.path, skip_verify='true')  # type: ignore

            except Exception as err:
                raise Exception(f'Failed to upload pack, error: {err}')

        # the flow are - turn off the sign check -> upload -> turn back the check to be as previously
        logger.info('Turn off the server verification for signed packs')
        _, _, prev_conf = tools.update_server_configuration(client=client,
                                                            server_configuration={PACK_VERIFY_KEY: 'false'},
                                                            error_msg='Can not turn off the pack verification')
        try:
            logger.info('Uploading...')
            return client.upload_content_packs(file=self.path)  # type: ignore
        finally:
            config_keys_to_update = None
            config_keys_to_delete = None
            try:
                prev_key_val = prev_conf.get(PACK_VERIFY_KEY, None)
                if prev_key_val is not None:
                    config_keys_to_update = {PACK_VERIFY_KEY: prev_key_val}
                else:
                    config_keys_to_delete = {PACK_VERIFY_KEY}
                logger.info('Setting the server verification to be as previously')
                tools.update_server_configuration(client=client,
                                                  server_configuration=config_keys_to_update,
                                                  config_keys_to_delete=config_keys_to_delete,
                                                  error_msg='Can not turn on the pack verification')
            except (Exception, KeyboardInterrupt):
                action = DELETE_VERIFY_KEY_ACTION if prev_key_val is None \
                    else SET_VERIFY_KEY_ACTION.format(prev_key_val)
                raise Exception(TURN_VERIFICATION_ERROR_MSG.format(action=action))
import argparse

import demisto_client

from demisto_sdk.commands.test_content.tools import update_server_configuration

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description=
        "Unlocks an integration, script or a playbook in Cortex XSOAR.")
    parser.add_argument("type", choices=["integration", "script", "playbook"])
    parser.add_argument("name")
    args = parser.parse_args()
    client = demisto_client.configure(verify_ssl=False)
    update_server_configuration(
        client,
        {f"content.unlock.{args.type}s": args.name},
        "Could not update configurations",
    )
    print(f"{args.type}: {args.name} unlocked.")