pprados / langchain-googledrive

An external version of a pull request for langchain.
Apache License 2.0
26 stars 10 forks source link

Feature Request: Service Account Key from Environment (not file) #2

Closed tedsecretsource closed 1 year ago

tedsecretsource commented 1 year ago

This is a feature request to use a service account key that is defined in an environment variable. This is not a request to use the path to the service account key but to have the actual key in the environment.

Storing credentials on the filesystem can be problematic from a security perspective and for services like Heroku's Container stack, the credentials would have to be part of the repository in order to make it into a deployed production environment. This is because filesystems on the Container stack are "ephemeral".

I've worked around LangChain's GoogleDriveLoader file restriction with the following class override. Maybe it can help you?

class CustomGoogleDriveLoader(GoogleDriveLoader):
    """Loads Google Drive credentials from the environment instead of from a file."""
    def _load_credentials(self):
        try:
            creds = service_account.Credentials.from_service_account_info(
                json.loads(os.environ['GOOGLE_SERVICE_ACCT_KEY']),
                scopes=['https://www.googleapis.com/auth/drive.readonly']
            )
            return creds
        except ValueError:
            return super()._load_credentials()

I suspect the change would have to be made somewhere near here

Thanks. I'm looking forward to trying this out but not being able to store the whole key in the environment is a showstopper for me.

Ted

pprados commented 1 year ago

Thanks. I update the source with GOOGLE_ACCOUNT_SERVICE_KEY. I must fix two others bugs, and i will publish a new version.

        if "GOOGLE_ACCOUNT_SERVICE_KEY" in os.environ:
            return service_account.Credentials.from_service_account_info(
                json.loads(os.environ['GOOGLE_ACCOUNT_SERVICE_KEY']),
                scopes=scopes
            )
        elif api_file:
pprados commented 1 year ago

@tedsecretsource I just published a new version v0.0.306 with the variable GOOGLE_ACCOUNT_KEY with the body of Google files.