Skip to main content

Addons for opentaskpy, giving it the ability to push/pull files via GCP Cloud Storage.

Project description

PyPi unittest status Coverage License Issues Stars

This repository contains addons to allow integration with GCP Cloud Storage via Open Task Framework (OTF)

Open Task Framework (OTF) is a Python based framework to make it easy to run predefined file transfers and scripts/commands on remote machines.

This addons allows pushes and pulls of Files from (and to) GCP Cloud Storage Buckets.

GCP SA Credentials

This package uses google-auth to get OAuth2.0 creds for the GCP Token API. This includes access_token.

Prior to using this framework, a GCP IAM Service Account should be created through gcloud CLI or Web portal. The JSON credentials for the Service account should be exported and stored locally. (currently the .gitignore excludes any .json in the tests folder by default)

The Service account crednetials should be included in tests/testFiles and require only the following properties:

{
    private_key= "-----BEGIN PRIVATE KEY-----\nMIIEv ....",
    client_email= "file.upload@projectName.iam.gserviceaccount.com",
    token_uri= "https://oauth2.googleapis.com/token"
}

The rest of the keys can be removed.

Running this OTF Addon, requires test files being placed in the src/tmp directory. Running the tests will perform an upload and download from/to GCP Cloud Storage.

Each request will generate a new Service Account Token, token refresh/state-keeping through AWS SSM or local cache has not been implemented yet.

Transfers

Transfers require a few additional arguments to work. These are:

  • bucket: The bucket name of the Cloud Storage instance
  • credentials: JSON object containing the above 3 credential properties.

Supported features

  • File transfer: ingress/egress from/to Cloud Storage
    • Renaming functionality
    • PostCopy functionality
    • fileWatch functionality

Configuration

JSON configs for transfers can be defined as follows:

Example file upload

"destination": {
    "bucket": "bucketname",
    "directory": "directory/nested",
    "protocol": {
        "name": "opentaskpy.addons.gcp.remotehandlers.bucket.BucketTransfer",
        "credentials": "{LOOKUP DEFINITION FOR SA CREDENTIALS}",
    },
    "rename":{
        "pattern":"Hithere",
        "sub": "Hi"
    }
}

Example file download

"source": {
    "bucket": "bucketname",
    "directory": "directory/nested",
    "protocol": {
        "name": "opentaskpy.addons.gcp.remotehandlers.bucket.BucketTransfer",
        "credentials": "{LOOKUP DEFINITION FOR SA CREDENTIALS}",
    },
    "postCopyAction":{
        "action":"move",
        "destination": "directory/nested/processed",
        "pattern" : "(?<![^ ])(?=[^ ])(?!ab)",   ## Regex for prefixing
        "sub" : "Archived_"
    },
    "fileRegex": "**.txt" ## Global Expression syntax (only download .txt)
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otf_addons_gcp-24.32.0.tar.gz (28.2 kB view details)

Uploaded Source

File details

Details for the file otf_addons_gcp-24.32.0.tar.gz.

File metadata

  • Download URL: otf_addons_gcp-24.32.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for otf_addons_gcp-24.32.0.tar.gz
Algorithm Hash digest
SHA256 870cfa94f4ce215b9b64116442b9e9f2df1608db9db1561a169f6e96a3eab8c2
MD5 73bd5e8ac102c50d9b51581c9dc20b90
BLAKE2b-256 260b7eff5ec622b7939fd1d579da2f147029dbbf7cf5e3c483710333e8c8e1fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page