Skip to content

Commit

Permalink
JEN-178:CutUserKeyFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
zmicer committed Sep 27, 2016
1 parent df918ad commit 3c2f5b6
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 55 deletions.
Expand Up @@ -44,7 +44,7 @@ public BlazemeterCredentialImpl(String id, String apiKey,String description) {

public String getId() {
if (super.getId() == null) {
return StringUtils.left(apiKey, 4) + Constants.CREDENTIALS_KEY + StringUtils.right(apiKey, 4);
return StringUtils.left(apiKey, 4) + Constants.THREE_DOTS + StringUtils.right(apiKey, 4);
} else {
return super.getId();
}
Expand Down
@@ -0,0 +1,35 @@
/**
Copyright 2016 BlazeMeter Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package hudson.plugins.blazemeter.api;

import hudson.plugins.blazemeter.utils.Constants;
import org.apache.commons.lang.StringUtils;

import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;

public class CutUserKeyFormatter extends SimpleFormatter {

@Override
public synchronized String format(LogRecord record) {
String logEntry=super.format(record);
int apiKey=logEntry.lastIndexOf("api_key");
if(apiKey>0){
String keyToReplace=logEntry.substring(apiKey+13,apiKey+28);
return StringUtils.replace(logEntry,keyToReplace, Constants.THREE_DOTS);
}
return logEntry;
}
}
19 changes: 15 additions & 4 deletions src/main/java/hudson/plugins/blazemeter/api/HttpLogger.java
@@ -1,3 +1,17 @@
/**
Copyright 2016 BlazeMeter Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package hudson.plugins.blazemeter.api;

import hudson.plugins.blazemeter.utils.Constants;
Expand All @@ -8,9 +22,6 @@
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
* Created by zmicer on 22.9.16.
*/
public class HttpLogger implements HttpLoggingInterceptor.Logger {

private Logger httpLog=Logger.getLogger(Constants.HTTP_LOG);
Expand All @@ -22,7 +33,7 @@ public HttpLogger(String httpLog_f){
} catch (IOException e) {
e.printStackTrace();
}
http_lfh.setFormatter(new SimpleFormatter());
http_lfh.setFormatter(new CutUserKeyFormatter());
httpLog.addHandler(http_lfh);
httpLog.setUseParentHandlers(false);

Expand Down
Expand Up @@ -26,6 +26,7 @@ public interface UrlManager {
String TESTS="/tests";
String MASTERS="/masters";
String WEB="/web";
String CI_STATUS="/ci-status";
String getServerUrl();

void setServerUrl(String serverUrl);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public String masterStatus(String appKey, String userKey, String masterId) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
testStatus= serverUrl +LATEST+"/masters/"+masterId+"/status?events=false&api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;
testStatus= serverUrl +LATEST+UrlManager.MASTERS+"/"+masterId+"/status?events=false&api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;
return testStatus;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public String testStop(String appKey, String userKey, String masterId) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
testStop= serverUrl +LATEST+"/masters/"
testStop= serverUrl +LATEST+UrlManager.MASTERS+"/"
+masterId+"/stop?api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;

return testStop;
Expand All @@ -116,7 +116,7 @@ public String testTerminate(String appKey, String userKey, String masterId) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
testTerminate= serverUrl +LATEST+"/masters/"
testTerminate= serverUrl +LATEST+UrlManager.MASTERS+"/"
+masterId+"/terminate?api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;

return testTerminate;
Expand All @@ -132,7 +132,7 @@ public String testReport(String appKey, String userKey, String masterId) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
testAggregateReport= serverUrl +LATEST+"/masters/"
testAggregateReport= serverUrl +LATEST+UrlManager.MASTERS+"/"
+masterId+"/reports/main/summary?api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;

return testAggregateReport;
Expand Down Expand Up @@ -190,7 +190,7 @@ public String getCIStatus(String appKey, String userKey, String masterId){
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
getTresholds= serverUrl +LATEST+MASTERS+"/"+masterId+"/ci-status?api_key="
getTresholds= serverUrl +LATEST+MASTERS+"/"+masterId+UrlManager.CI_STATUS+"?api_key="
+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;

return getTresholds;
Expand Down Expand Up @@ -313,7 +313,7 @@ public String masterId(String appKey,String userKey,String masterId) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return masterIdUrl= serverUrl +LATEST+"/masters/"+masterId+"?api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;
return masterIdUrl= serverUrl +LATEST+UrlManager.MASTERS+"/"+masterId+"?api_key="+userKey+"&app_key="+appKey+ CLIENT_IDENTIFICATION;
}

@Override
Expand Down
Expand Up @@ -22,7 +22,7 @@ public interface Constants {
String BM_KPIS="bm-kpis.jtl";
String BM_ARTEFACTS="-bm-artefacts";
String VERSION="version";
String CREDENTIALS_KEY="...";
String THREE_DOTS ="...";
String NO_API_KEY="No API Key";
String UNKNOWN_TYPE="unknown_type";
String API_KEY_EMPTY ="API key is empty: please, enter valid API key";
Expand Down

0 comments on commit 3c2f5b6

Please sign in to comment.