Skip to content

Commit

Permalink
fix(bazel): include iam Go dep for IAMPolicy mixin (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Sep 14, 2021
1 parent ba3b1ad commit 55e3a6c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bazel/src/main/java/com/google/api/codegen/bazel/ApiDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class ApiDir {
Pattern.compile("_(?<version>[a-zA-Z]+\\d+[\\w]*)\\.yaml");
private static String CLOUD_AUTH_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
private static String LOCATIONS_MIXIN = "name: google.cloud.location.Locations";
private static String IAM_POLICY_MIXIN = "name: google.iam.v1.IAMPolicy";

private final Map<String, String> serviceYamlPaths = new TreeMap<>();
private final Map<String, Boolean> cloudScopes = new TreeMap<>();
private final Map<String, Boolean> containLocations = new TreeMap<>();
private final Map<String, Boolean> containIAMPolicy = new TreeMap<>();

Map<String, String> getServiceYamlPaths() {
return serviceYamlPaths;
Expand All @@ -43,6 +45,10 @@ Map<String, Boolean> getContainsLocations() {
return containLocations;
}

Map<String, Boolean> getContainsIAMPolicy() {
return containIAMPolicy;
}

void parseYamlFile(String fileName, String fileBody) {
// It is a service yaml
Matcher m = SERVICE_YAML_TYPE.matcher(fileBody);
Expand All @@ -57,6 +63,9 @@ void parseYamlFile(String fileName, String fileBody) {
if (fileBody.contains(LOCATIONS_MIXIN)) {
containLocations.put(verKey, true);
}
if (fileBody.contains(IAM_POLICY_MIXIN)) {
containIAMPolicy.put(verKey, true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ApiVersionedDir {

private static String LOCATIONS_MIXIN = "name: google.cloud.location.Locations";

private static String IAM_POLICY_MIXIN = "name: google.iam.v1.IAMPolicy";

private static final String[] PRESERVED_PROTO_LIBRARY_STRING_ATTRIBUTES = {
// TypeScript:
"package_name",
Expand Down Expand Up @@ -167,6 +169,8 @@ class ApiVersionedDir {

private boolean containsLocations;

private boolean containsIAMPolicy;

// Names of *_gapic_assembly_* rules (since they may be overridden by the user)
private final Map<String, String> assemblyPkgRulesNames = new HashMap<>();

Expand Down Expand Up @@ -250,6 +254,10 @@ boolean hasLocations() {
return this.containsLocations;
}

boolean hasIAMPolicy() {
return this.containsIAMPolicy;
}

void parseYamlFile(String fileName, String fileBody) {
// It is a gapic yaml
Matcher m = GAPIC_YAML_TYPE.matcher(fileBody);
Expand Down Expand Up @@ -286,6 +294,11 @@ void parseYamlFile(String fileName, String fileBody) {
if (fileBody.contains(LOCATIONS_MIXIN)) {
this.containsLocations = true;
}

// API Serivce config has IAMPolicy API.
if (fileBody.contains(IAM_POLICY_MIXIN)) {
this.containsIAMPolicy = true;
}
}
}

Expand Down Expand Up @@ -428,5 +441,8 @@ void injectFieldsFromTopLevel() {

boolean topLevelContainsLocations = parent.getContainsLocations().getOrDefault(version, false);
containsLocations = topLevelContainsLocations ? topLevelContainsLocations : containsLocations;

boolean topLevelContainsIAMPolicy = parent.getContainsIAMPolicy().getOrDefault(version, false);
containsIAMPolicy = topLevelContainsIAMPolicy ? topLevelContainsIAMPolicy : containsIAMPolicy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ class BazelBuildFileView {
"java_gapic_test_deps", joinSetWithIndentationNl(mapJavaGapicTestDeps(actualImports)));
tokens.put("extra_imports_java", joinSetWithIndentationNl(mapJavaGapicAssemblyPkgDeps(extraImports)));

// Add iam_policy_proto dependency for mix-in if individual language rules need it.
// Java does not seem to need it for mix-in purposes, so this is added after Java deps
// are worked out.
if (bp.hasIAMPolicy() && !bp.getProtoPackage().equals("google.iam.v1")) {
extraImports.add("//google/iam/v1:iam_policy_proto");
}
actualImports.addAll(extraImports);

// Construct GAPIC import path & package name based on go_package proto option
String protoPkg = bp.getProtoPackage();
boolean isCloud = bp.getCloudScope() || protoPkg.contains("cloud");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ title: Example Library API
apis:
- name: google.example.library.v1.LibraryService
- name: google.cloud.location.Locations
- name: google.iam.v1.IAMPolicy

documentation:
summary: A simple Google Example Library API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ go_gapic_library(
":library_go_proto",
"//google/api:httpbody_go_proto",
"//google/cloud/location:location_go_proto",
"//google/iam/v1:iam_go_proto",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ title: Example Library API
apis:
- name: google.example.library.v1.LibraryService
- name: google.cloud.location.Locations
- name: google.iam.v1.IAMPolicy

documentation:
summary: A simple Google Example Library API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ go_gapic_library(
":library_go_proto",
"//google/api:httpbody_go_proto",
"//google/cloud/location:location_go_proto",
"//google/iam/v1:iam_go_proto",
],
)

Expand Down

0 comments on commit 55e3a6c

Please sign in to comment.