Skip to content

Commit

Permalink
feat: add storage control folder and managed folder samples (GoogleCl…
Browse files Browse the repository at this point in the history
…oudPlatform#3761)

* feat: add storage control folder and managed folder samples

* add tests

* add storage-control.yaml
  • Loading branch information
ddelgrosso1 authored Jul 26, 2024
1 parent 0beddbd commit e755f7d
Show file tree
Hide file tree
Showing 14 changed files with 812 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/storage-control.yaml
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]
57 changes: 57 additions & 0 deletions storage-control/createFolder.js
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));
57 changes: 57 additions & 0 deletions storage-control/createManagedFolder.js
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));
56 changes: 56 additions & 0 deletions storage-control/deleteFolder.js
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));
60 changes: 60 additions & 0 deletions storage-control/deleteManagedFolder.js
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));
56 changes: 56 additions & 0 deletions storage-control/getFolder.js
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));
Loading

0 comments on commit e755f7d

Please sign in to comment.