Skip to content

Commit

Permalink
Update API Key implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Apr 8, 2024
1 parent 77948bb commit 7d6ecf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 11 additions & 3 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,17 @@ public class APIClient {
authTypes.jwt = {header: <string>jwtAuthentication.headerName, sendTokenToUpstream: <boolean>jwtAuthentication.sendTokenToUpstream, disabled: !jwtAuthentication.enabled, audience: jwtAuthentication.audience};
} else if authentication.authType == "APIKey" && authentication is APIKeyAuthentication {
APIKeyAuthentication apiKeyAuthentication = check authentication.cloneWithType(APIKeyAuthentication);
authTypes.apiKey = [];
authTypes.apiKey.push({'in: "Header", name: apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
authTypes.apiKey.push({'in: "Query", name: apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
model:APIKey[] apiKeys = [];
boolean|() headerEnabled = apiKeyAuthentication.headerEnable;
boolean|() queryEnabled = apiKeyAuthentication.queryParamEnable;

if headerEnabled is boolean && headerEnabled {
apiKeys.push({'in: "Header", name: <string>apiKeyAuthentication.headerName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
if queryEnabled is boolean && queryEnabled {
apiKeys.push({'in: "Query", name: <string>apiKeyAuthentication.queryParamName, sendTokenToUpstream: apiKeyAuthentication.sendTokenToUpstream});
}
authTypes.apiKey = apiKeys;
} else if authentication.authType == "mTLS" {
MTLSAuthentication mtlsAuthentication = check authentication.cloneWithType(MTLSAuthentication);
isMTLSMandatory = mtlsAuthentication.required == "mandatory";
Expand Down
7 changes: 3 additions & 4 deletions runtime/config-deployer-service/ballerina/types.bal
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ballerina/constraint;
// AUTO-GENERATED FILE.
// This file is auto-generated by the Ballerina OpenAPI tool.

import ballerina/http;
import ballerina/constraint;

public type OkAnydata record {|
*http:Ok;
Expand Down Expand Up @@ -275,8 +274,8 @@ public type APIKeyAuthentication record {|
boolean sendTokenToUpstream = false;
string headerName = "apiKey";
string queryParamName = "apiKey";
boolean headerEnable = true;
boolean queryParamEnable = true;
boolean headerEnable?;
boolean queryParamEnable?;
|};

# Mutual SSL configuration of this API
Expand Down

0 comments on commit 7d6ecf8

Please sign in to comment.