An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
-
Greg Messner authored932c6bba
package org.gitlab4j.api;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.Constants.TokenType;
import org.gitlab4j.api.models.OauthTokenResponse;
import org.gitlab4j.api.models.Session;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.models.Version;
import org.gitlab4j.api.utils.MaskingLoggingFilter;
import org.gitlab4j.api.utils.Oauth2LoginStreamingOutput;
import org.gitlab4j.api.utils.SecretString;
/**
* This class is provides a simplified interface to a GitLab API server, and divides the API up into
* a separate API class for each concern.
*/
public class GitLabApi {
private final static Logger LOGGER = Logger.getLogger(GitLabApi.class.getName());
/** GitLab4J default per page. GitLab will ignore anything over 100. */
public static final int DEFAULT_PER_PAGE = 96;
/** Specifies the version of the GitLab API to communicate with. */
public enum ApiVersion {
V3, V4;
public String getApiNamespace() {
return ("/api/" + name().toLowerCase());
}
}
// Used to keep track of GitLabApiExceptions on calls that return Optional<?>
private static final Map<Integer, GitLabApiException> optionalExceptionMap =
Collections.synchronizedMap(new WeakHashMap<Integer, GitLabApiException>());
GitLabApiClient apiClient;
private ApiVersion apiVersion;
private String gitLabServerUrl;
private Map<String, Object> clientConfigProperties;
private int defaultPerPage = DEFAULT_PER_PAGE;
private Session session;
private ApplicationsApi applicationsApi;
private ApplicationSettingsApi applicationSettingsApi;
private AwardEmojiApi awardEmojiApi;
private BoardsApi boardsApi;
private CommitsApi commitsApi;
private ContainerRegistryApi containerRegistryApi;
private DiscussionsApi discussionsApi;
private DeployKeysApi deployKeysApi;
private EpicsApi epicsApi;
private EventsApi eventsApi;
private GroupApi groupApi;
private HealthCheckApi healthCheckApi;
private ImportExportApi importExportApi;
private IssuesApi issuesApi;
private JobApi jobApi;
private LabelsApi labelsApi;
private LicenseApi licenseApi;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
private LicenseTemplatesApi licenseTemplatesApi;
private MarkdownApi markdownApi;
private MergeRequestApi mergeRequestApi;
private MilestonesApi milestonesApi;
private NamespaceApi namespaceApi;
private NotesApi notesApi;
private NotificationSettingsApi notificationSettingsApi;
private PackagesApi packagesApi;
private PipelineApi pipelineApi;
private ProjectApi projectApi;
private ProtectedBranchesApi protectedBranchesApi;
private RepositoryApi repositoryApi;
private RepositoryFileApi repositoryFileApi;
private RunnersApi runnersApi;
private SearchApi searchApi;
private ServicesApi servicesApi;
private SessionApi sessionApi;
private SnippetsApi snippetsApi;
private SystemHooksApi systemHooksApi;
private TagsApi tagsApi;
private TodosApi todosApi;
private UserApi userApi;
private WikisApi wikisApi;
/**
* Get the GitLab4J shared Logger instance.
*
* @return the GitLab4J shared Logger instance
*/
public static final Logger getLogger() {
return (LOGGER);
}
/**
* Create a new GitLabApi instance that is logically a duplicate of this instance, with the exception off sudo state.
*
* @return a new GitLabApi instance that is logically a duplicate of this instance, with the exception off sudo state.
*/
public final GitLabApi duplicate() {
Integer sudoUserId = this.getSudoAsId();
GitLabApi gitLabApi = new GitLabApi(apiVersion, gitLabServerUrl,
getTokenType(), getAuthToken(), getSecretToken(), clientConfigProperties);
if (sudoUserId != null) {
gitLabApi.apiClient.setSudoAsId(sudoUserId);
}
if (getIgnoreCertificateErrors()) {
gitLabApi.setIgnoreCertificateErrors(true);
}
gitLabApi.defaultPerPage = this.defaultPerPage;
return (gitLabApi);
}
/**
* <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
* and creates a new {@code GitLabApi} instance using returned access token.</p>
*
* @param url GitLab URL
* @param username user name for which private token should be obtained
* @param password a CharSequence containing the password for a given {@code username}
* @return new {@code GitLabApi} instance configured for a user-specific token
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public static GitLabApi oauth2Login(String url, String username, CharSequence password) throws GitLabApiException {
return (GitLabApi.oauth2Login(ApiVersion.V4, url, username, password, null, null, false));
}
/**