-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: add storage control folder and managed folder samples #3761
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2081d92
feat: add storage control folder and managed folder samples
ddelgrosso1 d56235b
add tests
ddelgrosso1 c7283e2
add storage-control.yaml
ddelgrosso1 9914392
Merge branch 'main' into storage-control-samples
ddelgrosso1 da699d9
Merge branch 'main' into storage-control-samples
ddelgrosso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: here and elsewhere, folder & managed folder names can be local variables since they can be static during testing. See https://googlecloudplatform.github.io/samples-style-guide/#minimal-arguments