public void injectAccountAndContainerForPostRequest(RestRequest restRequest, RestRequestMetricsGroup metricsGroup)
      throws RestServiceException {
    accountAndContainerSanityCheck(restRequest);
    if (getHeader(restRequest.getArgs(), Headers.TARGET_ACCOUNT_NAME, false) != null
        || getHeader(restRequest.getArgs(), Headers.TARGET_CONTAINER_NAME, false) != null) {
      ensureRequiredHeadersOrThrow(restRequest, requiredAmbryHeadersForPutWithAccountAndContainerName);
      frontendMetrics.putWithAccountAndContainerHeaderRate.mark();
      injectAccountAndContainerUsingAccountAndContainerHeaders(restRequest, metricsGroup);
    } else if (frontendConfig.allowServiceIdBasedPostRequest) {
      ensureRequiredHeadersOrThrow(restRequest, requiredAmbryHeadersForPutWithServiceId);
      frontendMetrics.putWithServiceIdForAccountNameRate.mark();
      String serviceId = getHeader(restRequest.getArgs(), Headers.SERVICE_ID, true);
      boolean isPrivate = isPrivate(restRequest.getArgs());
      injectAccountAndContainerUsingServiceId(restRequest, serviceId, isPrivate, metricsGroup);
    } else {
      throw new RestServiceException(
          "Missing either " + Headers.TARGET_ACCOUNT_NAME + " or " + Headers.TARGET_CONTAINER_NAME + " header",
          RestServiceErrorCode.BadRequest);
    }
  }
Injects target {@link Account} and {@link Container} for PUT requests. This method also ensures required headers
are present for the PUT requests that use serviceId as the account name, and the PUT requests that carry both the
{@code x-ambry-target-account} and {@code x-ambry-target-container} headers.
@param restRequest The Put {@link RestRequest}.
@param metricsGroup The {@link RestRequestMetricsGroup} to use to set up {@link ContainerMetrics}, or {@code null}
                    if {@link ContainerMetrics} instantiation is not needed.
@throws RestServiceException
ambry-frontend/src/main/java/com/github/ambry/frontend/AccountAndContainerInjector.java