text: // Copyright 2022 Google LLC
  //
  // 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
  //
  //      https://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.
  
  // Generated by the Codegen C++ plugin.
  // If you make any local changes, they will be lost.
  // source: google/devtools/containeranalysis/v1/containeranalysis.proto
  
  #include "google/cloud/containeranalysis/container_analysis_client.h"
  #include "google/cloud/containeranalysis/container_analysis_options.h"
  #include "google/cloud/containeranalysis/internal/container_analysis_option_defaults.h"
  #include <memory>
  #include <thread>
  
  namespace google {
  namespace cloud {
  namespace containeranalysis {
  GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
  
  ContainerAnalysisClient::ContainerAnalysisClient(
      std::shared_ptr<ContainerAnalysisConnection> connection, Options options)
      : connection_(std::move(connection)),
        options_(internal::MergeOptions(
            std::move(options),
            containeranalysis_internal::ContainerAnalysisDefaultOptions(
                connection_->options()))) {}
  ContainerAnalysisClient::~ContainerAnalysisClient() = default;
  
  StatusOr<google::iam::v1::Policy> ContainerAnalysisClient::SetIamPolicy(
      std::string const& resource, google::iam::v1::Policy const& policy,
      Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    google::iam::v1::SetIamPolicyRequest request;
    request.set_resource(resource);
    *request.mutable_policy() = policy;
    return connection_->SetIamPolicy(request);
  }
  
  StatusOr<google::iam::v1::Policy> ContainerAnalysisClient::SetIamPolicy(
      std::string const& resource, IamUpdater const& updater, Options options) {
    internal::CheckExpectedOptions<ContainerAnalysisBackoffPolicyOption>(
        options, __func__);
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    google::iam::v1::GetIamPolicyRequest get_request;
    get_request.set_resource(resource);
    google::iam::v1::SetIamPolicyRequest set_request;
    set_request.set_resource(resource);
    auto backoff_policy = internal::CurrentOptions()
                              .get<ContainerAnalysisBackoffPolicyOption>()
                              ->clone();
    for (;;) {
      auto recent = connection_->GetIamPolicy(get_request);
      if (!recent) {
        return recent.status();
      }
      auto policy = updater(*std::move(recent));
      if (!policy) {
        return Status(StatusCode::kCancelled, "updater did not yield a policy");
      }
      *set_request.mutable_policy() = *std::move(policy);
      auto result = connection_->SetIamPolicy(set_request);
      if (result || result.status().code() != StatusCode::kAborted) {
        return result;
      }
      std::this_thread::sleep_for(backoff_policy->OnCompletion());
    }
  }
  
  StatusOr<google::iam::v1::Policy> ContainerAnalysisClient::SetIamPolicy(
      google::iam::v1::SetIamPolicyRequest const& request, Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    return connection_->SetIamPolicy(request);
  }
  
  StatusOr<google::iam::v1::Policy> ContainerAnalysisClient::GetIamPolicy(
      std::string const& resource, Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    google::iam::v1::GetIamPolicyRequest request;
    request.set_resource(resource);
    return connection_->GetIamPolicy(request);
  }
  
  StatusOr<google::iam::v1::Policy> ContainerAnalysisClient::GetIamPolicy(
      google::iam::v1::GetIamPolicyRequest const& request, Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    return connection_->GetIamPolicy(request);
  }
  
  StatusOr<google::iam::v1::TestIamPermissionsResponse>
  ContainerAnalysisClient::TestIamPermissions(
      std::string const& resource, std::vector<std::string> const& permissions,
      Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    google::iam::v1::TestIamPermissionsRequest request;
    request.set_resource(resource);
    *request.mutable_permissions() = {permissions.begin(), permissions.end()};
    return connection_->TestIamPermissions(request);
  }
  
  StatusOr<google::iam::v1::TestIamPermissionsResponse>
  ContainerAnalysisClient::TestIamPermissions(
      google::iam::v1::TestIamPermissionsRequest const& request,
      Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    return connection_->TestIamPermissions(request);
  }
  
  StatusOr<
      google::devtools::containeranalysis::v1::VulnerabilityOccurrencesSummary>
  ContainerAnalysisClient::GetVulnerabilityOccurrencesSummary(
      std::string const& parent, std::string const& filter, Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    google::devtools::containeranalysis::v1::
        GetVulnerabilityOccurrencesSummaryRequest request;
    request.set_parent(parent);
    request.set_filter(filter);
    return connection_->GetVulnerabilityOccurrencesSummary(request);
  }
  
  StatusOr<
      google::devtools::containeranalysis::v1::VulnerabilityOccurrencesSummary>
  ContainerAnalysisClient::GetVulnerabilityOccurrencesSummary(
      google::devtools::containeranalysis::v1::
          GetVulnerabilityOccurrencesSummaryRequest const& request,
      Options options) {
    internal::OptionsSpan span(
        internal::MergeOptions(std::move(options), options_));
    return connection_->GetVulnerabilityOccurrencesSummary(request);
  }
  
  GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
  }  // namespace containeranalysis
  }  // namespace cloud
  }  // namespace google
  