Skip to content

Commit

Permalink
Fixed #51 (Deprecated GitHub API password auth)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdolif committed Oct 12, 2020
1 parent 31d77b2 commit facaf7b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ The las2peer port is fixed at *9011*.
| WIDGET_HOME_BASE_URL | http://role:8086/ |
| OIDC_PROVIDER | https://api.learning-layers.eu/o/oauth2 |

The TOKEN should be a personal access token of a GitHub user account which has access to create new repositories in the git organization used to host the components created with the CAE.

### Other Variables

| Variable | Default | Description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public CodeGenerationService() throws GitHostException {

// Create git adapter matching the usedGitHost
if (Objects.equals(usedGitHost, "GitHub")) {
gitAdapter = new GitHubAdapter(gitUser, gitPassword, gitOrganization, templateRepository, gitUserMail);
gitAdapter = new GitHubAdapter(gitUser, gitPassword, token, gitOrganization, templateRepository, gitUserMail);
} else if (Objects.equals(usedGitHost, "GitLab")) {
gitAdapter = new GitLabAdapter(baseURL, token, gitUser, gitPassword, gitOrganization, templateRepository,
gitUserMail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,48 @@ public abstract class BaseGitHostAdapter implements GitHostAdapter {
//TODO: Exception handling

// Basic (unspecific) git service properties
protected String gitUser;
protected String gitUser;
protected String gitPassword;
protected String token;
protected String gitOrganization;
protected String templateRepository;
protected String gitUserMail;

protected String baseURL = "";

protected BaseGitHostAdapter(String gitUser, String gitPassword, String gitOrganization, String templateRepository,
String gitUserMail, String baseURL) throws GitHostException {
protected BaseGitHostAdapter(String gitUser, String gitPassword, String token, String gitOrganization,
String templateRepository, String gitUserMail, String baseURL) throws GitHostException {
super();
this.gitUser = gitUser;
this.gitPassword = gitPassword;
this.token = token;
this.gitOrganization = gitOrganization;
this.templateRepository = templateRepository;
this.gitUserMail = gitUserMail;
this.baseURL = baseURL;

if(gitUser.isEmpty() ||
gitPassword.isEmpty() ||
token.isEmpty() ||
gitOrganization.isEmpty() ||
templateRepository.isEmpty() ||
gitUserMail.isEmpty()) {
throw new GitHostException("Not all required properties are set");
}
}

public String getGitUser() {
return gitUser;
}

public String getGitPassword() {
return gitPassword;
}

public String getToken() {
return token;
}

public String getGitOrganization() {
return gitOrganization;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
public class GitHubAdapter extends BaseGitHostAdapter {
//TODO: Exception handling

private GitHubAdapter(String gitUser, String gitPassword, String gitOrganization, String templateRepository,
String gitUserMail, String baseURL) throws GitHostException {
super(gitUser, gitPassword, gitOrganization, templateRepository, gitUserMail, baseURL);
private GitHubAdapter(String gitUser, String gitPassword, String personalAccessToken, String gitOrganization,
String templateRepository, String gitUserMail, String baseURL) throws GitHostException {
super(gitUser, gitPassword, personalAccessToken, gitOrganization, templateRepository, gitUserMail, baseURL);
}

public GitHubAdapter(String gitUser, String gitPassword, String gitOrganization, String templateRepository,
String gitUserMail) throws GitHostException {
this(gitUser,gitPassword,gitOrganization,templateRepository,gitUserMail,"https://github.com/");
public GitHubAdapter(String gitUser, String gitPassword, String personalAccessToken, String gitOrganization,
String templateRepository, String gitUserMail) throws GitHostException {
this(gitUser, gitPassword, personalAccessToken, gitOrganization, templateRepository, gitUserMail, "https://github.com/");
}

/**
Expand All @@ -44,7 +44,7 @@ public void createRepo(String name, String description) throws GitHostException
jsonObject.put("description", description);
String body = JSONObject.toJSONString(jsonObject);

String authString = this.gitUser + ":" + this.gitPassword;
String authString = this.getToken();

byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
String authStringEnc;
Expand Down Expand Up @@ -95,7 +95,7 @@ public void createRepo(String name, String description) throws GitHostException
*/
@Override
public void deleteRepo(String name) throws GitHostException {
String authString = this.gitUser + ":" + this.gitPassword;
String authString = this.getToken();
byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
String authStringEnc = new String(authEncBytes);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
*/
public class GitLabAdapter extends BaseGitHostAdapter{
//TODO: Exception handling

private String token;

public GitLabAdapter(String baseURL, String token, String gitUser, String gitPassword, String gitOrganization,
public GitLabAdapter(String baseURL, String token, String gitUser, String gitPassword, String gitOrganization,
String templateRepository, String gitUserMail) throws GitHostException {
super(gitUser, gitPassword, gitOrganization, templateRepository, gitUserMail, baseURL);
this.token = token;

super(gitUser, gitPassword, token, gitOrganization, templateRepository, gitUserMail, baseURL);
}

/**
Expand Down

0 comments on commit facaf7b

Please sign in to comment.