Example #1
0
 def test_that_init_auth_will_find_the_users_home_dir_and_apikeyfile(self):
     fd, tmpfile = tempfile.mkstemp()
     auth.get_config_path = lambda _: tmpfile
     args = {}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'api_key_file_location': tmpfile})
     os.unlink(tmpfile)
Example #2
0
 def test_that_init_auth_will_find_the_users_home_dir_and_apikeyfile(self):
     fd, tmpfile = tempfile.mkstemp()
     auth.get_config_path = lambda _: tmpfile
     args = {}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'api_key_file_location': tmpfile})
     os.unlink(tmpfile)
Example #3
0
 def test_init_auth_handles_the_apikeyfile_flag_properly(self):
     fd, tmpfile = tempfile.mkstemp()
     tmpfile = realpath(tmpfile)
     args = {'--apikeyfile': tmpfile}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'api_key_file_location': tmpfile})
     os.unlink(tmpfile)
Example #4
0
 def test_init_auth_handles_the_apikeyfile_flag_properly(self):
     fd, tmpfile = tempfile.mkstemp()
     tmpfile = realpath(tmpfile)
     args = {'--apikeyfile': tmpfile}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'api_key_file_location': tmpfile})
     os.unlink(tmpfile)
Example #5
0
 def test_init_auth_handles_the_environment_variables_with_apikeyfile(self):
     fd, tmpfile = tempfile.mkstemp()
     os.environ['STORMPATH_APIKEY_FILE'] = tmpfile
     args = {}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'api_key_file_location': tmpfile})
     os.unlink(tmpfile)
     del os.environ['STORMPATH_APIKEY_FILE']
Example #6
0
 def test_init_auth_handles_the_environment_variables_with_apikeyfile(self):
     fd, tmpfile = tempfile.mkstemp()
     os.environ['STORMPATH_APIKEY_FILE'] = tmpfile
     args = {}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'api_key_file_location': tmpfile})
     os.unlink(tmpfile)
     del os.environ['STORMPATH_APIKEY_FILE']
Example #7
0
 def test_init_auth_handles_the_environment_variables_with_key_and_secret(self):
     args = {}
     os.environ['STORMPATH_APIKEY_ID'] = 'key'
     os.environ['STORMPATH_APIKEY_SECRET'] = 'secret'
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'id': 'key', 'secret': 'secret'})
     del os.environ['STORMPATH_APIKEY_ID']
     del os.environ['STORMPATH_APIKEY_SECRET']
Example #8
0
 def test_init_auth_handles_the_environment_variables_with_key_and_secret(
         self):
     args = {}
     os.environ['STORMPATH_APIKEY_ID'] = 'key'
     os.environ['STORMPATH_APIKEY_SECRET'] = 'secret'
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'id': 'key', 'secret': 'secret'})
     del os.environ['STORMPATH_APIKEY_ID']
     del os.environ['STORMPATH_APIKEY_SECRET']
Example #9
0
 def test_init_auth_handles_the_apikey_flag_properly(self):
     args = {'--apikey': 'key:secret'}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'id': 'key', 'secret': 'secret'})
