Move gist username password to config file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package de.jeyp91.gists;
|
||||
|
||||
import com.google.api.client.util.DateTime;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpResponse;
|
||||
@@ -18,16 +19,37 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Set;
|
||||
|
||||
public class GistProvider {
|
||||
|
||||
private static GistProvider prov = null;
|
||||
private JSONArray gistList = null;
|
||||
private JSONArray gistList;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
private GistProvider() {
|
||||
this.gistList = listAllGists();
|
||||
readConfig();
|
||||
}
|
||||
|
||||
private void readConfig() {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource("Gist_Config.json");
|
||||
JSONObject gistConfig;
|
||||
|
||||
try {
|
||||
String jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
//Read JSON file
|
||||
gistConfig = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
this.username = gistConfig.get("username").toString();
|
||||
this.password = gistConfig.get("password").toString();
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static GistProvider getInstance() {
|
||||
@@ -68,9 +90,7 @@ public class GistProvider {
|
||||
|
||||
public String updateGist(String id, String file, String content) throws UnsupportedEncodingException {
|
||||
String requestUrl = "https://api.github.com/gists/" + id;
|
||||
String username = "tippligawuerzburg";
|
||||
String password = "1154f448eae29212971cb82ca8850f54bff23629";
|
||||
String auth = username + ":" + password;
|
||||
String auth = this.username + ":" + this.password;
|
||||
byte[] encodedAuth = Base64.encodeBase64(
|
||||
auth.getBytes(StandardCharsets.ISO_8859_1));
|
||||
String authHeader = "Basic " + new String(encodedAuth);
|
||||
@@ -157,9 +177,7 @@ public class GistProvider {
|
||||
|
||||
private String getRawData(String requestUrl) {
|
||||
|
||||
String username = "tippligawuerzburg";
|
||||
String password = "1154f448eae29212971cb82ca8850f54bff23629";
|
||||
String auth = username + ":" + password;
|
||||
String auth = this.username + ":" + this.password;
|
||||
byte[] encodedAuth = Base64.encodeBase64(
|
||||
auth.getBytes(StandardCharsets.ISO_8859_1));
|
||||
String authHeader = "Basic " + new String(encodedAuth);
|
||||
|
||||
4
src/main/resources/Gist_Config.json
Normal file
4
src/main/resources/Gist_Config.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"username": "tippligawuerzburg",
|
||||
"password": "1154f448eae29212971cb82ca8850f54bff23629"
|
||||
}
|
||||
Reference in New Issue
Block a user