Пример #1
0
def _ValidateDockerRepo(repo_name):
    repo = ar_requests.GetRepository(repo_name)
    messages = ar_requests.GetMessages()
    if repo.format != messages.Repository.FormatValueValuesEnum.DOCKER:
        raise ar_exceptions.InvalidInputValueError(
            "Invalid repository type {}. The `artifacts docker` command group can "
            "only be used on Docker repositories.".format(repo.format))
Пример #2
0
def ShouldCreateRepository(repo):
    """Checks for the existence of the provided repository.

  If the provided repository does not exist, the user will be prompted
  as to whether they would like to continue.

  Args:
    repo: googlecloudsdk.command_lib.artifacts.docker_util.DockerRepo defining
      the repository.

  Returns:
    A boolean indicating whether a repository needs to be created.
  """
    try:
        requests.GetRepository(repo.GetRepositoryName())
        return False
    except base_exceptions.HttpForbiddenError:
        log.error(
            'Permission denied while accessing Artifact Registry. Artifact '
            'Registry access is required to deploy from source.')
        raise
    except base_exceptions.HttpBadRequestError:
        log.error('Error in retrieving repository from Artifact Registry.')
        raise
    except base_exceptions.HttpNotFoundError:
        message = (
            'Deploying from source requires an Artifact Registry Docker '
            'repository to store built containers. A repository named '
            '[{name}] in region [{location}] will be created.'.format(
                name=repo.repo, location=repo.location))

        console_io.PromptContinue(message, cancel_on_no=True)

    return True
Пример #3
0
def GetRedirectionEnablementReport(project):
    """Prints a redirection enablement report and returns mis-configured repos.

  This checks all the GCR repositories in the supplied project and checks if
  they each have a repository in Artifact Registry create to be the redirection
  target. It prints a report as it validates.

  Args:
    project: The project to validate

  Returns:
    A list of the GCR repos that do not have a redirection repo configured in
    Artifact Registry.
  """
    locations = ar_requests.ListLocations(project, 100)

    # Sorting is performed so that Python2 & 3 agree on the order of API calls
    # in scenario tests.
    gcr_repos = GetExistingGCRBuckets(
        sorted(_GCR_BUCKETS.values(), key=lambda x: x["repository"]), project)

    failed_repos = []
    repo_report = []
    report_line = []
    con = console_attr.GetConsoleAttr()

    # For each gcr repo in a location that our environment supports,
    # is there an associated repo in AR?
    for gcr_repo in gcr_repos:
        if gcr_repo["location"] in locations:
            report_line = [gcr_repo["repository"], gcr_repo["location"]]
            ar_repo_name = "projects/{}/locations/{}/repositories/{}".format(
                project, gcr_repo["location"], gcr_repo["repository"])
            try:
                ar_repo = ar_requests.GetRepository(ar_repo_name)
                report_line.append(con.Colorize(ar_repo.name, "green"))
            except apitools_exceptions.HttpNotFoundError:
                report_line.append(con.Colorize("NOT FOUND", "red"))
                failed_repos.append(gcr_repo)
            repo_report.append(report_line)

    log.status.Print("Redirection enablement report:\n")
    printer = resource_printer.Printer("table", out=log.status)
    printer.AddHeading([
        con.Emphasize("Container Registry Host", bold=True),
        con.Emphasize("Location", bold=True),
        con.Emphasize("Artifact Registry Repository", bold=True)
    ])
    for line in repo_report:
        printer.AddRecord(line)
    printer.Finish()
    log.status.Print()
    return failed_repos
Пример #4
0
def _GetLocationRepoPathAndMavenConfig(args, repo_format):
  """Get resource values and validate user input."""
  repo = _GetRequiredRepoValue(args)
  project = _GetRequiredProjectValue(args)
  location = _GetRequiredLocationValue(args)
  repo_path = project + "/" + repo
  repo = ar_requests.GetRepository(
      "projects/{}/locations/{}/repositories/{}".format(project, location,
                                                        repo))
  if repo.format != repo_format:
    raise ar_exceptions.InvalidInputValueError(
        "Invalid repository type {}. Valid type is {}.".format(
            repo.format, repo_format))
  return location, repo_path, repo.mavenConfig
Пример #5
0
def _GetLocationAndRepoPath(args, repo_format):
    """Get resource values and validate user input."""
    repo = _GetRequiredRepoValue(args)
    project = _GetRequiredProjectValue(args)
    location = _GetRequiredLocationValue(args)
    repo_path = project + "/" + repo
    location_list = ar_requests.ListLocations(project)
    if location.lower() not in location_list:
        raise ar_exceptions.UnsupportedLocationError(
            "{} is not a valid location. Valid locations are [{}].".format(
                location, ", ".join(location_list)))
    repo = ar_requests.GetRepository(
        "projects/{}/locations/{}/repositories/{}".format(
            project, location, repo))
    if repo.format != repo_format:
        raise ar_exceptions.InvalidInputValueError(
            "Invalid repository type {}. Valid type is {}.".format(
                repo.format, repo_format))
    return location, repo_path