Remove cap on soy (#2592)

We still need to cap the protobuf version that soy depends on, but the
rest of nomulus can use the latest version of protobuf.
This commit is contained in:
Lai Jiang
2024-10-18 17:21:26 +00:00
committed by GitHub
parent 1171c5cfcb
commit 4d96e5a6b1
28 changed files with 459 additions and 630 deletions
@@ -1,137 +0,0 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// 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
//
// http://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.
package google.registry.ui.server;
import static com.google.common.base.Suppliers.memoize;
import static com.google.common.io.Resources.asCharSource;
import static com.google.common.io.Resources.getResource;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import com.google.template.soy.SoyFileSet;
import com.google.template.soy.SoyUtils;
import com.google.template.soy.parseinfo.SoyFileInfo;
import com.google.template.soy.shared.SoyCssRenamingMap;
import com.google.template.soy.tofu.SoyTofu;
import google.registry.ui.ConsoleDebug;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** Helper methods for rendering Soy templates from Java code. */
public final class SoyTemplateUtils {
@VisibleForTesting
public static final Supplier<SoyCssRenamingMap> CSS_RENAMING_MAP_SUPPLIER =
SoyTemplateUtils.createCssRenamingMapSupplier(
Resources.getResource("google/registry/ui/css/registrar_bin.css.js"),
Resources.getResource("google/registry/ui/css/registrar_dbg.css.js"));
/** Returns a memoized supplier containing compiled tofu. */
public static Supplier<SoyTofu> createTofuSupplier(final SoyFileInfo... soyInfos) {
return memoize(
() -> {
ConsoleDebug debugMode = ConsoleDebug.get();
SoyFileSet.Builder builder = SoyFileSet.builder();
for (SoyFileInfo soyInfo : soyInfos) {
builder.add(getResource(soyInfo.getClass(), soyInfo.getFileName()));
}
Map<String, Object> globals;
try {
globals =
new HashMap<>(SoyUtils.parseCompileTimeGlobals(asCharSource(SOY_GLOBALS, UTF_8)));
} catch (IOException e) {
throw new RuntimeException("Failed to load soy globals", e);
}
globals.put("DEBUG", debugMode.ordinal());
builder.setCompileTimeGlobals(globals);
return builder.build().compileToTofu();
});
}
/** Returns a memoized supplier of the thing you pass to {@code setCssRenamingMap()}. */
public static Supplier<SoyCssRenamingMap> createCssRenamingMapSupplier(
final URL cssMap,
final URL cssMapDebug) {
return memoize(
() -> {
final ImmutableMap<String, String> renames = getCssRenames(cssMap, cssMapDebug);
return (cssClassName) -> {
List<String> result = new ArrayList<>();
for (String part : CSS_CLASS_SPLITTER.split(cssClassName)) {
result.add(renames.getOrDefault(part, part));
}
return CSS_CLASS_JOINER.join(result);
};
});
}
private static ImmutableMap<String, String> getCssRenames(URL cssMap, URL cssMapDebug) {
try {
return switch (ConsoleDebug.get()) {
case RAW -> ImmutableMap.of(); // See firstNonNull() above for clarification.
case DEBUG -> extractCssRenames(Resources.toString(cssMapDebug, UTF_8));
default -> extractCssRenames(Resources.toString(cssMap, UTF_8));
};
} catch (IOException e) {
throw new RuntimeException("Failed to load css map", e);
}
}
/**
* Extract class name rewrites from a {@code .css.js} mapping file.
*
* <p>This is the file created when you pass {@code --css_renaming_output_file} to the Closure
* Stylesheets compiler. In order for this to work, {@code --output_renaming_map_format} should
* be {@code CLOSURE_COMPILED} or {@code CLOSURE_UNCOMPILED}.
*
* <p>Here's an example of what the {@code .css.js} file looks like:<pre>
*
* goog.setCssNameMapping({
* "nonLatin": "a",
* "secondary": "b",
* "mobile": "c"
* });</pre>
*
* <p>This is a burden that's only necessary for tofu, since the closure compiler is smart enough
* to substitute CSS class names when soy is compiled to JavaScript.
*/
private static ImmutableMap<String, String> extractCssRenames(String json) {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
Matcher matcher = KEY_VALUE_PATTERN.matcher(json);
while (matcher.find()) {
builder.put(matcher.group(1), matcher.group(2));
}
return builder.build();
}
private static final URL SOY_GLOBALS = getResource("google/registry/ui/globals.txt");
private static final Splitter CSS_CLASS_SPLITTER = Splitter.on('-');
private static final Joiner CSS_CLASS_JOINER = Joiner.on('-');
private static final Pattern KEY_VALUE_PATTERN =
Pattern.compile("['\"]([^'\"]+)['\"]: ['\"]([^'\"]+)['\"]");
private SoyTemplateUtils() {}
}
@@ -17,7 +17,7 @@
/**
* Template for the content of the monthly spec11 email
*/
{template .monthlySpec11Email}
{template monthlySpec11Email}
{@param threats: list<map<string, string>>}
{@param resources: list<string>}
{@param registry: string}
@@ -32,7 +32,7 @@
security concerns. This may be because the registrants have not completed the requisite steps
to mitigate the potential security abuse and/or have it reviewed and delisted.</p>
{call .threatMatchTable}
{call threatMatchTable}
{param threats: $threats /}
{/call}
@@ -42,7 +42,7 @@
please <a href="https://safebrowsing.google.com/safebrowsing/report_error/?hl=en">submit a
request</a> to have the site reviewed.</p>
{call .resourceList}
{call resourceList}
{param resources: $resources /}
{/call}
@@ -56,7 +56,7 @@
/**
* Template for the content of the daily spec11 email
*/
{template .dailySpec11Email}
{template dailySpec11Email}
{@param threats: list<map<string, string>>}
{@param resources: list<string>}
{@param date: string}
@@ -69,14 +69,14 @@
identify potential security concerns. On {$date}, the following domains that your
registrar manages were flagged for potential security concerns:</p>
{call .threatMatchTable}
{call threatMatchTable}
{param threats: $threats /}
{/call}
<p><b>Please communicate these findings to the registrant and work with the
registrant to mitigate any security issues and have the domains delisted.</b></p>
{call .resourceList}
{call resourceList}
{param resources: $resources /}
{/call}
@@ -98,7 +98,7 @@
/**
* Template for the list of potentially-useful resources
*/
{template .resourceList}
{template resourceList}
{@param resources: list<string>}
{if length($resources) > 0}
Some helpful resources for getting off a blocked list include:
@@ -113,7 +113,7 @@
/**
* Template for the table containing the threats themselves
*/
{template .threatMatchTable}
{template threatMatchTable}
{@param threats: list<map<string, string>>}
<table>
<tr>
@@ -122,8 +122,8 @@
</tr>
{for $threat in $threats}
<tr>
<td>{$threat['domainName']}</td>
<td>{$threat['threatType']}</td>
<td>{$threat.get('domainName')}</td>
<td>{$threat.get('threatType')}</td>
</tr>
{/for}
</table>
@@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.contact_create}
/**
* Create contact
*/
{template .contactcreate stricthtml="false"}
{@param? id: string}
{@param? name: string}
{@param? org: string}
{@param? street: list<string>}
{@param? city: string}
{@param? state: string}
{@param? zip: string}
{@param? cc: string}
{@param? phone: string}
{@param? fax: string}
{@param? email: string}
{template contactcreate stricthtml="false"}
{@param? id: string|null}
{@param? name: string|null}
{@param? org: string|null}
{@param? street: list<string>|null}
{@param? city: string|null}
{@param? state: string|null}
{@param? zip: string|null}
{@param? cc: string|null}
{@param? phone: string|null}
{@param? fax: string|null}
{@param? email: string|null}
{@param password: string}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -12,19 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.create_anchor_tenant}
/**
* Create anchor tenant domain
*/
{template .createanchortenant stricthtml="false"}
{template createanchortenant stricthtml="false"}
{@param domainName: string}
{@param contactId: string}
{@param password: string}
{@param period: int}
{@param? reason: string}
{@param? feeCurrency: string}
{@param? fee: string}
{@param? reason: string|null}
{@param? feeCurrency: string|null}
{@param? fee: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.domain_check}
/**
* Domain check request
*/
{template .domaincheck stricthtml="false"}
{template domaincheck stricthtml="false"}
{@param domainNames: list<string>}
{@param? allocationToken: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -40,7 +40,7 @@
</fee:domain>
{/for}
</fee:check>
{if isNonnull($allocationToken)}
{if $allocationToken}
<allocationToken:allocationToken
xmlns:allocationToken="urn:ietf:params:xml:ns:allocationToken-1.0">
{$allocationToken}
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.domain_check_claims}
/**
* Domain check claims request
*/
{template .domaincheckclaims stricthtml="false"}
{template domaincheckclaims stricthtml="false"}
{@param domainNames: list<string>}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.domain_create}
/**
* Create domain
*/
{template .domaincreate stricthtml="false"}
{template domaincreate stricthtml="false"}
{@param domain: string}
{@param period: int}
{@param nameservers: list<string>}
@@ -24,12 +24,12 @@
{@param admins: list<string>}
{@param techs: list<string>}
{@param password: string}
{@param? currency: string}
{@param? price: string}
{@param? currency: string|null}
{@param? price: string|null}
{@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
{@param? reason: string}
{@param? requestedByRegistrar: string}
{@param? allocationToken: string}
{@param? reason: string|null}
{@param? requestedByRegistrar: string|null}
{@param? allocationToken: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@@ -57,7 +57,7 @@
</domain:authInfo>
</domain:create>
</create>
{if length($dsRecords) > 0 or $price != null or $reason or $requestedByRegistrar or $allocationToken}
{if length($dsRecords) > 0 || $price != null || $reason || $requestedByRegistrar || $allocationToken}
<extension>
{if $price != null}
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
@@ -77,7 +77,7 @@
{/for}
</secDNS:create>
{/if}
{if $reason or $requestedByRegistrar}
{if $reason || $requestedByRegistrar}
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
{if $reason}
<metadata:reason>{$reason}</metadata:reason>
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.domain_delete}
/**
* Delete domain request
*/
{template .deletedomain stricthtml="false"}
{template deletedomain stricthtml="false"}
{@param domainName: string}
{@param immediately: bool}
{@param reason: string}
@@ -12,17 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.domain_renew}
/**
* Renew domain request
*/
{template .renewdomain stricthtml="false"}
{template renewdomain stricthtml="false"}
{@param domainName: string}
{@param expirationDate: string}
{@param period: string}
{@param? reason: string}
{@param? requestedByRegistrar: string}
{@param? reason: string|null}
{@param? requestedByRegistrar: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
@@ -34,7 +34,7 @@
<domain:period unit="y">{$period}</domain:period>
</domain:renew>
</renew>
{if $reason or $requestedByRegistrar}
{if $reason || $requestedByRegistrar}
<extension>
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
{if $reason}
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.domain_update}
/**
* Update domain
*/
{template .domainupdate stricthtml="false"}
{template domainupdate stricthtml="false"}
{@param domain: string}
{@param add: bool}
{@param addNameservers: list<string>}
@@ -29,15 +29,15 @@
{@param removeTechs: list<string>}
{@param removeStatuses: list<string>}
{@param change: bool}
{@param? registrant: string}
{@param? password: string}
{@param? registrant: string|null}
{@param? password: string|null}
{@param secdns: bool}
{@param addDsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
{@param removeDsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
{@param removeAllDsRecords: bool}
{@param? autorenews: string}
{@param? reason: string}
{@param? requestedByRegistrar: string}
{@param? autorenews: string|null}
{@param? reason: string|null}
{@param? requestedByRegistrar: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@@ -99,7 +99,7 @@
{/if}
</domain:update>
</update>
{if $secdns or $autorenews or $reason or $requestedByRegistrar}
{if $secdns || $autorenews || $reason || $requestedByRegistrar}
<extension>
{if $secdns}
<secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
@@ -139,7 +139,7 @@
<superuser:autorenews>{$autorenews}</superuser:autorenews>
</superuser:domainUpdate>
{/if}
{if $reason or $requestedByRegistrar}
{if $reason || $requestedByRegistrar}
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
{if $reason}
<metadata:reason>{$reason}</metadata:reason>
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.host_create}
/**
* Create host
*/
{template .hostcreate stricthtml="false"}
{template hostcreate stricthtml="false"}
{@param hostname: string}
{@param? ipv4addresses: list<string>}
{@param? ipv6addresses: list<string>}
{@param? ipv4addresses: list<string>|null}
{@param? ipv6addresses: list<string>|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.host_delete}
/**
* Delete host request
*/
{template .deletehost stricthtml="false"}
{template deletehost stricthtml="false"}
{@param hostName: string}
{@param reason: string}
{@param requestedByRegistrar: any}
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.remove_ip_address}
/**
* Request to remove IP addresses.
*/
{template .remove_ip_address stricthtml="false"}
{template remove_ip_address stricthtml="false"}
{@param name: string}
{@param ipAddresses: list<legacy_object_map<string, string>>}
{@param requestedByRegistrar: string}
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.uniform_rapid_suspension}
/**
* Uniform Rapid Suspension
*/
{template .uniformrapidsuspension stricthtml="false"}
{template uniformrapidsuspension stricthtml="false"}
{@param domainName: string}
{@param hostsToAdd: list<string>}
{@param hostsToRemove: list<string>}
@@ -12,17 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
{namespace domain.registry.tools}
{namespace domain.registry.tools.update_server_locks}
/**
* Update server locks
*/
{template .updateserverlocks stricthtml="false"}
{template updateserverlocks stricthtml="false"}
{@param domainName: string}
{@param locksToApply: list<string>}
{@param locksToRemove: list<string>}
{@param requestedByRegistrar: any}
{@param? reason: string}
{@param? reason: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
@@ -1,5 +0,0 @@
DEBUG = null
google.registry.ui.ConsoleDebug.PRODUCTION = 0
google.registry.ui.ConsoleDebug.DEBUG = 1
google.registry.ui.ConsoleDebug.RAW = 2
google.registry.ui.ConsoleDebug.TEST = 3