<commit_before># Lint as: python3
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License,Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Functions for collecting GCP related environment configurations."""

import enum
from typing import List, Text, Optional
from . import utility


class Commands(enum.Enum):
  """Enum for gcloud and gsutil commands."""
  GET_APIS = 1
  GET_CONTAINER_CLUSTERS = 2
  GET_CONTAINER_IMAGES = 3
  GET_DISKS = 4
  GET_GCLOUD_DEFAULT = 5
  GET_NETWORKS = 6
  GET_QUOTAS = 7
  GET_SCOPES = 8
  GET_SERVICE_ACCOUNTS = 9
  GET_STORAGE_BUCKETS = 10
  GET_GCLOUD_VERSION = 11


_command_string = {
    Commands.GET_APIS: 'services list',
    Commands.GET_CONTAINER_CLUSTERS: 'container clusters list',
    Commands.GET_CONTAINER_IMAGES: 'container images list',
    Commands.GET_DISKS: 'compute disks list',
    Commands.GET_GCLOUD_DEFAULT: 'config list --all',
    Commands.GET_NETWORKS: 'compute networks list',
    Commands.GET_QUOTAS: 'compute regions list',
    Commands.GET_SCOPES: 'compute instances list',
    Commands.GET_SERVICE_ACCOUNTS: 'iam service-accounts list',
    Commands.GET_STORAGE_BUCKETS: 'ls',
    Commands.GET_GCLOUD_VERSION: 'version',
}


def execute_gcloud_command(
    gcloud_command_list: List[Text],
    project_id: Optional[Text] = None,
    human_readable: Optional[bool] = False) -> utility.ExecutorResponse:
  """Function for invoking gcloud command.

  Args:
    gcloud_command_list: a command string list to be past to gcloud example
      format is ['config', 'list', '--all']
    project_id: specificies the project to run the commands against if not
      provided provided will use gcloud default project if one is configured
      otherwise will return an error message.
    human_readable: If false sets parameter --format json for all calls,
      otherwie output will be in human readable format.

  Returns:
    utility.ExecutorResponse with outputs from stdout,stderr and execution code.
  """
  command_list = ['gcloud']<commit_msg>Adding auth list support for diagnose_me (#3052)<commit_after># Lint as: python3
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License,Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Functions for collecting GCP related environment configurations."""

import enum
from typing import List, Text, Optional
from . import utility


class Commands(enum.Enum):
  """Enum for gcloud and gsutil commands."""
  GET_APIS = 1
  GET_CONTAINER_CLUSTERS = 2
  GET_CONTAINER_IMAGES = 3
  GET_DISKS = 4
  GET_GCLOUD_DEFAULT = 5
  GET_NETWORKS = 6
  GET_QUOTAS = 7
  GET_SCOPES = 8
  GET_SERVICE_ACCOUNTS = 9
  GET_STORAGE_BUCKETS = 10
  GET_GCLOUD_VERSION = 11
  GET_AUTH_LIST = 12


_command_string = {
    Commands.GET_APIS: 'services list',
    Commands.GET_CONTAINER_CLUSTERS: 'container clusters list',
    Commands.GET_CONTAINER_IMAGES: 'container images list',
    Commands.GET_DISKS: 'compute disks list',
    Commands.GET_GCLOUD_DEFAULT: 'config list --all',
    Commands.GET_NETWORKS: 'compute networks list',
    Commands.GET_QUOTAS: 'compute regions list',
    Commands.GET_SCOPES: 'compute instances list',
    Commands.GET_SERVICE_ACCOUNTS: 'iam service-accounts list',
    Commands.GET_STORAGE_BUCKETS: 'ls',
    Commands.GET_GCLOUD_VERSION: 'version',
    Commands.GET_AUTH_LIST: 'auth list',
}


def execute_gcloud_command(
    gcloud_command_list: List[Text],
    project_id: Optional[Text] = None,
    human_readable: Optional[bool] = False) -> utility.ExecutorResponse:
  """Function for invoking gcloud command.

  Args:
    gcloud_command_list: a command string list to be past to gcloud example
      format is ['config', 'list', '--all']
    project_id: specificies the project to run the commands against if not
      provided provided will use gcloud default project if one is configured
      otherwise will return an error message.
    human_readable: If false sets parameter --format json for all calls,
      otherwie output will be in human readable format.

  Returns:
    utility.ExecutorResponse with outputs from stdout,stderr and execution code.
  """
  command_list = ['gcloud']
{'fraction_non_alphanumeric': 0.07761839261151503, 'fraction_numerical': 0.009825112988799371, 'mean_word_length': 4.1727642276422765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1197418', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1508, 'n_words': 538}