1""" 2GitLab API: 3https://docs.gitlab.com/ee/api/instance_level_ci_variables.html 4https://docs.gitlab.com/ee/api/project_level_variables.html 5https://docs.gitlab.com/ee/api/group_level_variables.html 6""" 7from gitlab.base import RequiredOptional, RESTManager, RESTObject 8from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin 9 10__all__ = [ 11 "Variable", 12 "VariableManager", 13 "GroupVariable", 14 "GroupVariableManager", 15 "ProjectVariable", 16 "ProjectVariableManager", 17] 18 19 20class Variable(SaveMixin, ObjectDeleteMixin, RESTObject): 21 _id_attr = "key" 22 23 24class VariableManager(CRUDMixin, RESTManager): 25 _path = "/admin/ci/variables" 26 _obj_cls = Variable 27 _create_attrs = RequiredOptional( 28 required=("key", "value"), optional=("protected", "variable_type", "masked") 29 ) 30 _update_attrs = RequiredOptional( 31 required=("key", "value"), optional=("protected", "variable_type", "masked") 32 ) 33 34 35class GroupVariable(SaveMixin, ObjectDeleteMixin, RESTObject): 36 _id_attr = "key" 37 38 39class GroupVariableManager(CRUDMixin, RESTManager): 40 _path = "/groups/%(group_id)s/variables" 41 _obj_cls = GroupVariable 42 _from_parent_attrs = {"group_id": "id"} 43 _create_attrs = RequiredOptional( 44 required=("key", "value"), optional=("protected", "variable_type", "masked") 45 ) 46 _update_attrs = RequiredOptional( 47 required=("key", "value"), optional=("protected", "variable_type", "masked") 48 ) 49 50 51class ProjectVariable(SaveMixin, ObjectDeleteMixin, RESTObject): 52 _id_attr = "key" 53 54 55class ProjectVariableManager(CRUDMixin, RESTManager): 56 _path = "/projects/%(project_id)s/variables" 57 _obj_cls = ProjectVariable 58 _from_parent_attrs = {"project_id": "id"} 59 _create_attrs = RequiredOptional( 60 required=("key", "value"), 61 optional=("protected", "variable_type", "masked", "environment_scope"), 62 ) 63 _update_attrs = RequiredOptional( 64 required=("key", "value"), 65 optional=("protected", "variable_type", "masked", "environment_scope"), 66 ) 67