| 78 | SKIP_AUTH_CLASSES = [] |
| 79 | |
| 80 | def get_client(self, args, debug=False): |
| 81 | ST2_CLI_SKIP_CONFIG = os.environ.get("ST2_CLI_SKIP_CONFIG", 0) |
| 82 | ST2_CLI_SKIP_CONFIG = int(ST2_CLI_SKIP_CONFIG) |
| 83 | |
| 84 | skip_config = args.skip_config |
| 85 | skip_config = skip_config or ST2_CLI_SKIP_CONFIG |
| 86 | |
| 87 | # Note: Options provided as the CLI argument have the highest precedence |
| 88 | # Precedence order: cli arguments > environment variables > rc file variables |
| 89 | cli_options = [ |
| 90 | "base_url", |
| 91 | "auth_url", |
| 92 | "api_url", |
| 93 | "stream_url", |
| 94 | "api_version", |
| 95 | "cacert", |
| 96 | "basic_auth", |
| 97 | ] |
| 98 | cli_options = {opt: getattr(args, opt, None) for opt in cli_options} |
| 99 | if cli_options.get("cacert", None) is not None: |
| 100 | if cli_options["cacert"].lower() in ["true", "1", "t", "y", "yes"]: |
| 101 | cli_options["cacert"] = True |
| 102 | elif cli_options["cacert"].lower() in ["false", "0", "f", "no"]: |
| 103 | cli_options["cacert"] = False |
| 104 | config_file_options = self._get_config_file_options(args=args) |
| 105 | |
| 106 | kwargs = {} |
| 107 | |
| 108 | if not skip_config: |
| 109 | # Config parsing is not skipped |
| 110 | kwargs = merge_dicts(kwargs, config_file_options) |
| 111 | |
| 112 | kwargs = merge_dicts(kwargs, cli_options) |
| 113 | kwargs["debug"] = debug |
| 114 | |
| 115 | client = Client(**kwargs) |
| 116 | |
| 117 | if skip_config: |
| 118 | # Config parsing is skipped |
| 119 | self.LOG.info("Skipping parsing CLI config") |
| 120 | return client |
| 121 | |
| 122 | # Ok to use config at this point |
| 123 | rc_config = get_config() |
| 124 | |
| 125 | # Silence SSL warnings |
| 126 | silence_ssl_warnings = rc_config.get("general", {}).get( |
| 127 | "silence_ssl_warnings", False |
| 128 | ) |
| 129 | if silence_ssl_warnings: |
| 130 | # pylint: disable=no-member |
| 131 | requests.packages.urllib3.disable_warnings(InsecureRequestWarning) |
| 132 | |
| 133 | # We skip automatic authentication for some commands such as auth |
| 134 | try: |
| 135 | command_class_name = args.func.__self__.__class__.__name__ |
| 136 | except Exception: |
| 137 | command_class_name = None |