Example #10
0
def main():
    arguments = docopt(__doc__)
    action = arguments.get('<action>')
    resource = arguments.get('<resource>')

    log = setup_output(arguments.get('--verbose'))

    arguments.update(get_context_dict())
    arguments, resource, action = find_non_dash_arguments_and_default_action(
        arguments, resource, action)
    arguments = properly_support_boolean_values(arguments)
    arguments = check_primary_identifier_without_flags(arguments, resource,
                                                       action)

    if not action:
        log.error(__doc__.strip('\n'))
        return -1

    if action == 'help':
        log.error(__doc__.strip('\n'))
        return -1

    if action not in AVAILABLE_ACTIONS:
        log.error(
            "Unknown action '{}'. See 'stormpath --help' for list of available actions."
            .format(action))
        return -1

    if action in LOCAL_ACTIONS:
        return 0 if AVAILABLE_ACTIONS[action](arguments) else -1

    if not resource and action != STATUS_ACTION:
        if action == SET_ACTION:
            log.error(
                "A resource type is required. Available resources for the set command are: application, directory. Please see 'stormpath --help'"
            )
            return -1

        log.error(
            "A resource type is required. Available resources: {}. Please see 'stormpath --help'"
            .format(', '.join(sorted(AVAILABLE_RESOURCES.keys()))))
        return -1

    if resource not in AVAILABLE_RESOURCES and action != STATUS_ACTION:
        log.error(
            "Unknown resource type '{}'. See 'stormpath --help' for list of available resource types."
            .format(resource))
        return -1

    try:
        auth_args = init_auth(arguments)
        client = Client(user_agent=USER_AGENT, **auth_args)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    if action == STATUS_ACTION:
        return 0 if AVAILABLE_ACTIONS[action](client, arguments) else -1

    try:
        res = AVAILABLE_RESOURCES[resource](client, arguments)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    act = AVAILABLE_ACTIONS[action]

    try:
        result = act(res, arguments)
    except (StormpathError, ValueError) as ex:
        log.error(str(ex))
        return -1

    if result is not None and (isinstance(result, list) or isinstance(
            result, dict) or isinstance(result, types.GeneratorType)):
        output(result,
               show_links=arguments.get('--show-links', False),
               show_headers=arguments.get('--show-headers', False),
               output_json=arguments.get('--output-json', False))
    return 0
Example #11
0
def main():
    arguments = docopt(__doc__)
    action = arguments.get('<action>')
    resource = arguments.get('<resource>')

    log = setup_output(arguments.get('--verbose'))

    arguments.update(get_context_dict())
    arguments = strip_equal_sign(arguments)

    if resource and resource.find('=') != -1:
        # Workaround for when list command is not specified
        # and non-dash attributes are used
        arguments['<attributes>'].append(resource)
        arguments['<resource>'] = None
        resource = None

    if action in AVAILABLE_RESOURCES and not resource:
        resource = action
        action = DEFAULT_ACTION

    if not action:
        log.error(__doc__.strip('\n'))
        return -1

    if action not in AVAILABLE_ACTIONS:
        log.error("Unknown action '%s'. See 'stormpath --help' for list of "
            "available actions." % action)
        return -1

    if action in LOCAL_ACTIONS:
        return 0 if AVAILABLE_ACTIONS[action](arguments) else -1

    if not resource:
        log.error("A resource type is required. Available resources: %s. "
            "Please see 'stormpath --help'" % ", ".join(sorted(AVAILABLE_RESOURCES.keys())))
        return -1

    if resource not in AVAILABLE_RESOURCES:
        log.error("Unknown resource type '%s'. See 'stormpath --help' for "
            "list of available resource types." % resource)
        return -1

    try:
        auth_args = init_auth(arguments)
        client = Client(user_agent=USER_AGENT, **auth_args)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    try:
        res = AVAILABLE_RESOURCES[resource](client, arguments)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    act = AVAILABLE_ACTIONS[action]

    try:
        result = act(res, arguments)
    except (StormpathError, ValueError) as ex:
        log.error(str(ex))
        return -1

    if result is not None and (isinstance(result, list) or isinstance(result, dict)):
        output(result,
            show_links=arguments.get('--show-links', False))
    return 0
