use of org.gitlab4j.api.UserApi in project catma by forTEXT.
the class GitLabServerManagerTest method tearDown.
@AfterEach
public void tearDown() throws Exception {
GitLabApi adminGitLabApi = gitlabManagerPrivileged.getGitLabApi();
GroupApi groupApi = adminGitLabApi.getGroupApi();
ProjectApi projectApi = adminGitLabApi.getProjectApi();
UserApi userApi = adminGitLabApi.getUserApi();
if (groupsToDeleteOnTearDown.size() > 0) {
for (String groupPath : groupsToDeleteOnTearDown) {
gitlabManagerRestricted.deleteGroup(groupPath);
await().until(() -> groupApi.getGroups().isEmpty());
}
}
if (repositoriesToDeleteOnTearDown.size() > 0) {
for (Integer repositoryId : repositoriesToDeleteOnTearDown) {
gitlabManagerRestricted.deleteRepository(repositoryId);
await().until(() -> projectApi.getProjects().isEmpty());
}
}
if (usersToDeleteOnTearDown.size() > 0) {
for (Integer userId : usersToDeleteOnTearDown) {
userApi.deleteUser(userId);
GitLabServerManagerTest.awaitUserDeleted(userApi, userId);
}
}
// delete the GitLab user that we created in setUp, including associated groups/repos
// TODO: explicit deletion of associated groups/repos (above) is now superfluous since we are doing a hard delete
userApi.deleteUser(gitlabManagerRestricted.getUser().getUserId(), true);
// GitLabServerManagerTest.awaitUserDeleted(userApi, gitlabManagerRestricted.getUser().getUserId());
}
use of org.gitlab4j.api.UserApi in project catma by forTEXT.
the class CustomUserApiTest method tearDown.
@After
public void tearDown() throws Exception {
if (this.usersToDeleteOnTearDown.size() > 0) {
for (Integer userId : this.usersToDeleteOnTearDown) {
UserApi userApi = this.gitLabApi.getUserApi();
userApi.deleteUser(userId);
GitLabServerManagerTest.awaitUserDeleted(userApi, userId);
}
}
}
use of org.gitlab4j.api.UserApi in project catma by forTEXT.
the class GitlabManagerPrivileged method createPersonalAccessToken.
@Override
public String createPersonalAccessToken(int userId, String tokenName, LocalDate expiresAt) throws IOException {
UserApi userApi = this.privilegedGitLabApi.getUserApi();
try {
PersonalAccessToken personalAccessToken = userApi.createPersonalAccessToken(userId, tokenName, Date.from(expiresAt.atStartOfDay(ZoneId.systemDefault()).toInstant()), new Scope[] { Scope.READ_API });
logger.info(String.format("Created personal access token for user with ID %1$s.", userId));
return personalAccessToken.getToken();
} catch (GitLabApiException e) {
throw new IOException("Failed to create personal access token", e);
}
}
use of org.gitlab4j.api.UserApi 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.UserApi 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