-
Notifications
You must be signed in to change notification settings - Fork 168
Feat: add Google Cloud Storage Connector #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Storage } from '@smythos/sdk'; | ||
|
||
async function main() { | ||
const gcsStorage = Storage.GCS({ | ||
projectId: process.env.GCP_PROJECT_ID, | ||
clientEmail: process.env.GCP_CLIENT_EMAIL, | ||
privateKey: process.env.GCP_PRIVATE_KEY, | ||
bucket: process.env.GCP_BUCKET_NAME, | ||
}); | ||
|
||
await gcsStorage.write('test.txt', 'Hello, world!'); | ||
|
||
const data = await gcsStorage.read('test.txt'); | ||
|
||
const dataAsString = data.toString(); | ||
|
||
console.log(dataAsString); | ||
} | ||
|
||
main(); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -81,3 +81,50 @@ SRE.init({ | |||||||||||||||||||||||||||||||
- Store credentials securely using environment variables or AWS Secrets Manager | ||||||||||||||||||||||||||||||||
- Configure appropriate bucket policies and CORS settings | ||||||||||||||||||||||||||||||||
- Enable encryption at rest and in transit for sensitive data | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
--- | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
### GCS | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
**Role**: Google Cloud Storage connector | ||||||||||||||||||||||||||||||||
**Summary**: Provides scalable cloud storage using Google Cloud Storage, suitable for production deployments requiring high availability and durability on Google Cloud Platform. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| Setting | Type | Required | Default | Description | | ||||||||||||||||||||||||||||||||
| ------------- | ------ | -------- | ------- | ----------------------------------------------- | | ||||||||||||||||||||||||||||||||
| `projectId` | string | Yes | - | Google Cloud Project ID where the bucket is located | | ||||||||||||||||||||||||||||||||
| `clientEmail` | string | Yes | - | Service account email address | | ||||||||||||||||||||||||||||||||
| `privateKey` | string | Yes | - | Service account private key | | ||||||||||||||||||||||||||||||||
| `bucket` | string | Yes | - | GCS bucket name for storing files | | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
**Example Configuration:** | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```typescript | ||||||||||||||||||||||||||||||||
import { SRE } from '@smythos/sre'; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
SRE.init({ | ||||||||||||||||||||||||||||||||
Storage: { | ||||||||||||||||||||||||||||||||
Connector: 'GCS', | ||||||||||||||||||||||||||||||||
Settings: { | ||||||||||||||||||||||||||||||||
projectId: 'my-project-id', | ||||||||||||||||||||||||||||||||
clientEmail: process.env.GCP_CLIENT_EMAIL, | ||||||||||||||||||||||||||||||||
privateKey: process.env.GCP_PRIVATE_KEY, | ||||||||||||||||||||||||||||||||
bucket: 'my-app-storage', | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
Comment on lines
+101
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Private key newline gotcha (common failure in env vars) Service account keys stored in env vars often need newline restoration. Add a tip: - privateKey: process.env.GCP_PRIVATE_KEY,
+ // If stored as single-line env var, restore newlines:
+ privateKey: process.env.GCP_PRIVATE_KEY?.replace(/\\n/g, '\n'), I can update the example + add a warning callout. π Committable suggestion
Suggested change
π€ Prompt for AI Agents
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
**Use Cases:** | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- Production environments requiring scalability on Google Cloud Platform | ||||||||||||||||||||||||||||||||
- Multi-region deployments within GCP infrastructure | ||||||||||||||||||||||||||||||||
- Applications with high availability requirements | ||||||||||||||||||||||||||||||||
- Integration with Google Cloud ecosystem | ||||||||||||||||||||||||||||||||
- Large-scale data storage and processing | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
**Security Notes:** | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- Use service accounts with minimal required permissions | ||||||||||||||||||||||||||||||||
- Store credentials securely using environment variables or Google Secret Manager | ||||||||||||||||||||||||||||||||
- Configure appropriate bucket policies and IAM settings | ||||||||||||||||||||||||||||||||
- Enable encryption at rest and in transit for sensitive data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Env private key likely breaks without newline restoration
Most env-injected SA keys require
replace(/\\n/g, '\n')
. Without it, auth fails.Apply:
π Committable suggestion
π€ Prompt for AI Agents