Example #12
0
def main():
    arguments = docopt(__doc__)
    action = arguments.get('<action>')
    resource = arguments.get('<resource>')

    log = setup_output(arguments.get('--verbose'))

    arguments.update(get_context_dict())
    arguments, resource, action = find_non_dash_arguments_and_default_action(arguments, resource, action)
    arguments = properly_support_boolean_values(arguments)
    arguments = check_primary_identifier_without_flags(arguments, resource, action)

    if not action:
        log.error(__doc__.strip('\n'))
        return -1

    if action == 'help':
        log.error(__doc__.strip('\n'))
        return -1

    if action not in AVAILABLE_ACTIONS:
        log.error("Unknown action '{}'. See 'stormpath --help' for list of available actions.".format(action))
        return -1

    if action in LOCAL_ACTIONS:
        return 0 if AVAILABLE_ACTIONS[action](arguments) else -1

    if not resource and action != STATUS_ACTION:
        if action == SET_ACTION:
            log.error("A resource type is required. Available resources for the set command are: application, directory. Please see 'stormpath --help'")
            return -1

        log.error("A resource type is required. Available resources: {}. Please see 'stormpath --help'".format(', '.join(sorted(AVAILABLE_RESOURCES.keys()))))
        return -1

    if resource not in AVAILABLE_RESOURCES and action != STATUS_ACTION:
        log.error("Unknown resource type '{}'. See 'stormpath --help' for list of available resource types.".format(resource))
        return -1

    try:
        auth_args = init_auth(arguments)
        client = Client(user_agent=USER_AGENT, **auth_args)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    if action == STATUS_ACTION:
        return 0 if AVAILABLE_ACTIONS[action](client, arguments) else -1

    try:
        res = AVAILABLE_RESOURCES[resource](client, arguments)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    act = AVAILABLE_ACTIONS[action]

    try:
        result = act(res, arguments)
    except (StormpathError, ValueError) as ex:
        log.error(str(ex))
        return -1

    if result is not None and (
            isinstance(result, list) or
            isinstance(result, dict) or
            isinstance(result, types.GeneratorType)):
        output(
            result, show_links=arguments.get('--show-links', False),
            show_headers=arguments.get('--show-headers', False),
            output_json=arguments.get('--output-json', False))
    return 0
Example #13
0
def main():
    arguments = docopt(__doc__)
    action = arguments.get('<action>')
    resource = arguments.get('<resource>')

    log = setup_output(arguments.get('--verbose'))

    arguments.update(get_context_dict())
    arguments = strip_equal_sign(arguments)

    if resource and resource.find('=') != -1:
        # Workaround for when list command is not specified
        # and non-dash attributes are used
        arguments['<attributes>'].append(resource)
        arguments['<resource>'] = None
        resource = None

    if action in AVAILABLE_RESOURCES and not resource:
        resource = action
        action = DEFAULT_ACTION

    if not action:
        log.error(__doc__.strip('\n'))
        return -1

    if action not in AVAILABLE_ACTIONS:
        log.error("Unknown action '%s'. See 'stormpath --help' for list of "
                  "available actions." % action)
        return -1

    if action in LOCAL_ACTIONS:
        return 0 if AVAILABLE_ACTIONS[action](arguments) else -1

    if not resource:
        log.error("A resource type is required. Available resources: %s. "
                  "Please see 'stormpath --help'" %
                  ", ".join(sorted(AVAILABLE_RESOURCES.keys())))
        return -1

    if resource not in AVAILABLE_RESOURCES:
        log.error("Unknown resource type '%s'. See 'stormpath --help' for "
                  "list of available resource types." % resource)
        return -1

    try:
        auth_args = init_auth(arguments)
        client = Client(user_agent=USER_AGENT, **auth_args)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    try:
        res = AVAILABLE_RESOURCES[resource](client, arguments)
    except ValueError as ex:
        log.error(str(ex))
        return -1

    act = AVAILABLE_ACTIONS[action]

    try:
        result = act(res, arguments)
    except (StormpathError, ValueError) as ex:
        log.error(str(ex))
        return -1

    if result is not None and (isinstance(result, list)
                               or isinstance(result, dict)):
        output(result, show_links=arguments.get('--show-links', False))
    return 0
Example #14
0
 def test_init_auth_handles_the_apikey_flag_properly(self):
     args = {'--apikey': 'key:secret'}
     ret = auth.init_auth(args)
     self.assertEquals(ret, {'id': 'key', 'secret': 'secret'})