Skip to content

Refactor/structure objects #997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions gitlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,32 @@

from __future__ import print_function
from __future__ import absolute_import
from gitlab.exceptions import * # noqa
from gitlab.v4.objects.application import * # noqa
from gitlab.v4.objects.broadcast_message import * # noqa
from gitlab.v4.objects.current_user import * # noqa
from gitlab.v4.objects.deploy_key import * # noqa
from gitlab.v4.objects.ee import * # noqa
from gitlab.v4.objects.event import * # noqa
from gitlab.v4.objects.feature import * # noqa
from gitlab.v4.objects.group import * # noqa
from gitlab.v4.objects.hook import * # noqa
from gitlab.v4.objects.issue import * # noqa
from gitlab.v4.objects.mergerequest import * # noqa
from gitlab.v4.objects.namespace import * # noqa
from gitlab.v4.objects.notification_settings import * # noqa
from gitlab.v4.objects.project import * # noqa
from gitlab.v4.objects.runner import * # noqa
from gitlab.v4.objects.sidekiq import * # noqa
from gitlab.v4.objects.snippet import * # noqa
from gitlab.v4.objects.template import * # noqa
from gitlab.v4.objects.todo import * # noqa
from gitlab.v4.objects.user import * # noqa
import importlib
import time
import warnings

import requests

import gitlab.config
from gitlab.const import * # noqa
from gitlab.exceptions import * # noqa
from gitlab import utils # noqa

__title__ = "python-gitlab"
__version__ = "2.0.0"
Expand Down Expand Up @@ -110,35 +126,32 @@ def __init__(

self.per_page = per_page

objects = importlib.import_module("gitlab.v%s.objects" % self._api_version)
self._objects = objects

self.broadcastmessages = objects.BroadcastMessageManager(self)
self.deploykeys = objects.DeployKeyManager(self)
self.geonodes = objects.GeoNodeManager(self)
self.gitlabciymls = objects.GitlabciymlManager(self)
self.gitignores = objects.GitignoreManager(self)
self.groups = objects.GroupManager(self)
self.hooks = objects.HookManager(self)
self.issues = objects.IssueManager(self)
self.ldapgroups = objects.LDAPGroupManager(self)
self.licenses = objects.LicenseManager(self)
self.namespaces = objects.NamespaceManager(self)
self.mergerequests = objects.MergeRequestManager(self)
self.notificationsettings = objects.NotificationSettingsManager(self)
self.projects = objects.ProjectManager(self)
self.runners = objects.RunnerManager(self)
self.settings = objects.ApplicationSettingsManager(self)
self.sidekiq = objects.SidekiqManager(self)
self.snippets = objects.SnippetManager(self)
self.users = objects.UserManager(self)
self.todos = objects.TodoManager(self)
self.dockerfiles = objects.DockerfileManager(self)
self.events = objects.EventManager(self)
self.audit_events = objects.AuditEventManager(self)
self.features = objects.FeatureManager(self)
self.pagesdomains = objects.PagesDomainManager(self)
self.user_activities = objects.UserActivitiesManager(self)
self.broadcastmessages = BroadcastMessageManager(self)
self.deploykeys = DeployKeyManager(self)
self.geonodes = GeoNodeManager(self)
self.gitlabciymls = GitlabciymlManager(self)
self.gitignores = GitignoreManager(self)
self.groups = GroupManager(self)
self.hooks = HookManager(self)
self.issues = IssueManager(self)
self.ldapgroups = LDAPGroupManager(self)
self.licenses = LicenseManager(self)
self.namespaces = NamespaceManager(self)
self.mergerequests = MergeRequestManager(self)
self.notificationsettings = NotificationSettingsManager(self)
self.projects = ProjectManager(self)
self.runners = RunnerManager(self)
self.settings = ApplicationSettingsManager(self)
self.sidekiq = SidekiqManager(self)
self.snippets = SnippetManager(self)
self.users = UserManager(self)
self.todos = TodoManager(self)
self.dockerfiles = DockerfileManager(self)
self.events = EventManager(self)
self.audit_events = AuditEventManager(self)
self.features = FeatureManager(self)
self.pagesdomains = PagesDomainManager(self)
self.user_activities = UserActivitiesManager(self)

def __enter__(self):
return self
Expand Down
6 changes: 2 additions & 4 deletions gitlab/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import gitlab
from gitlab import base
from gitlab import cli
from gitlab import base, cli, utils
from gitlab import exceptions as exc
from gitlab import types as g_types
from gitlab import utils


class GetMixin(object):
Expand Down Expand Up @@ -415,7 +413,7 @@ class AccessRequestMixin(object):
("ProjectAccessRequest", "GroupAccessRequest"), tuple(), ("access_level",)
)
@exc.on_http_error(exc.GitlabUpdateError)
def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
def approve(self, access_level=gitlab.const.DEVELOPER_ACCESS, **kwargs):
"""Approve an access request.

Args:
Expand Down
1 change: 1 addition & 0 deletions gitlab/v4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from gitlab.const import * # noqa
1 change: 0 additions & 1 deletion gitlab/v4/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import gitlab
import gitlab.base
from gitlab import cli
import gitlab.v4.objects


class GitlabCLI(object):
Expand Down
Empty file added gitlab/v4/objects/__init__.py
Empty file.
137 changes: 137 additions & 0 deletions gitlab/v4/objects/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from gitlab.base import * # noqa
from gitlab.exceptions import * # noqa
from gitlab.mixins import * # noqa
from gitlab import types
from gitlab import utils


class ApplicationAppearance(SaveMixin, RESTObject):
_id_attr = None


class ApplicationAppearanceManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = "/application/appearance"
_obj_cls = ApplicationAppearance
_update_attrs = (
tuple(),
(
"title",
"description",
"logo",
"header_logo",
"favicon",
"new_project_guidelines",
"header_message",
"footer_message",
"message_background_color",
"message_font_color",
"email_header_and_footer_enabled",
),
)

@exc.on_http_error(exc.GitlabUpdateError)
def update(self, id=None, new_data=None, **kwargs):
"""Update an object on the server.

