MCPcopy Create free account
hub / github.com/grpc/grpc-java / parse

Method parse

core/src/main/java/io/grpc/internal/SpiffeUtil.java:68–90  ·  view source on GitHub ↗

Parses a URI string, applies validation rules described in SPIFFE standard, and, in case of success, returns parsed TrustDomain and Path. @param uri a String representing a SPIFFE ID

(String uri)

Source from the content-addressed store, hash-verified

66 * @param uri a String representing a SPIFFE ID
67 */
68 public static SpiffeId parse(String uri) {
69 doInitialUriValidation(uri);
70 checkArgument(uri.toLowerCase(Locale.US).startsWith(PREFIX), "Spiffe Id must start with "
71 + PREFIX);
72 String domainAndPath = uri.substring(PREFIX.length());
73 String trustDomain;
74 String path;
75 if (!domainAndPath.contains("/")) {
76 trustDomain = domainAndPath;
77 path = "";
78 } else {
79 String[] parts = domainAndPath.split("/", 2);
80 trustDomain = parts[0];
81 path = parts[1];
82 checkArgument(!path.isEmpty(), "Path must not include a trailing '/'");
83 }
84 validateTrustDomain(trustDomain);
85 validatePath(path);
86 if (!path.isEmpty()) {
87 path = "/" + path;
88 }
89 return new SpiffeId(trustDomain, path);
90 }
91
92 private static void doInitialUriValidation(String uri) {
93 checkArgument(checkNotNull(uri, "uri").length() > 0, "Spiffe Id can't be empty");

Callers 6

parseSuccessTestMethod · 0.95
parseFailureTestMethod · 0.95
spiffeUriFormatTestMethod · 0.95
spiffePathFormatTestMethod · 0.95
extractSpiffeIdMethod · 0.95

Calls 5

validateTrustDomainMethod · 0.95
validatePathMethod · 0.95
containsMethod · 0.45
isEmptyMethod · 0.45

Tested by 5

parseSuccessTestMethod · 0.76
parseFailureTestMethod · 0.76
spiffeUriFormatTestMethod · 0.76
spiffePathFormatTestMethod · 0.76