forked from GoogleCloudPlatform/nodejs-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add storage control folder and managed folder samples (GoogleCl…
…oudPlatform#3761) * feat: add storage control folder and managed folder samples * add tests * add storage-control.yaml
- Loading branch information
1 parent
0beddbd
commit e755f7d
Showing
14 changed files
with
812 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: storage-control | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'storage-control/**' | ||
- '.github/workflows/storage-control.yaml' | ||
- '.github/workflows/test.yaml' | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- labeled | ||
paths: | ||
- 'storage-control/**' | ||
- '.github/workflows/storage-control.yaml' | ||
- '.github/workflows/test.yaml' | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
jobs: | ||
test: | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' | ||
uses: ./.github/workflows/test.yaml | ||
with: | ||
name: 'storage-control' | ||
path: 'storage-control' | ||
flakybot: | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail | ||
uses: ./.github/workflows/flakybot.yaml | ||
needs: [test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
function main(bucketName, folderName) { | ||
// [START storage_control_create_folder] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
|
||
// The name of your GCS bucket | ||
// const bucketName = 'bucketName'; | ||
|
||
// The name of the folder to be created | ||
// const folderName = 'folderName'; | ||
|
||
// Imports the Control library | ||
const {StorageControlClient} = require('@google-cloud/storage-control').v2; | ||
|
||
// Instantiates a client | ||
const controlClient = new StorageControlClient(); | ||
|
||
async function callCreateFolder() { | ||
const bucketPath = controlClient.bucketPath('_', bucketName); | ||
|
||
// Create the request | ||
const request = { | ||
parent: bucketPath, | ||
folderId: folderName, | ||
}; | ||
|
||
// Run request | ||
const [response] = await controlClient.createFolder(request); | ||
console.log(`Created folder: ${response.name}.`); | ||
} | ||
|
||
callCreateFolder(); | ||
// [END storage_control_create_folder] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
function main(bucketName, managedFolderName) { | ||
// [START storage_control_managed_folder_create] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
|
||
// The name of your GCS bucket | ||
// const bucketName = 'bucketName'; | ||
|
||
// The name of the managed folder to be created | ||
// const managedFolderName = 'managedFolderName'; | ||
|
||
// Imports the Control library | ||
const {StorageControlClient} = require('@google-cloud/storage-control').v2; | ||
|
||
// Instantiates a client | ||
const controlClient = new StorageControlClient(); | ||
|
||
async function callCreateManagedFolder() { | ||
const bucketPath = controlClient.bucketPath('_', bucketName); | ||
|
||
// Create the request | ||
const request = { | ||
parent: bucketPath, | ||
managedFolderId: managedFolderName, | ||
}; | ||
|
||
// Run request | ||
const [response] = await controlClient.createManagedFolder(request); | ||
console.log(`Created managed folder: ${response.name}.`); | ||
} | ||
|
||
callCreateManagedFolder(); | ||
// [END storage_control_managed_folder_create] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
function main(bucketName, folderName) { | ||
// [START storage_control_delete_folder] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
|
||
// The name of your GCS bucket | ||
// const bucketName = 'bucketName'; | ||
|
||
// The name of the folder to be deleted | ||
// const folderName = 'folderName'; | ||
|
||
// Imports the Control library | ||
const {StorageControlClient} = require('@google-cloud/storage-control').v2; | ||
|
||
// Instantiates a client | ||
const controlClient = new StorageControlClient(); | ||
|
||
async function callDeleteFolder() { | ||
const folderPath = controlClient.folderPath('_', bucketName, folderName); | ||
|
||
// Create the request | ||
const request = { | ||
name: folderPath, | ||
}; | ||
|
||
// Run request | ||
await controlClient.deleteFolder(request); | ||
console.log(`Deleted folder: ${folderName}.`); | ||
} | ||
|
||
callDeleteFolder(); | ||
// [END storage_control_delete_folder] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
function main(bucketName, managedFolderName) { | ||
// [START storage_control_managed_folder_delete] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
|
||
// The name of your GCS bucket | ||
// const bucketName = 'bucketName'; | ||
|
||
// The name of the folder to be deleted | ||
// const managedFolderName = 'managedFolderName'; | ||
|
||
// Imports the Control library | ||
const {StorageControlClient} = require('@google-cloud/storage-control').v2; | ||
|
||
// Instantiates a client | ||
const controlClient = new StorageControlClient(); | ||
|
||
async function callDeleteManagedFolder() { | ||
const managedFolderPath = controlClient.managedFolderPath( | ||
'_', | ||
bucketName, | ||
managedFolderName | ||
); | ||
|
||
// Create the request | ||
const request = { | ||
name: managedFolderPath, | ||
}; | ||
|
||
// Run request | ||
await controlClient.deleteManagedFolder(request); | ||
console.log(`Deleted managed folder: ${managedFolderName}.`); | ||
} | ||
|
||
callDeleteManagedFolder(); | ||
// [END storage_control_managed_folder_delete] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
function main(bucketName, folderName) { | ||
// [START storage_control_get_folder] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
|
||
// The name of your GCS bucket | ||
// const bucketName = 'bucketName'; | ||
|
||
// The name of the folder to get | ||
// const folderName = 'folderName'; | ||
|
||
// Imports the Control library | ||
const {StorageControlClient} = require('@google-cloud/storage-control').v2; | ||
|
||
// Instantiates a client | ||
const controlClient = new StorageControlClient(); | ||
|
||
async function callGetFolder() { | ||
const folderPath = controlClient.folderPath('_', bucketName, folderName); | ||
|
||
// Create the request | ||
const request = { | ||
name: folderPath, | ||
}; | ||
|
||
// Run request | ||
const [response] = await controlClient.getFolder(request); | ||
console.log(`Got folder: ${response.name}.`); | ||
} | ||
|
||
callGetFolder(); | ||
// [END storage_control_get_folder] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
Oops, something went wrong.