/ github / UserKey.py
UserKey.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net>                 #
 4  # Copyright 2012 Zearin <zearin@gonk.net>                                      #
 5  # Copyright 2013 AKFish <akfish@gmail.com>                                     #
 6  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
 7  # Copyright 2013 martinqt <m.ki2@laposte.net>                                  #
 8  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 9  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
10  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
11  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
12  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
13  #                                                                              #
14  # This file is part of PyGithub.                                               #
15  # http://pygithub.readthedocs.io/                                              #
16  #                                                                              #
17  # PyGithub is free software: you can redistribute it and/or modify it under    #
18  # the terms of the GNU Lesser General Public License as published by the Free  #
19  # Software Foundation, either version 3 of the License, or (at your option)    #
20  # any later version.                                                           #
21  #                                                                              #
22  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
23  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
24  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
25  # details.                                                                     #
26  #                                                                              #
27  # You should have received a copy of the GNU Lesser General Public License     #
28  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
29  #                                                                              #
30  ################################################################################
31  
32  from typing import Any, Dict
33  
34  import github.GithubObject
35  from github.GithubObject import Attribute
36  
37  
38  class UserKey(github.GithubObject.CompletableGithubObject):
39      """
40      This class represents UserKeys. The reference can be found here https://docs.github.com/en/rest/reference/users#keys
41      """
42  
43      def _initAttributes(self) -> None:
44          self._id: Attribute[int] = github.GithubObject.NotSet
45          self._key: Attribute[str] = github.GithubObject.NotSet
46          self._title: Attribute[str] = github.GithubObject.NotSet
47          self._url: Attribute[str] = github.GithubObject.NotSet
48          self._verified: Attribute[bool] = github.GithubObject.NotSet
49  
50      def __repr__(self) -> str:
51          return self.get__repr__({"id": self._id.value, "title": self._title.value})
52  
53      @property
54      def id(self) -> int:
55          self._completeIfNotSet(self._id)
56          return self._id.value
57  
58      @property
59      def key(self) -> str:
60          self._completeIfNotSet(self._key)
61          return self._key.value
62  
63      @property
64      def title(self) -> str:
65          self._completeIfNotSet(self._title)
66          return self._title.value
67  
68      @property
69      def url(self) -> str:
70          self._completeIfNotSet(self._url)
71          return self._url.value
72  
73      @property
74      def verified(self) -> bool:
75          self._completeIfNotSet(self._verified)
76          return self._verified.value
77  
78      def delete(self) -> None:
79          """
80          :calls: `DELETE /user/keys/{id} <https://docs.github.com/en/rest/reference/users#get-a-public-ssh-key-for-the-authenticated-user>`_
81          :rtype: None
82          """
83          headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
84  
85      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
86          if "id" in attributes:  # pragma no branch
87              self._id = self._makeIntAttribute(attributes["id"])
88          if "key" in attributes:  # pragma no branch
89              self._key = self._makeStringAttribute(attributes["key"])
90          if "title" in attributes:  # pragma no branch
91              self._title = self._makeStringAttribute(attributes["title"])
92          if "url" in attributes:  # pragma no branch
93              self._url = self._makeStringAttribute(attributes["url"])
94          if "verified" in attributes:  # pragma no branch
95              self._verified = self._makeBoolAttribute(attributes["verified"])