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
Example #2
0
 def test_auth_creds(self):
     creds = Credentials.from_authorized_user_file(token_file)
     GoogleDrive(creds)