Skip to content

Commit

Permalink
Remove configurability of ApiKeyHeader from deployment.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
IsuruMaduranga committed Aug 14, 2023
1 parent 3e49417 commit bb45427
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,15 +759,15 @@ public void setAuthorizationHeader(String authorizationHeader) {
}

/**
* Name of the API key header used for invoking the API. If it is not set, API key header name specified in tenant or system level will be used.
* Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used.
**/
public APIDTO apiKeyHeader(String apiKeyHeader) {
this.apiKeyHeader = apiKeyHeader;
return this;

Check warning on line 766 in components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIDTO.java#L765-L766

Added lines #L765 - L766 were not covered by tests
}


@ApiModelProperty(example = "apiKey", value = "Name of the API key header used for invoking the API. If it is not set, API key header name specified in tenant or system level will be used. ")
@ApiModelProperty(example = "apiKey", value = "Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. ")
@JsonProperty("apiKeyHeader")
@Pattern(regexp="(^[^~!@#;:%^*()+={}|\\\\<>\"',&$\\s+]*$)") public String getApiKeyHeader() {
return apiKeyHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,15 +625,15 @@ public void setAuthorizationHeader(String authorizationHeader) {
}

/**
* Name of the API key header used for invoking the API. If it is not set, API key header name specified in tenant or system level will be used.
* Name of the API key header used for invoking the API. If it is not set, default value &#x60;apiKey&#x60; will be used.
**/
public APIProductDTO apiKeyHeader(String apiKeyHeader) {
this.apiKeyHeader = apiKeyHeader;
return this;

Check warning on line 632 in components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIProductDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIProductDTO.java#L631-L632

Added lines #L631 - L632 were not covered by tests
}


@ApiModelProperty(example = "ApiKey", value = "Name of the API key header used for invoking the API. If it is not set, API key header name specified in tenant or system level will be used. ")
@ApiModelProperty(example = "ApiKey", value = "Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. ")
@JsonProperty("apiKeyHeader")
public String getApiKeyHeader() {
return apiKeyHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class SettingsDTO {
private String defaultSubscriptionPolicy = null;
private String authorizationHeader = null;
private List<SettingsCustomPropertiesDTO> customProperties = new ArrayList<SettingsCustomPropertiesDTO>();
private String apiKeyHeader = null;

/**
* The Developer Portal URL
Expand Down Expand Up @@ -274,24 +273,6 @@ public void setCustomProperties(List<SettingsCustomPropertiesDTO> customProperti
this.customProperties = customProperties;
}

/**
* Api Key Header
**/
public SettingsDTO apiKeyHeader(String apiKeyHeader) {
this.apiKeyHeader = apiKeyHeader;
return this;
}


@ApiModelProperty(example = "apiKey", value = "Api Key Header")
@JsonProperty("apiKeyHeader")
public String getApiKeyHeader() {
return apiKeyHeader;
}
public void setApiKeyHeader(String apiKeyHeader) {
this.apiKeyHeader = apiKeyHeader;
}


@Override
public boolean equals(java.lang.Object o) {
Expand All @@ -314,13 +295,12 @@ public boolean equals(java.lang.Object o) {
Objects.equals(defaultAdvancePolicy, settings.defaultAdvancePolicy) &&
Objects.equals(defaultSubscriptionPolicy, settings.defaultSubscriptionPolicy) &&
Objects.equals(authorizationHeader, settings.authorizationHeader) &&
Objects.equals(customProperties, settings.customProperties) &&
Objects.equals(apiKeyHeader, settings.apiKeyHeader);
Objects.equals(customProperties, settings.customProperties);
}

@Override
public int hashCode() {
return Objects.hash(devportalUrl, environment, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, customProperties, apiKeyHeader);
return Objects.hash(devportalUrl, environment, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, customProperties);
}

@Override
Expand All @@ -341,7 +321,6 @@ public String toString() {
sb.append(" defaultSubscriptionPolicy: ").append(toIndentedString(defaultSubscriptionPolicy)).append("\n");
sb.append(" authorizationHeader: ").append(toIndentedString(authorizationHeader)).append("\n");
sb.append(" customProperties: ").append(toIndentedString(customProperties)).append("\n");
sb.append(" apiKeyHeader: ").append(toIndentedString(apiKeyHeader)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static APITemplateBuilderImpl getAPITemplateBuilder(API api, String tenan
if (!StringUtils.isBlank(api.getApiKeyHeader())) {
apiKeyHeader = api.getApiKeyHeader();
} else {
apiKeyHeader = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.API_KEY_HEADER);
apiKeyHeader = APIConstants.API_KEY_HEADER_DEFAULT;

Check warning on line 128 in components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java#L128

Added line #L128 was not covered by tests
}
if (!StringUtils.isBlank(apiKeyHeader)) {
corsProperties.put(APIConstants.API_KEY_HEADER, apiKeyHeader);
Expand Down Expand Up @@ -313,7 +313,7 @@ public static APITemplateBuilderImpl getAPITemplateBuilder(APIProduct apiProduct
if (!StringUtils.isBlank(apiProduct.getApiKeyHeader())) {
apiKeyHeader = apiProduct.getApiKeyHeader();
} else {
apiKeyHeader = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.API_KEY_HEADER);
apiKeyHeader = APIConstants.API_KEY_HEADER_DEFAULT;

Check warning on line 316 in components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java#L316

Added line #L316 was not covered by tests
}
if (!StringUtils.isBlank(apiKeyHeader)) {
corsProperties.put(APIConstants.API_KEY_HEADER, apiKeyHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ public static API fromDTOtoAPI(APIDTO dto, String provider) throws APIManagement
setMaxTpsFromApiDTOToModel(dto, model);
model.setAuthorizationHeader(dto.getAuthorizationHeader());
model.setApiKeyHeader(dto.getApiKeyHeader());
if (model.getApiKeyHeader() == null) {
model.setApiKeyHeader(APIConstants.API_KEY_HEADER_DEFAULT);
}
model.setApiSecurity(getSecurityScheme(dto.getSecurityScheme()));

if (dto.getType().toString().equals(APIConstants.API_TYPE_WEBSUB)) {
Expand Down Expand Up @@ -2671,6 +2674,9 @@ public static APIProduct fromDTOtoAPIProduct(APIProductDTO dto, String provider)
product.setApiSecurity(getSecurityScheme(dto.getSecurityScheme()));
product.setAuthorizationHeader(dto.getAuthorizationHeader());
product.setApiKeyHeader(dto.getApiKeyHeader());
if (product.getApiKeyHeader() == null) {
product.setApiKeyHeader(APIConstants.API_KEY_HEADER_DEFAULT);

Check warning on line 2678 in components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java#L2678

Added line #L2678 was not covered by tests
}

//attach api categories to API model
setAPICategoriesToModel(dto, product, provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,9 +1150,6 @@ public static API prepareToCreateAPIByDTO(APIDTO body, APIProvider apiProvider,
if (body.getAuthorizationHeader() == null) {
body.setAuthorizationHeader(APIConstants.AUTHORIZATION_HEADER_DEFAULT);
}
if (body.getApiKeyHeader() == null) {
body.setApiKeyHeader(APIUtil.getOAuthConfigurationFromAPIMConfig(APIConstants.API_KEY_HEADER));
}
if (body.getApiKeyHeader() == null) {
body.setApiKeyHeader(APIConstants.API_KEY_HEADER_DEFAULT);
}
Expand Down Expand Up @@ -1771,10 +1768,6 @@ public static APIProduct addAPIProductWithGeneratedSwaggerDefinition(APIProductD
apiProductDTO.setAuthorizationHeader(APIConstants.AUTHORIZATION_HEADER_DEFAULT);
}

if (apiProductDTO.getApiKeyHeader() == null) {
apiProductDTO.setApiKeyHeader(
APIUtil.getOAuthConfigurationFromAPIMConfig(APIConstants.API_KEY_HEADER));
}
if (apiProductDTO.getApiKeyHeader() == null) {
apiProductDTO.setApiKeyHeader(APIConstants.API_KEY_HEADER_DEFAULT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,11 @@ public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, String organizatio
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain,
APIConstants.AUTHORIZATION_HEADER);
String apiKeyHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain,
APIConstants.API_KEY_HEADER);

if (authorizationHeader == null) {
authorizationHeader = APIConstants.AUTHORIZATION_HEADER_DEFAULT;
}
if (apiKeyHeader == null) {
apiKeyHeader = APIConstants.API_KEY_HEADER_DEFAULT;
}
settingsDTO.setAuthorizationHeader(authorizationHeader);
settingsDTO.setApiKeyHeader(apiKeyHeader);
}
return settingsDTO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8709,8 +8709,7 @@ components:
type: string
pattern: '(^[^~!@#;:%^*()+={}|\\<>"'',&$\s+]*$)'
description: |
Name of the API key header used for invoking the API. If it is not set, API key header name specified
in tenant or system level will be used.
Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used.
example: apiKey
securityScheme:
type: array
Expand Down Expand Up @@ -9388,8 +9387,7 @@ components:
apiKeyHeader:
type: string
description: |
Name of the API key header used for invoking the API. If it is not set, API key header name specified
in tenant or system level will be used.
Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used.
example: ApiKey
securityScheme:
type: array
Expand Down Expand Up @@ -11483,10 +11481,6 @@ components:
required:
type: boolean
example: false
apiKeyHeader:
type: string
description: Api Key Header
example: apiKey
SecurityAuditAttribute:
title: SecurityAuditAttributeDTO
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,15 @@ public void setAuthorizationHeader(String authorizationHeader) {
}

/**
* Name of the API key header used for invoking the API. If it is not set, API key header name specified in tenant or system level will be used.
* Name of the API key header used for invoking the API. If it is not set, default value &#x60;apiKey&#x60; will be used.
**/
public APIDTO apiKeyHeader(String apiKeyHeader) {
this.apiKeyHeader = apiKeyHeader;
return this;

Check warning on line 328 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/dto/APIDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/dto/APIDTO.java#L327-L328

Added lines #L327 - L328 were not covered by tests
}


@ApiModelProperty(example = "ApiKey", value = "Name of the API key header used for invoking the API. If it is not set, API key header name specified in tenant or system level will be used. ")
@ApiModelProperty(example = "ApiKey", value = "Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. ")
@JsonProperty("apiKeyHeader")
public String getApiKeyHeader() {
return apiKeyHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3852,8 +3852,7 @@ components:
apiKeyHeader:
type: string
description: |
Name of the API key header used for invoking the API. If it is not set, API key header name specified
in tenant or system level will be used.
Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used.
example: ApiKey
securityScheme:
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4223,8 +4223,7 @@ definitions:
apiKeyHeader:
type: string
description: |
Name of the API key header used for invoking the API. If it is not set, API key header name specified
in tenant or system level will be used.
Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used.
example: ApiKey
securityScheme:
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,6 @@
<!--Authorization header-->
<AuthorizationHeader>{{apim.oauth_config.auth_header}}</AuthorizationHeader>
{% endif %}
{% if apim.oauth_config.api_key_header is defined %}
<!--API key header-->
<ApiKeyHeader>{{apim.oauth_config.api_key_header}}</ApiKeyHeader>
{% endif %}
<!-- Scope used for marking Application Tokens. If a token is generated with this scope, they will be treated as Application Access Tokens -->
<ApplicationTokenScope>{{apim.oauth_config.default_app_scope}}</ApplicationTokenScope>
<!-- All scopes under the AllowedScopes element are not validating against roles that has assigned to it.
Expand Down

0 comments on commit bb45427

Please sign in to comment.