Args:
id: ID of the object to update (can be None if not required)
new_data: the update data for the object
**kwargs: Extra options to send to the server (e.g. sudo)

Returns:
dict: The new object data (*not* a RESTObject)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request
"""
new_data = new_data or {}
data = new_data.copy()
super(ApplicationAppearanceManager, self).update(id, data, **kwargs)


class ApplicationSettings(SaveMixin, RESTObject):
_id_attr = None


class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = "/application/settings"
_obj_cls = ApplicationSettings
_update_attrs = (
tuple(),
(
"id",
"default_projects_limit",
"signup_enabled",
"password_authentication_enabled_for_web",
"gravatar_enabled",
"sign_in_text",
"created_at",
"updated_at",
"home_page_url",
"default_branch_protection",
"restricted_visibility_levels",
"max_attachment_size",
"session_expire_delay",
"default_project_visibility",
"default_snippet_visibility",
"default_group_visibility",
"outbound_local_requests_whitelist",
"domain_whitelist",
"domain_blacklist_enabled",
"domain_blacklist",
"external_authorization_service_enabled",
"external_authorization_service_url",
"external_authorization_service_default_label",
"external_authorization_service_timeout",
"user_oauth_applications",
"after_sign_out_path",
"container_registry_token_expire_delay",
"repository_storages",
"plantuml_enabled",
"plantuml_url",
"terminal_max_session_time",
"polling_interval_multiplier",
"rsa_key_restriction",
"dsa_key_restriction",
"ecdsa_key_restriction",
"ed25519_key_restriction",
"first_day_of_week",
"enforce_terms",
"terms",
"performance_bar_allowed_group_id",
"instance_statistics_visibility_private",
"user_show_add_ssh_key_message",
"file_template_project_id",
"local_markdown_version",
"asset_proxy_enabled",
"asset_proxy_url",
"asset_proxy_whitelist",
"geo_node_allowed_ips",
"allow_local_requests_from_hooks_and_services",
"allow_local_requests_from_web_hooks_and_services",
"allow_local_requests_from_system_hooks",
),
)

@exc.on_http_error(exc.GitlabUpdateError)
def update(self, id=None, new_data=None, **kwargs):
"""Update an object on the server.

Args:
id: ID of the object to update (can be None if not required)
new_data: the update data for the object
**kwargs: Extra options to send to the server (e.g. sudo)

Returns:
dict: The new object data (*not* a RESTObject)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request
"""
new_data = new_data or {}
data = new_data.copy()
if "domain_whitelist" in data and data["domain_whitelist"] is None:
data.pop("domain_whitelist")
super(ApplicationSettingsManager, self).update(id, data, **kwargs)
17 changes: 17 additions & 0 deletions gitlab/v4/objects/broadcast_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from gitlab.base import * # noqa
from gitlab.exceptions import * # noqa
from gitlab.mixins import * # noqa
from gitlab import types
from gitlab import utils


class BroadcastMessage(SaveMixin, ObjectDeleteMixin, RESTObject):
pass


class BroadcastMessageManager(CRUDMixin, RESTManager):
_path = "/broadcast_messages"
_obj_cls = BroadcastMessage

_create_attrs = (("message",), ("starts_at", "ends_at", "color", "font"))
_update_attrs = (tuple(), ("message", "starts_at", "ends_at", "color", "font"))
62 changes: 62 additions & 0 deletions gitlab/v4/objects/current_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from gitlab.base import * # noqa
from gitlab.exceptions import * # noqa
from gitlab.mixins import * # noqa
from gitlab import types
from gitlab import utils


class CurrentUserEmail(ObjectDeleteMixin, RESTObject):
_short_print_attr = "email"


class CurrentUserEmailManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/user/emails"
_obj_cls = CurrentUserEmail
_create_attrs = (("email",), tuple())


class CurrentUserGPGKey(ObjectDeleteMixin, RESTObject):
pass


class CurrentUserGPGKeyManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/user/gpg_keys"
_obj_cls = CurrentUserGPGKey
_create_attrs = (("key",), tuple())


class CurrentUserKey(ObjectDeleteMixin, RESTObject):
_short_print_attr = "title"


class CurrentUserKeyManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/user/keys"
_obj_cls = CurrentUserKey
_create_attrs = (("title", "key"), tuple())


class CurrentUserStatus(SaveMixin, RESTObject):
_id_attr = None
_short_print_attr = "message"


class CurrentUserStatusManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = "/user/status"
_obj_cls = CurrentUserStatus
_update_attrs = (tuple(), ("emoji", "message"))


class CurrentUser(RESTObject):
_id_attr = None
_short_print_attr = "username"
_managers = (
("status", "CurrentUserStatusManager"),
("emails", "CurrentUserEmailManager"),
("gpgkeys", "CurrentUserGPGKeyManager"),
("keys", "CurrentUserKeyManager"),
)


class CurrentUserManager(GetWithoutIdMixin, RESTManager):
_path = "/user"
_obj_cls = CurrentUser
14 changes: 14 additions & 0 deletions gitlab/v4/objects/deploy_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from gitlab.base import * # noqa
from gitlab.exceptions import * # noqa
from gitlab.mixins import * # noqa
from gitlab import types
from gitlab import utils


class DeployKey(RESTObject):
pass


class DeployKeyManager(ListMixin, RESTManager):
_path = "/deploy_keys"
_obj_cls = DeployKey
Loading