Skip to content

Commit

Permalink
Give unique name to Scope CR
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Apr 16, 2024
1 parent d9749db commit de809ef
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public class APIClient {
if apiArtifact.scopes.hasKey(scope) {
scopeCr = apiArtifact.scopes.get(scope);
} else {
scopeCr = self.generateScopeCR(apiArtifact, apkConf, organization, scope, count);
scopeCr = self.generateScopeCR(operation, apiArtifact, apkConf, organization, scope, count);
count = count + 1;
}
model:HTTPRouteFilter scopeFilter = {'type: "ExtensionRef", extensionRef: {group: "dp.wso2.com", kind: scopeCr.kind, name: scopeCr.metadata.name}};
Expand Down Expand Up @@ -654,7 +654,7 @@ public class APIClient {
if apiArtifact.scopes.hasKey(scope) {
scopeCr = apiArtifact.scopes.get(scope);
} else {
scopeCr = self.generateScopeCR(apiArtifact, apkConf, organization, scope, count);
scopeCr = self.generateScopeCR(operation, apiArtifact, apkConf, organization, scope, count);
count = count + 1;
}
model:GQLRouteFilter scopeFilter = {extensionRef: {group: "dp.wso2.com", kind: scopeCr.kind, name: scopeCr.metadata.name}};
Expand Down Expand Up @@ -722,10 +722,10 @@ public class APIClient {
return ();
}

private isolated function generateScopeCR(model:APIArtifact apiArtifact, APKConf apkConf, commons:Organization organization, string scope, int count) returns model:Scope {
private isolated function generateScopeCR(APKOperations operation, model:APIArtifact apiArtifact, APKConf apkConf, commons:Organization organization, string scope, int count) returns model:Scope {
model:Scope scopeCr = {
metadata: {
name: apiArtifact.uniqueId + "-scope-" + count.toString(),
name: self.getScopeUid(apiArtifact, operation, count),
labels: self.getLabels(apkConf, organization)
},
spec: {
Expand Down Expand Up @@ -1531,6 +1531,17 @@ public class APIClient {
}
}

public isolated function getScopeUid(model:APIArtifact apiArtifact, APKOperations? apiOperation, int count) returns string {
string scopeUid = apiArtifact.uniqueId;
if (apiOperation is APKOperations) {
if (apiOperation.target is string) {
byte[] hexBytes = string:toBytes(<string>apiArtifact.uniqueId + <string>apiOperation.target + <string>apiOperation.verb);
scopeUid = crypto:hashSha1(hexBytes).toBase16();
}
}
return scopeUid + "-scope-" + count.toString();
}

public isolated function getBackendPolicyUid(APKConf api, string endpointType, commons:Organization organization) returns string {
string concatanatedString = uuid:createType1AsString();
return "backendpolicy-" + concatanatedString;
Expand Down

0 comments on commit de809ef

Please sign in to comment.