diff --git a/cli/dcoscli/config/main.py b/cli/dcoscli/config/main.py index 07e1c99..4fb2767 100644 --- a/cli/dcoscli/config/main.py +++ b/cli/dcoscli/config/main.py @@ -22,10 +22,12 @@ Positional Arguments: """ import collections +import json import os import dcoscli import docopt +import pkg_resources import six import toml from dcos.api import (cmds, config, constants, emitting, errors, jsonitem, @@ -327,6 +329,16 @@ def _get_config_schema(command): :rtype: (dict, dcos.api.errors.Error) """ + # core.* config variables are special. They're valid, but don't + # correspond to any particular subcommand, so we must handle them + # separately. + if command == "core": + return (json.loads( + pkg_resources.resource_string( + 'dcoscli', + 'data/config-schema/core.json').decode('utf-8')), + None) + executable, err = subcommand.command_executables( command, util.dcos_path()) diff --git a/cli/dcoscli/data/config-schema/core.json b/cli/dcoscli/data/config-schema/core.json new file mode 100644 index 0000000..80745b5 --- /dev/null +++ b/cli/dcoscli/data/config-schema/core.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "reporting": { + "type": "boolean", + "title": "Usage Reporting", + "description": "Whether to report usage events to Mesosphere", + "default": true + }, + "email": { + "type": "string", + "title": "Your email address", + "description": "Your email address" + }, + "token": { + "type": "string", + "title": "Your OAuth token", + "description": "Your OAuth token" + } + }, + "additionalProperties": false +} diff --git a/cli/tests/data/dcos.toml b/cli/tests/data/dcos.toml index 4dec770..016834f 100644 --- a/cli/tests/data/dcos.toml +++ b/cli/tests/data/dcos.toml @@ -1,3 +1,5 @@ +[core] +reporting = true [subcommand] pip_find_links = "../dist" [marathon] diff --git a/cli/tests/integrations/cli/test_config.py b/cli/tests/integrations/cli/test_config.py index bf71457..5cad82d 100644 --- a/cli/tests/integrations/cli/test_config.py +++ b/cli/tests/integrations/cli/test_config.py @@ -67,7 +67,8 @@ def test_list_property(env): env) assert returncode == 0 - assert stdout == b"""marathon.host=localhost + assert stdout == b"""core.reporting=True +marathon.host=localhost marathon.port=8080 package.cache=tmp/cache package.sources=['git://github.com/mesosphere/universe.git', \ @@ -339,6 +340,12 @@ def test_set_missing_property(env): _get_value('marathon.host', 'localhost', env) +def test_set_core_property(env): + _set_value('core.reporting', 'false', env) + _get_value('core.reporting', False, env) + _set_value('core.reporting', 'true', env) + + def _set_value(key, value, env): returncode, stdout, stderr = exec_command( ['dcos', 'config', 'set', key, value],