Use -dot- subdomain notation in MapReduce console links

appspot.com is not provisioned with a multi-level wildcard SSL certificate, so
URLs of the form https://service.projectid.appspot.com/path need to be rewritten
as https://service-dot-projectid.appspot.com/path (and same for version names).

This is a follow-up to []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=231418795
This commit is contained in:
mcilwain 2019-01-29 09:43:30 -08:00 committed by Michael Muller
parent 6e0b8f2cfd
commit 3812c2ceda
7 changed files with 85 additions and 6 deletions

View file

@ -38,6 +38,25 @@ public interface AppEngineServiceUtils {
/** Returns a host name to use for the given service and version. */
String getVersionHostname(String service, String version);
/**
* Converts a multi-level App Engine host name (not URL) to the -dot- single subdomain format.
*
* <p>This is needed because appspot.com only has a single wildcard SSL certificate, so the native
* App Engine URLs of the form service.projectid.appspot.com or
* version.service.projectid.appspot.com won't work over HTTPS when being fetched from outside of
* GCP. The work-around is to change all of the "." subdomain markers to "-dot-". E.g.:
*
* <ul>
* <li>tools.projectid.appspot.com --> tools-dot-projectid.appspot.com
* <li>version.backend.projectid.appspot.com --> version-dot-backend-dot-projectid.appspot.com
* </ul>
*
* @see <a
* href="https://cloud.google.com/appengine/docs/standard/java/how-requests-are-routed">How
* App Engine requests are routed</a>
*/
String convertToSingleSubdomain(String hostname);
/** Set the number of instances at runtime for a given service and version. */
void setNumInstances(String service, String version, long numInstances);
}

View file

@ -18,11 +18,18 @@ import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.appengine.api.modules.ModulesService;
import com.google.common.flogger.FluentLogger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
/** A wrapper for {@link ModulesService} that provides a saner API. */
public class AppEngineServiceUtilsImpl implements AppEngineServiceUtils {
private static final Pattern APPSPOT_HOSTNAME_PATTERN =
Pattern.compile("^(.*)\\.appspot\\.com$");
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final ModulesService modulesService;
@Inject
@ -56,4 +63,14 @@ public class AppEngineServiceUtilsImpl implements AppEngineServiceUtils {
checkArgument(numInstances > 0, "Number of instances must be greater than 0");
modulesService.setNumInstances(service, version, numInstances);
}
@Override
public String convertToSingleSubdomain(String hostname) {
Matcher matcher = APPSPOT_HOSTNAME_PATTERN.matcher(hostname);
if (!matcher.matches()) {
logger.atWarning().log("Skipping conversion because hostname can't be parsed: %s", hostname);
return hostname;
}
return matcher.group(1).replace(".", "-dot-") + ".appspot.com";
}
}