Esempio n. 1
0
 def save_creds(self, cred_mc: OAuth2Credentials,
                cred_mm: OAuth2Credentials):
     cred_mc_entity = datastore.Entity(
         self._KEY_CRED_MC, exclude_from_indexes=('credentials', ))
     cred_mc_entity.update({'credentials': cred_mc.to_json()})
     cred_mm_entity = datastore.Entity(
         self._KEY_CRED_MM, exclude_from_indexes=('credentials', ))
     cred_mm_entity.update({'credentials': cred_mm.to_json()})
     self._ds.put_multi([cred_mc_entity, cred_mm_entity])
Esempio n. 2
0
    async def _update_creds(self, creds: OAuth2Credentials):
        cred_json = creds.to_json()
        json_dict = json.loads(cred_json)

        # update cache of new Credentials
        self.photo_library_creds = json_dict
        # Save it to the database
        await self.config.photo_library_creds.set(json_dict)
def config(cleandir, drive_creds: OAuth2Credentials):
    with open(os.path.join(cleandir, "secrets.yaml"), "w") as f:
        f.write("for_unit_tests: \"password value\"\n")

    with open(os.path.join(cleandir, "credentials.dat"), "w") as f:
        f.write(drive_creds.to_json())

    config = Config()
    config.override(Setting.DRIVE_URL, "http://localhost:1234")
    config.override(Setting.HASSIO_URL, "http://localhost:1234/")
    config.override(Setting.HOME_ASSISTANT_URL, "http://localhost:1234/homeassistant/api/")
    config.override(Setting.AUTHENTICATE_URL, "http://localhost:1234/external/drivecreds/")
    config.override(Setting.HASSIO_TOKEN, "test_header")
    config.override(Setting.SECRETS_FILE_PATH, "secrets.yaml")
    config.override(Setting.CREDENTIALS_FILE_PATH, "credentials.dat")
    config.override(Setting.FOLDER_FILE_PATH, "folder.dat")
    config.override(Setting.RETAINED_FILE_PATH, "retained.json")
    config.override(Setting.INGRESS_TOKEN_FILE_PATH, "ingress.dat")

    return config
Esempio n. 4
0
 def save_creds(self, cred_mc: OAuth2Credentials,
                cred_mm: OAuth2Credentials):
     with self._PATH_CRED_MC.open('w') as fmc:
         fmc.write(cred_mc.to_json())
     with self._PATH_CRED_MM.open('w') as fmm:
         fmm.write(cred_mm.to_json())