Node.js with custom endpoint
import { Storage } from '@google-cloud/storage';
import { FlashbackGCSStorage } from '@flashbacktech/flashbackclient/gcs';
const config = {
apiEndpoint: process.env.TEST_GCS_AWS_PROVIDER_URL,
tokenUri: process.env.TEST_GCS_AWS_PROVIDER_URL + '/token',
credentials: {
client_email: process.env.TEST_GCS_CLIENT_EMAIL!,
private_key: process.env.TEST_GCS_PRIVATE_KEY,
},
},
}
// Use custom auth client with custom token endpoint
const tokenUri = config.tokenUri || `${config.apiEndpoint}/token`;
const authClient = new FlashbackAuthClient(
tokenUri,
config.credentials,
[
'https://www.googleapis.com/auth/devstorage.full_control',
'https://www.googleapis.com/auth/devstorage.read_only',
'https://www.googleapis.com/auth/devstorage.read_write'
]
);
const storage = new Storage({
apiEndpoint: config.apiEndpoint,
authClient,
useAuthWithCustomEndpoint: true,
});
const bucket = storage.bucket(bucketName);
// 1. Check if bucket exists
try {
const [exists] = await storage.bucket(bucketName).exists();
expect(exists).toBe(true);
} catch (error) {
console.error('Error checking bucket existence:', error);
throw error;
}
Last updated
Was this helpful?