Skip to content

Commit

Permalink
fix: rationalize API Key spelling and casing
Browse files Browse the repository at this point in the history
  • Loading branch information
jgiovaresco committed Jul 13, 2023
1 parent 5ec49d5 commit 896140b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= API key policy
= API Key policy

ifdef::env-github[]
image:https://img.shields.io/static/v1?label=Available%20at&message=Gravitee.io&color=1EC9D2["Gravitee.io", link="https://download.gravitee.io/#graviteeio-apim/plugins/policies/gravitee-policy-apikey/"]
Expand All @@ -21,10 +21,10 @@ endif::[]

== Description

You can use the `api-key` policy to enforce API key checks during request processing, allowing only apps with approved API
You can use the `api-key` policy to enforce API Key checks during request processing, allowing only apps with approved API
keys to access your APIs.

This policy ensures that API keys are valid, have not been revoked or expired and are approved to consume the specific
This policy ensures that API Keys are valid, have not been revoked or expired and are approved to consume the specific
resources associated with your API.

== Configuration
Expand All @@ -37,7 +37,7 @@ You can configure the following policy level options:

.^|`propagateApiKey`
^.^|-
|Propagate API key to upstream API
|Propagate API Key to upstream API
^.^|boolean
^.^|_false_

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/gravitee/policy/apikey/ApiKeyPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Maybe<SecurityToken> extractSecurityToken(HttpExecutionContext ctx) {

/**
* {@inheritDoc}
* Validate the subscription, as a valid shared API key can be linked to a closed or expired subscription.
* Validate the subscription, as a valid shared API Key can be linked to a closed or expired subscription.
*
* @return <code>true</code>, indicating that the subscription must be validated.
*/
Expand Down Expand Up @@ -108,7 +108,7 @@ private Completable handleSecurity(final HttpExecutionContext ctx) {
Optional<String> requestApiKey = extractApiKey(ctx);

if (requestApiKey.isEmpty()) {
// The api key is required
// The API Key is required
return interrupt401(ctx, API_KEY_MISSING_KEY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onRequest(Request request, Response response, ExecutionContext execu
String requestApiKey = lookForApiKey(executionContext, request);

if (requestApiKey == null || requestApiKey.isEmpty()) {
// The api key is required
// The API Key is required
policyChain.failWith(PolicyResult.failure(API_KEY_MISSING_KEY, HttpStatusCode.UNAUTHORIZED_401, API_KEY_UNAUTHORIZED_MESSAGE));
} else {
final String apiId = (String) executionContext.getAttribute(ExecutionContext.ATTR_API);
Expand All @@ -81,13 +81,13 @@ public void onRequest(Request request, Response response, ExecutionContext execu
if (!apiKey.isRevoked() && (apiKey.getExpireAt() == null || apiKey.getExpireAt().after(new Date(request.timestamp())))) {
policyChain.doNext(request, response);
} else {
// The api key is not valid
// The API Key is not valid
policyChain.failWith(
PolicyResult.failure(API_KEY_INVALID_KEY, HttpStatusCode.UNAUTHORIZED_401, API_KEY_UNAUTHORIZED_MESSAGE)
);
}
} else {
// The api key does not exist
// The API Key does not exist
policyChain.failWith(
PolicyResult.failure(API_KEY_INVALID_KEY, HttpStatusCode.UNAUTHORIZED_401, API_KEY_UNAUTHORIZED_MESSAGE)
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id=api-key
name=Api Key
name=API Key
version=${project.version}
description=${project.description}
class=io.gravitee.policy.apikey.ApiKeyPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void init() {
lenient().when(ctx.request()).thenReturn(request);
lenient().when(request.timestamp()).thenReturn(System.currentTimeMillis());

// Initialize default header and query param names to get api key from.
// Initialize default header and query param names to get API Key from.
initializeParamNames(DEFAULT_API_KEY_HEADER_PARAMETER, DEFAULT_API_KEY_QUERY_PARAMETER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void shouldGet401IfEmptyApiKey(HttpClient client) throws InterruptedException {
}

@Test
@DisplayName("Should receive 401 - Unauthorized when calling with an API key, without subscription")
@DisplayName("Should receive 401 - Unauthorized when calling with an API Key, without subscription")
void shouldGet401IfNoSubscription(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

Expand Down Expand Up @@ -148,7 +148,7 @@ void shouldGet401IfNoSubscription(HttpClient client) throws InterruptedException
}

@Test
@DisplayName("Should receive 401 - Unauthorized when calling with an API key, with expired subscription")
@DisplayName("Should receive 401 - Unauthorized when calling with an API Key, with expired subscription")
void shouldGet401IfExpiredSubscription(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/apis/api-key.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"pre": [
{
"name": "Api Key",
"name": "API Key",
"description": "",
"enabled": true,
"policy": "api-key",
Expand Down

0 comments on commit 896140b

Please sign in to comment.