def run_rule()

in gcpdiag/lint/composer/err_2023_005_environment_delete_fail_nat_config.py [0:0]


def run_rule(context: models.Context, report: lint.LintReportRuleInterface):

  if not apis.is_enabled(context.project_id, 'composer'):
    report.add_skipped(None, 'composer is disabled')
    return

  if not apis.is_enabled(context.project_id, 'logging'):
    report.add_skipped(None, 'logging api is disabled')
    return

  envs = envs_by_project[context.project_id]

  if not envs:
    report.add_skipped(None, 'no Cloud Composer environments found')
    return

  env_name_set = set()

  if logs_by_project.get(context.project_id) and \
     logs_by_project[context.project_id].entries:
    for log_entry in logs_by_project[context.project_id].entries:
      # filter out non -relevant entries
      logging_check_path = get_path(log_entry,
                                    ('protoPayload', 'status', 'message'),
                                    default='')
      if (log_entry['severity'] != 'ERROR' or
          log_entry['protoPayload']['methodName'] != MATCH_METHOD or
          (((MATCH_STR_1 not in logging_check_path) or
            (MATCH_STR_2 not in logging_check_path) or
            (MATCH_STR_3 not in logging_check_path)) and
           (MATCH_STR_4 not in logging_check_path))):
        continue
      env_name = get_path(log_entry, ('resource', 'labels', 'environment_name'))
      env_name_set.add(env_name)

  for env in envs:
    if (env.state == 'ERROR') and (env.name in env_name_set):
      report.add_failed(env)
    else:
      report.add_ok(env)