コード例 #1
0
    def initremote(self):
        self.isinitremote = True
        self._send_version()
        prefix = self.annex.getconfig('prefix')
        root_id = self.annex.getconfig('root_id')
        if not prefix and not root_id:
            raise RemoteError("Either prefix or root_id must be given.")

        token_config = self.annex.getconfig('token')
        if token_config:
            self.annex.setconfig('token', "")
            token_file = Path(token_config)
        else:
            git_root = Path(self.annex.getgitdir())
            othertmp_dir = git_root / "annex/othertmp"
            othertmp_dir.mkdir(parents=True, exist_ok=True)
            token_file = othertmp_dir / "git-annex-remote-googledrive.token"

        try:
            self.credentials = Credentials.from_authorized_user_file(
                token_file)
        except Exception as e:
            if token_config:
                raise RemoteError(
                    "Could not read token file {}:".format(token_file), e)
            self.annex.debug(
                "Error reading token file at {}".format(token_file), e,
                " Trying embedded credentials")
            if not self.credentials:
                raise RemoteError(
                    "No Credentials found. Run 'git-annex-remote-googledrive setup' in order to authenticate."
                )

        self.annex.setconfig('root_id', self.root.id)
        self.isinitremote = False
コード例 #2
0
 def credentials(self):
     if not hasattr(self, '_credentials'):
         json_creds = self.annex.getcreds('credentials')['user']
         try:
             self._credentials = Credentials.from_json(json_creds)
         except json.decoder.JSONDecodeError:
             self.annex.debug(
                 "Error decoding stored credentials: {}".format(json_creds))
             self._credentials = None
     return self._credentials
コード例 #3
0
 def credentials(self, creds):
     if creds != self.credentials:
         self._credentials = creds
         self.annex.setcreds('credentials',
                             ''.join(Credentials.to_json(creds).split()),
                             '')
コード例 #4
0
 def test_auth_creds(self):
     creds = Credentials.from_authorized_user_file(token_file)
     GoogleDrive(creds)