Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Commit bd7af3c

Browse files
committed
Improving and developing the GUI
1 parent 149b189 commit bd7af3c

22 files changed

+2291
-522
lines changed

src/main/java/pl/simplemethod/codebin/githubOauth/GithubClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected org.json.JSONObject getReposInfo(String token, String username, Strin
109109
* @param token Token for authorization
110110
* @return Json object with data
111111
*/
112-
protected String getUserRepos(String token) {
112+
protected String getUserRepos(String token) {
113113
org.json.JSONObject body = new org.json.JSONObject();
114114
try {
115115
HttpResponse<JsonNode> userReposInfo = Unirest.get("https://api.github.com/user/repos").header("accept", "application/json").header("Authorization", "Bearer " + token).header("Content-Type", "application/json").asJson();

src/main/java/pl/simplemethod/codebin/githubOauth/GithubRestController.java

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pl.simplemethod.codebin.githubOauth;
22

33

4+
import org.json.simple.parser.JSONParser;
5+
import org.json.simple.parser.ParseException;
46
import org.springframework.beans.factory.annotation.Autowired;
57
import org.springframework.http.HttpHeaders;
68
import org.springframework.http.HttpStatus;
@@ -31,7 +33,7 @@ public class GithubRestController {
3133
*/
3234
@GetMapping("/repos/{userName}/{repoName}/minimal")
3335
public @ResponseBody
34-
ResponseEntity getReposCloneWithMinimalInfo(@CookieValue("token") String token,@PathVariable(value="userName") String username, @PathVariable(value="repoName") String repos) {
36+
ResponseEntity getReposCloneWithMinimalInfo(@CookieValue("token") String token, @PathVariable(value = "userName") String username, @PathVariable(value = "repoName") String repos) {
3537
HttpHeaders headers = new HttpHeaders();
3638
headers.setContentType(MediaType.APPLICATION_JSON);
3739
return new ResponseEntity<>(githubClient.getCloneReposMinimalInfo(token, username, repos).toString(), headers, HttpStatus.valueOf(200));
@@ -47,22 +49,23 @@ ResponseEntity getReposCloneWithMinimalInfo(@CookieValue("token") String token,@
4749
*/
4850
@GetMapping("/repos/{userName}/{repoName}")
4951
public @ResponseBody
50-
ResponseEntity getReposInfo(@CookieValue("token") String token, @PathVariable(value="userName") String username, @PathVariable(value="repoName") String repos) {
52+
ResponseEntity getReposInfo(@CookieValue("token") String token, @PathVariable(value = "userName") String username, @PathVariable(value = "repoName") String repos) {
5153
HttpHeaders headers = new HttpHeaders();
5254
headers.setContentType(MediaType.APPLICATION_JSON);
5355
return new ResponseEntity<>(githubClient.getReposInfo(token, username, repos).toString(), headers, HttpStatus.valueOf(200));
5456
}
5557

5658
/**
5759
* Statistics contributors in a repository. Does not work for private repositories and requires a double request for working. https://developer.github.com/v3/repos/statistics/
58-
* @param token Token for authorization
59-
* @param username User name
60-
* @param repos Name of the repository
60+
*
61+
* @param token Token for authorization
62+
* @param username User name
63+
* @param repos Name of the repository
6164
* @return Json object with data
6265
*/
6366
@GetMapping("/repos/{userName}/{repoName}/contributors")
6467
public @ResponseBody
65-
ResponseEntity getReposContributorsStatistics(@CookieValue("token") String token, @PathVariable(value="userName") String username, @PathVariable(value="repoName") String repos) {
68+
ResponseEntity getReposContributorsStatistics(@CookieValue("token") String token, @PathVariable(value = "userName") String username, @PathVariable(value = "repoName") String repos) {
6669
HttpHeaders headers = new HttpHeaders();
6770
headers.setContentType(MediaType.APPLICATION_JSON);
6871
return new ResponseEntity<>(githubClient.getReposContributorsStatistics(token, username, repos).toString(), headers, HttpStatus.valueOf(200));
@@ -95,53 +98,49 @@ ResponseEntity getInfoAboutOwner(@CookieValue("token") String token) {
9598
headers.setContentType(MediaType.APPLICATION_JSON);
9699
return new ResponseEntity<>(githubClient.getUserInfo(token).toString(), headers, HttpStatus.valueOf(200));
97100
}
101+
98102
/**
99103
* Returns JSON with user information
100104
*
101-
* @param token Token for authorization
102-
* @param username Username
105+
* @param token Token for authorization
106+
* @param username Username
103107
* @return Json with data
104108
*/
105109
@GetMapping(value = "/users/{userName}")
106110
public @ResponseBody
107-
ResponseEntity getInfoAboutUser(@CookieValue("token") String token, @PathVariable(value="userName") String username) {
111+
ResponseEntity getInfoAboutUser(@CookieValue("token") String token, @PathVariable(value = "userName") String username) {
108112
HttpHeaders headers = new HttpHeaders();
109113
headers.setContentType(MediaType.APPLICATION_JSON);
110-
return new ResponseEntity<>(githubClient.getUserInfo(token,username).toString(), headers, HttpStatus.valueOf(200));
114+
return new ResponseEntity<>(githubClient.getUserInfo(token, username).toString(), headers, HttpStatus.valueOf(200));
111115
}
112116

113117

114-
115118
/**
116119
* Method for verifying if a profile exists
117-
* @param token Token to github authorize
120+
*
121+
* @param token Token to github authorize
118122
* @return Json object
119123
*/
120-
@GetMapping("/checktoken")
124+
@GetMapping("/user/checktoken")
121125
public @ResponseBody
122126
ResponseEntity checkToken(@RequestParam("token") String token) {
123127
HttpHeaders headers = new HttpHeaders();
124128
org.json.JSONObject body = new org.json.JSONObject();
125129
try {
126130
Users users = usersRepository.getFirstByToken(token);
127131
if (users == null) {
128-
body.put("token","errr");
132+
body.put("token", "errr");
129133
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(404));
130-
}
131-
else
132-
{
133-
org.json.JSONObject oauth= githubClient.getUserInfo(token);
134-
try{
134+
} else {
135+
org.json.JSONObject oauth = githubClient.getUserInfo(token);
136+
try {
135137
oauth.get("login");
136-
if( oauth.get("login")!=null)
137-
{
138-
body.put("token",users);
138+
if (oauth.get("login") != null) {
139+
body.put("token", users);
139140
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(200));
140141
}
141-
}
142-
catch (org.json.JSONException e)
143-
{
144-
body.put("token","errr");
142+
} catch (org.json.JSONException e) {
143+
body.put("token", "errr");
145144
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(404));
146145
}
147146

@@ -153,4 +152,49 @@ ResponseEntity checkToken(@RequestParam("token") String token) {
153152
}
154153
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(404));
155154
}
155+
156+
@GetMapping("/user/repos/public")
157+
public @ResponseBody
158+
ResponseEntity getpublicrepos(@CookieValue("token") String token) {
159+
HttpHeaders headers = new HttpHeaders();
160+
JSONParser parser = new JSONParser();
161+
org.json.JSONObject body = new org.json.JSONObject();
162+
org.json.simple.JSONArray result = new org.json.simple.JSONArray();
163+
Object obj = null;
164+
try {
165+
Users users = usersRepository.getFirstByToken(token);
166+
if (users == null) {
167+
body.put("token", "errr");
168+
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(404));
169+
} else {
170+
try {
171+
obj = parser.parse(githubClient.getUserRepos(token));
172+
org.json.simple.JSONArray jsonArray = (org.json.simple.JSONArray) obj;
173+
jsonArray.forEach(item -> {
174+
org.json.simple.JSONObject obj1 = (org.json.simple.JSONObject) item;
175+
176+
if (obj1.get("private").toString().equals("false")) {
177+
org.json.simple.JSONObject helper = new org.json.simple.JSONObject();
178+
helper.put("language", obj1.get("language"));
179+
helper.put("id", obj1.get("id"));
180+
helper.put("license", obj1.get("license"));
181+
helper.put("name", obj1.get("name"));
182+
helper.put("git_url", obj1.get("git_url"));
183+
helper.put("html_url", obj1.get("html_url"));
184+
helper.put("description", obj1.get("description"));
185+
helper.put("created_at", obj1.get("created_at"));
186+
result.add(helper);
187+
}
188+
});
189+
return new ResponseEntity<>(result.toString(), headers, HttpStatus.valueOf(200));
190+
} catch (NullPointerException | ParseException | org.json.JSONException e) {
191+
body.put("token", "errr");
192+
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(404));
193+
}
194+
}
195+
} catch (org.json.JSONException e) {
196+
return new ResponseEntity<>(e, headers, HttpStatus.valueOf(404));
197+
198+
}
199+
}
156200
}

src/main/java/pl/simplemethod/codebin/model/Containers.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,34 @@ public class Containers implements Serializable {
4040

4141
@Column(name = "create_time", nullable = false)
4242
private Long createTime;
43+
@Column(name = "share_url", unique = true, nullable = false)
44+
private String shareUrl;
4345

44-
public Containers(String name, String idDocker, Images image, Integer exposedPorts, Integer hostPorts, Long ramMemory, Long diskQuota, Integer status, Long createTime) {
46+
public Containers(String name, String idDocker, Images image, Integer exposedPorts, Integer hostPorts, Long ramMemory, Long diskQuota, String shareUrl, Integer status, Long createTime) {
4547
this.name = name;
4648
this.idDocker = idDocker;
4749
this.image = image;
4850
this.exposedPorts = exposedPorts;
4951
this.hostPorts = hostPorts;
5052
this.ramMemory = ramMemory;
5153
this.diskQuota = diskQuota;
54+
this.shareUrl = shareUrl;
5255
this.status = status;
5356
this.createTime = createTime;
5457
}
5558

5659
public Containers() {
5760
}
5861

62+
public String getShareUrl() {
63+
return shareUrl;
64+
}
65+
66+
public void setShareUrl(String shareUrl) {
67+
this.shareUrl = shareUrl;
68+
}
69+
70+
5971
public Integer getId() {
6072
return id;
6173
}
@@ -141,14 +153,16 @@ public String toString() {
141153
return "Containers{" +
142154
"id=" + id +
143155
", name='" + name + '\'' +
144-
", docker_id='" + idDocker + '\'' +
156+
", idDocker='" + idDocker + '\'' +
145157
", image=" + image +
146158
", exposedPorts=" + exposedPorts +
147159
", hostPorts=" + hostPorts +
148160
", ramMemory=" + ramMemory +
149161
", diskQuota=" + diskQuota +
150162
", status=" + status +
151163
", createTime=" + createTime +
164+
", shareUrl='" + shareUrl + '\'' +
152165
'}';
153166
}
167+
154168
}

src/main/java/pl/simplemethod/codebin/repository/ContainersRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public interface ContainersRepository extends JpaRepository<Containers, Long> {
1717

1818
Containers getFirstByIdDocker(String dockerId);
1919

20+
Containers getFirstByShareUrl(String shareURL);
21+
2022
List<Containers> getByHostPorts(Integer ports);
2123

2224
List<Containers> getByIdDocker(String dockerId);

src/main/java/pl/simplemethod/codebin/srv/SrvRestController.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.http.MediaType;
88
import org.springframework.http.ResponseEntity;
99
import org.springframework.web.bind.annotation.*;
10+
import pl.simplemethod.codebin.linkDeploy.LinkClient;
1011
import pl.simplemethod.codebin.model.Containers;
1112
import pl.simplemethod.codebin.model.Images;
1213
import pl.simplemethod.codebin.repository.ContainersRepository;
@@ -21,29 +22,32 @@
2122
public class SrvRestController {
2223

2324
@Autowired
24-
SrvClient srvClient;
25+
private SrvClient srvClient;
2526

2627
@Autowired
2728
private ImagesRepository imagesRepository;
2829

2930
@Autowired
3031
private ContainersRepository containersRepository;
3132

33+
@Autowired
34+
private LinkClient linkClient;
3235

33-
34-
@GetMapping("/images1")
36+
/*
37+
@GetMapping("/createtest")
3538
public @ResponseBody
3639
ResponseEntity kek() {
3740
3841
List<Containers> containers = new ArrayList<>();
39-
Images images = imagesRepository.getFirstByName("sdssd");
40-
containers.add(new Containers("test","xddd",images,1010,4510,(long)1000,(long)1000,1, Instant.now().getEpochSecond()));
42+
Images images = imagesRepository.getFirstByName("java");
43+
containers.add(new Containers("test","test",images,1010,4510,(long)1000,(long)1000,1, Instant.now().getEpochSecond()));
4144
containers.forEach(containersRepository::save);
4245
4346
HttpHeaders headers = new HttpHeaders();
4447
return new ResponseEntity<>("xd", headers, HttpStatus.valueOf(200));
4548
}
4649
50+
*/
4751

4852
/**
4953
* REST for container creation
@@ -56,7 +60,7 @@ ResponseEntity kek() {
5660
* @param diskQuota Maximum amount of allocated memory on the disk
5761
* @return Json object with data
5862
*/
59-
@GetMapping("container/create")
63+
@PostMapping("container/create")
6064
public @ResponseBody
6165
ResponseEntity createContainer(@RequestParam("dockerimage") String dockerImage, @RequestParam("exposedports") Integer exposedPorts, @RequestParam("hostports") Integer hostPorts, @RequestParam("name") String name, @RequestParam("rammemory") Long ramMemory, @RequestParam("diskquota") Long diskQuota) {
6266
HttpHeaders headers = new HttpHeaders();
@@ -66,8 +70,8 @@ ResponseEntity createContainer(@RequestParam("dockerimage") String dockerImage,
6670
if (response.get("status").toString().equals("204")) {
6771
status = 200;
6872
List<Containers> containers = new ArrayList<>();
69-
Images images = imagesRepository.getFirstByName(dockerImage);
70-
containers.add(new Containers(name,response.get("id").toString(),images,exposedPorts,hostPorts,ramMemory,diskQuota,1, Instant.now().getEpochSecond()));
73+
Images images = imagesRepository.getFirstByName(dockerImage);
74+
containers.add(new Containers(name, response.get("id").toString(), images, exposedPorts, hostPorts, ramMemory, diskQuota, linkClient.encrypt(String.valueOf(hostPorts)), 1, Instant.now().getEpochSecond()));
7175
containers.forEach(containersRepository::save);
7276
} else {
7377
status = Integer.valueOf(response.get("status").toString());

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spring.jmx.unique-names=true
1010
spring.security.oauth2.client.registration.github.client-id=2f5c2010372081b036ff
1111
spring.security.oauth2.client.registration.github.client-secret=29e08d58c97f1448d3bd16f2ac10e5541be53937
1212
spring.security.oauth2.client.registration.github.scope=read:user,user:email,repo
13-
spring.security.oauth2.client.registration.github.redirect-uri=http://localhost/postlogin
13+
spring.security.oauth2.client.registration.github.redirect-uri=http://127.0.0.1/postlogin
1414

1515
#---------------------------------------------------
1616
# THYMELEAF PROPERTIES

0 commit comments

Comments
 (0)