google.cloud.forseti.services.cli module

Forseti CLI.

class DefaultConfig(*args, **kwargs)[source]

Bases: dict

Represents the configuration.

DEFAULT = {'endpoint': '', 'format': 'json', 'model': ''}
DEFAULT_ENDPOINT = 'localhost:50051'
__delitem__(key)[source]

Delete item by key.

Parameters:key (object) – Key to delete value for
Raises:KeyError – If configuration key is unknown.
__getitem__(key)[source]

Get item by key.

Parameters:key (object) – Key to get value for.
Returns:Returns base classe setitem result.
Return type:object
Raises:KeyError – If configuration key is unknown.
__setitem__(key, value)[source]

Set item by key.

Parameters:
  • key (object) – Key to set value for.
  • value (object) – Value to set.
Returns:

Returns base classe setitem result.

Return type:

object

Raises:

KeyError – If configuration key is unknown.

get_default_endpoint()[source]

Get server address.

Returns:Forseti server endpoint
Return type:str
class DefaultConfigParser[source]

Bases: object

Handles creation and persistence of DefaultConfig

classmethod load()[source]

Open configuration file and create an instance from it.

Returns:DefaultConfig.
Return type:object
classmethod persist(config)[source]

Save a configuration file.

Parameters:config (obj) – Configuration to store.
class DefaultParser(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)[source]

Bases: argparse.ArgumentParser

Default parser, when error is triggered, instead of printing error message, it will print the help message (-h).

error(message=None)[source]

This method will be triggered when error occurred.

Parameters:message (str) – Error message.
class JsonOutput[source]

Bases: google.cloud.forseti.services.cli.Output

Raw output for result objects.

write(obj)[source]

Writes json representation. :param obj: Object to write as json :type obj: object

class Output[source]

Bases: object

Output base interface.

write(obj)[source]

Writes an object to the output channel. :param obj: Object to write :type obj: object

Raises:NotImplementedError – Always
create_parser(parser_cls, config_env)[source]

Create argument parser hierarchy.

Parameters:
  • parser_cls (cls) – Class to instantiate parser from.
  • config_env (object) – Configuration environment
Returns:

The argument parser hierarchy which is created.

Return type:

argparser

define_config_parser(parent)[source]

Define the config service parser.

Parameters:parent (argparser) – Parent parser to hook into.
define_explainer_parser(parent)[source]

Define the explainer service parser.

Parameters:parent (argparser) – Parent parser to hook into.
define_inventory_parser(parent)[source]

Define the inventory service parser.

Parameters:parent (argparser) – Parent parser to hook into.
define_model_parser(parent)[source]

Define the model service parser.

Parameters:parent (argparser) – Parent parser to hook into.
define_notifier_parser(parent)[source]

Define the notifier service parser.

Parameters:parent (argparser) – Parent parser to hook into.
define_parent_parser(parser_cls, config_env)[source]

Define the parent parser.

Parameters:
  • parser_cls (type) – Class to instantiate parser from.
  • config_env (object) – Configuration environment.
Returns:

The parent parser which has been defined.

Return type:

argparser

define_scanner_parser(parent)[source]

Define the scanner service parser.

Parameters:parent (argparser) – Parent parser to hook into.
define_server_parser(parent)[source]

Define the server config service parser.

Parameters:parent (argparser) – Parent parser to hook into.
get_config_path()[source]

Get configuration file path.

Returns:Configuration path.
Return type:str
main(args=None, config_env=None, client=None, outputs=None, parser_cls=<class 'google.cloud.forseti.services.cli.DefaultParser'>, services=None)[source]

Main function. :param args: CLI arguments. :type args: list :param config_env: Configuration environment. :type config_env: obj :param client: API client to use. :type client: obj :param outputs: Supported output formats. :type outputs: list :param parser_cls: Argument parser type to instantiate. :type parser_cls: type :param services: Supported Forseti Server services. :type services: list

Returns:Environment configuration.
Return type:object
read_env(var_key, default)[source]

Read an environment variable with a default value.

Parameters:
  • var_key (str) – Environment key get.
  • default (str) – Default value if variable is not set.
Returns:

return environment value or default

Return type:

string

run_config(_, config, output, config_env)[source]

Run config commands. :param _: Unused. :type _: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param config_env: Configuration environment. :type config_env: object

run_explainer(client, config, output, _)[source]

Run explain commands. :param client: client to use for requests. :type client: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param _: Unused. :type _: object

run_inventory(client, config, output, _)[source]

Run inventory commands. :param client: client to use for requests. :type client: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param _: Unused. :type _: object

run_model(client, config, output, config_env)[source]

Run model commands. :param client: client to use for requests. :type client: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param config_env: Configuration environment. :type config_env: object

run_notifier(client, config, output, _)[source]

Run notifier commands. :param client: client to use for requests. :type client: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param _: Configuration environment. :type _: object

run_scanner(client, config, output, _)[source]

Run scanner commands. :param client: client to use for requests. :type client: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param _: Configuration environment. :type _: object

run_server(client, config, output, _)[source]

Run scanner commands. :param client: client to use for requests. :type client: iam_client.ClientComposition :param config: argparser namespace to use. :type config: object :param output: output writer to use. :type output: Output :param _: Configuration environment. :type _: object