package com.perforce.hwsclient.auth; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import com.squareup.okhttp.Interceptor; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; public class ApiKeyAuth implements Interceptor { private final String location; private final String paramName; private String apiKey; public ApiKeyAuth(String location, String paramName) { this.location = location; this.paramName = paramName; } public String getLocation() { return location; } public String getParamName() { return paramName; } public String getApiKey() { return apiKey; } public void setApiKey(String apiKey) { this.apiKey = apiKey; } @Override public Response intercept(Chain chain) throws IOException { String paramValue; Request request = chain.request(); if (location == "query") { String newQuery = request.uri().getQuery(); paramValue = paramName + "=" + apiKey; if (newQuery == null) { newQuery = paramValue; } else { newQuery += "&" + paramValue; } URI newUri; try { newUri = new URI(request.uri().getScheme(), request.uri().getAuthority(), request.uri().getPath(), newQuery, request.uri().getFragment()); } catch (URISyntaxException e) { throw new IOException(e); } request = request.newBuilder().url(newUri.toURL()).build(); } else if (location == "header") { request = request.newBuilder() .addHeader(paramName, apiKey) .build(); } return chain.proceed(request); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/java/src/main/java/com/perforce/hwsclient/auth/ApiKeyAuth.java | |||||
#1 | 19535 | drobins | Refactor package names to hws | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/java/src/main/java/com/perforce/helix_web_services_client/auth/ApiKeyAuth.java | |||||
#1 | 18795 | tjuricek | Use point-release versioning for the client SDKs and installers. | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1/java/src/main/java/com/perforce/helix_web_services_client/auth/ApiKeyAuth.java | |||||
#1 | 18679 | tjuricek |
Revising HWS paths to work primarily at product version 2016.1. The swagger definitions will primarily work at a major platform release number. We will generate new clients for each major release, and ensure backwards compatibility as time goes on by keeping the older clients around in the tree. Note: These are JUST URLs, and do not include other revisions we plan on making shortly. |
||
//guest/perforce_software/helix-web-services/main/source/clients/java/src/main/java/com/perforce/helix_web_services_client/auth/ApiKeyAuth.java | |||||
#2 | 18515 | tjuricek |
Replacing java_client with Swagger-based clients/java project. - Switched implementations of the Swagger client to use okhttp with gson. - Added the version to the "status" method, and hey, added that method to the spec - Added templates to the java code generator to add some default methods, fixing some import issues in Gradle NOTE: We may want to break down the API a bit and restructure it. |
||
#1 | 18488 | tjuricek |
Swagger Java client (initial version). This contains a basic configuration for the java client, which mostly decides package location, etc. Notably, the license must be ASL under the SmartBear copyright. |