use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class GitTagsetHandlerTest method tearDown.
@After
public void tearDown() throws Exception {
if (this.directoriesToDeleteOnTearDown.size() > 0) {
for (File dir : this.directoriesToDeleteOnTearDown) {
FileUtils.deleteDirectory(dir);
}
this.directoriesToDeleteOnTearDown.clear();
}
if (this.tagsetReposToDeleteOnTearDown.size() > 0) {
for (String tagsetId : this.tagsetReposToDeleteOnTearDown) {
String tagsetRepoName = GitTagsetHandler.getTagsetRepositoryName(tagsetId);
List<Project> projects = this.gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects(tagsetRepoName);
// this getProjects overload does a search
for (Project project : projects) {
this.gitLabServerManager.deleteRepository(project.getId());
}
await().until(() -> this.gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects().isEmpty());
}
this.tagsetReposToDeleteOnTearDown.clear();
}
if (this.projectsToDeleteOnTearDown.size() > 0) {
GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
for (String projectId : this.projectsToDeleteOnTearDown) {
gitProjectHandler.delete(projectId);
}
this.projectsToDeleteOnTearDown.clear();
}
// delete the GitLab user that the GitLabServerManager constructor in setUp would have
// created - see GitLabServerManagerTest tearDown() for more info
User user = this.gitLabServerManager.getGitLabUser();
this.gitLabServerManager.getAdminGitLabApi().getUserApi().deleteUser(user.getId());
GitLabServerManagerTest.awaitUserDeleted(this.gitLabServerManager.getAdminGitLabApi().getUserApi(), user.getId());
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class GitLabServerManagerTest method createUser.
@Test
public void createUser() throws Exception {
Integer createdUserId = this.serverManager.createUser("testuser@catma.de", "testuser", null, "Test User", null);
this.usersToDeleteOnTearDown.add(createdUserId);
assertNotNull(createdUserId);
assert createdUserId > 0;
User user = this.serverManager.getAdminGitLabApi().getUserApi().getUser(createdUserId);
assertNotNull(user);
assertEquals("testuser@catma.de", user.getEmail());
assertEquals("testuser", user.getUsername());
assertEquals("Test User", user.getName());
// assertFalse(user.getIsAdmin()); // seems to always return null
assert user.getCanCreateGroup();
assert user.getCanCreateProject();
assertEquals("active", user.getState());
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class JGitRepoManagerTest method pushToGitLabRepoWithAuthentication.
@Test
public void pushToGitLabRepoWithAuthentication() throws Exception {
GitLabServerManager gitLabServerManager = new GitLabServerManager(UserIdentification.userToMap(this.catmaUser.getIdentifier()));
// create a repository
IRemoteGitServerManager.CreateRepositoryResponse createRepositoryResponse = gitLabServerManager.createRepository(Randomizer.getRepoName(), null);
try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
// clone it
String repoName = jGitRepoManager.clone("", createRepositoryResponse.repositoryHttpUrl, null, gitLabServerManager.getUsername(), gitLabServerManager.getPassword());
File testRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), repoName);
assert testRepoPath.exists();
assert testRepoPath.isDirectory();
// can't call open on an attached instance
jGitRepoManager.detach();
// open the cloned repo, add and commit a file, then push
jGitRepoManager.open("", testRepoPath.getName());
File originalSourceDocument = new File("testdocs/rose_for_emily.pdf");
byte[] originalSourceDocumentBytes = Files.readAllBytes(originalSourceDocument.toPath());
File targetFile = new File(testRepoPath, originalSourceDocument.getName());
jGitRepoManager.addAndCommit(targetFile, originalSourceDocumentBytes, "Test Committer", "testcommitter@catma.de");
jGitRepoManager.push(gitLabServerManager.getUsername(), gitLabServerManager.getPassword());
// assert that the push worked by looking at the commits on the server
CommitsApi commitsApi = gitLabServerManager.getUserGitLabApi().getCommitsApi();
List<Commit> commits = commitsApi.getCommits(createRepositoryResponse.repositoryId);
assertEquals(1, commits.size());
assertEquals("Adding rose_for_emily.pdf", commits.get(0).getMessage());
// cleanup (these are not handled by tearDown)
gitLabServerManager.deleteRepository(createRepositoryResponse.repositoryId);
await().until(() -> gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects().isEmpty());
// see GitLabServerManagerTest tearDown() for more info
User user = gitLabServerManager.getGitLabUser();
gitLabServerManager.getAdminGitLabApi().getUserApi().deleteUser(user.getId());
GitLabServerManagerTest.awaitUserDeleted(gitLabServerManager.getAdminGitLabApi().getUserApi(), user.getId());
}
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class GitlabManagerPrivileged method acquireImpersonationToken.
@Override
public Pair<GitUser, String> acquireImpersonationToken(String identifier, String provider, String email, String name) throws IOException {
User user = this.acquireUser(identifier, provider, email, name);
UserApi customUserApi = this.privilegedGitLabApi.getUserApi();
try {
List<PersonalAccessToken> impersonationTokens = customUserApi.getImpersonationTokens(user.getId(), ImpersonationState.ACTIVE);
// revoke the default token if it exists actively
for (PersonalAccessToken token : impersonationTokens) {
if (token.getName().equals(GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME)) {
privilegedGitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());
break;
}
}
} catch (GitLabApiException e) {
throw new IOException("Failed to revoke existing impersonation token", e);
}
String impersonationToken = this.createImpersonationToken(user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
if (impersonationToken == null) {
String errorMessage = String.format("Failed to acquire impersonation token for CATMA with identifier `%s`. " + "The creation of the token the associated GitLab user ID `%s` failed, no " + "active impersonation token called `%s` can be found!", identifier, user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
throw new IOException(errorMessage);
}
Pair<GitUser, String> retVal = new Pair<>(new GitUser(user), impersonationToken);
return retVal;
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class GitlabManagerPrivileged method setTermsOfUseConsentGiven.
public void setTermsOfUseConsentGiven(de.catma.user.User catmaUser, boolean value) {
try {
UserApi userApi = privilegedGitLabApi.getUserApi();
User user = userApi.getUser(catmaUser.getUserId());
Optional<CustomAttribute> optionalAttribute = Optional.empty();
if (user.getCustomAttributes() != null) {
optionalAttribute = user.getCustomAttributes().stream().filter(attr -> attr.getKey().equals(CustomAttributeName.terms_of_use_consent_given.name())).findFirst();
}
CustomAttribute attr = optionalAttribute.orElse(new CustomAttribute().withKey(CustomAttributeName.terms_of_use_consent_given.name()).withValue(Boolean.FALSE.toString()));
attr.setValue(Boolean.valueOf(value).toString());
userApi.changeCustomAttribute(user.getId(), attr);
} catch (GitLabApiException e) {
logger.log(Level.SEVERE, "Could access custom attributes", e);
}
}
Aggregations