Skip to content

Commit

Permalink
Add name generation for apk-conf
Browse files Browse the repository at this point in the history
  • Loading branch information
DDH13 committed May 3, 2024
1 parent ed46c2c commit 2282d77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class APIClient {
encodedString = encodedString.substring(0, encodedString.length() - 1);
}
APKConf apkConf = {
name: api.getName(),
name: api.getType() == API_TYPE_GRPC ? self.getUniqueNameForGrpcApi(api.getName()) : api.getName(),
basePath: api.getBasePath().length() > 0 ? api.getBasePath() : encodedString,
version: api.getVersion(),
'type: api.getType() == "" ? API_TYPE_REST : api.getType().toUpperAscii()
Expand Down Expand Up @@ -1679,6 +1679,11 @@ public class APIClient {
return hashedValue.toBase16();
}

public isolated function getUniqueNameForGrpcApi(string concatanatedServices) returns string {
byte[] hashedValue = crypto:hashSha1(concatanatedServices.toBytes());
return hashedValue.toBase16();
}

public isolated function retrieveHttpRouteRefName(APKConf apkConf, string 'type, commons:Organization organization) returns string {
return uuid:createType1AsString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,24 @@ private static API getGRPCAPIFromProtoDefinition(String definition) {
API api = new API();
api.setBasePath("/"+protoParser.protoFile.basePath);
api.setVersion(protoParser.protoFile.version);
StringBuilder apiName = new StringBuilder();
List<String> sortedServices = new ArrayList<>();

for (ProtoParser.Service service : protoParser.getServices()) {
sortedServices.add(service.name);
for (String method : service.methods) {
URITemplate uriTemplate = new URITemplate();
uriTemplate.setUriTemplate(protoParser.protoFile.packageName + "." + service.name);
uriTemplate.setVerb(method);
uriTemplates.add(uriTemplate);
}
}
sortedServices.sort(String::compareTo);
for (String service : sortedServices) {
apiName.append(service).append("-");
}
apiName.deleteCharAt(apiName.length() - 1);
api.setName(apiName.toString());
api.setUriTemplates(uriTemplates.toArray(new URITemplate[uriTemplates.size()]));

return api;
Expand Down

0 comments on commit 2282d77

Please sign in to comment.