Add git token (code + config)
This commit is contained in:
parent
24dc025507
commit
4df8f2a37b
3 changed files with 47 additions and 43 deletions
|
@ -30,23 +30,23 @@ public class Configuration {
|
|||
private int groupJoinMinutes;
|
||||
private String groupQuitMinutes;
|
||||
|
||||
private File file;
|
||||
private String git_token;
|
||||
|
||||
private File _file;
|
||||
|
||||
public Configuration(String path){
|
||||
this.file = new File(path);
|
||||
System.out.println("Config on " + file.getAbsolutePath());
|
||||
this._file = new File(path);
|
||||
System.out.println("Config on " + _file.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void load() throws Exception{
|
||||
if (!this.file.exists())
|
||||
return;
|
||||
BufferedReader reader = new BufferedReader(new FileReader(this.file));
|
||||
if(!this._file.exists()) return;
|
||||
BufferedReader reader = new BufferedReader(new FileReader(this._file));
|
||||
String line;
|
||||
while((line = reader.readLine()) != null){
|
||||
String[] split = line.split("=");
|
||||
Field field = getClass().getDeclaredField(split[0]);
|
||||
if (field == null)
|
||||
continue;
|
||||
if(field == null) continue;
|
||||
field.setAccessible(true);
|
||||
injectValue(field, split[1]);
|
||||
}
|
||||
|
@ -93,18 +93,16 @@ public class Configuration {
|
|||
}
|
||||
|
||||
public void save() throws Exception{
|
||||
if (!file.exists()) {
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.exists())
|
||||
parent.mkdirs();
|
||||
file.createNewFile();
|
||||
if(!_file.exists()){
|
||||
File parent = _file.getParentFile();
|
||||
if(!parent.exists()) parent.mkdirs();
|
||||
_file.createNewFile();
|
||||
}
|
||||
Field[] fields = getClass().getDeclaredFields();
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(_file));
|
||||
for(Field field : fields){
|
||||
field.setAccessible(true);
|
||||
if (field.getName().startsWith("_"))
|
||||
continue;
|
||||
if(field.getName().startsWith("_")) continue;
|
||||
Object value = field.get(this);
|
||||
writer.write(field.getName() + "=" + value);
|
||||
}
|
||||
|
@ -157,8 +155,7 @@ public class Configuration {
|
|||
}
|
||||
|
||||
public String getUsersFiles(){
|
||||
if (users_files == null || users_files.trim().isEmpty())
|
||||
users_files = "/tmp/users_files";
|
||||
if(users_files == null || users_files.trim().isEmpty()) users_files = "/tmp/users_files";
|
||||
return users_files;
|
||||
}
|
||||
|
||||
|
@ -173,4 +170,8 @@ public class Configuration {
|
|||
public String getGroupQuitMinutes(){
|
||||
return this.groupQuitMinutes;
|
||||
}
|
||||
|
||||
public String getGitToken(){
|
||||
return this.git_token;
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ public class Main{
|
|||
|
||||
private static void initRoutes(Router router, Configuration config){
|
||||
DatabaseRepository repo = router.getDataBase();
|
||||
router.register(new Register(repo, router, config.getUsersFiles()));
|
||||
router.register(new Register(repo, router, config.getUsersFiles(), config.getGitToken()));
|
||||
router.register(new Login(repo, router));
|
||||
router.register(new ProfileSettings(repo));
|
||||
router.register(new ChangePassword(repo));
|
||||
|
|
|
@ -36,11 +36,13 @@ public class Register extends FormResponse {
|
|||
private String usersFilesPath;
|
||||
private KeyPairGenerator generator;
|
||||
private Encoder encoder;
|
||||
private String gitToken;
|
||||
|
||||
public Register(DatabaseRepository databaseRepo, Router router, String initUsersFilesPath) {
|
||||
public Register(DatabaseRepository databaseRepo, Router router, String initUsersFilesPath, String gitToken){
|
||||
this.databaseRepo = databaseRepo;
|
||||
this.router = router;
|
||||
usersFilesPath = initUsersFilesPath;
|
||||
this.usersFilesPath = initUsersFilesPath;
|
||||
this.gitToken = gitToken;
|
||||
try {
|
||||
generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(2048); //a changer ?
|
||||
|
@ -120,6 +122,7 @@ public class Register extends FormResponse {
|
|||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type","application/json");
|
||||
connection.setRequestProperty("Authorization","Bearer "+this.gitToken);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue