Skip to content

deprecated #2096

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions modelarmor/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require": {
"google/cloud-modelarmor": "^0.1.0"
},
"autoload": {
"psr-4": {
"Google\\Cloud\\Samples\\ModelArmor\\": "test"
}
}
}
44 changes: 44 additions & 0 deletions modelarmor/src/get_folder_floor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* Copyright 2025 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.
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\ModelArmor;

require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s FOLDER_ID\n", basename(__FILE__));
}
list($_, $folderId) = $argv;

// [START modelarmor_get_folder_floor_settings]
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;

/** Uncomment and populate these variables in your code. */
// $folderId = "YOUR_FOLDER_ID"; // e.g. 'my-folder-id';

// Instantiates a client.
$client = new ModelArmorClient();

$floorSettingsName = sprintf('folders/%s/locations/global/floorSetting', $folderId);

$response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));

printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
// [END modelarmor_get_folder_floor_settings]
44 changes: 44 additions & 0 deletions modelarmor/src/get_organization_floor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* Copyright 2025 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.
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\ModelArmor;

require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s ORGANIZATION_ID\n", basename(__FILE__));
}
list($_, $organizationId) = $argv;

// [START modelarmor_get_organizarion_floor_settings]
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;

/** Uncomment and populate these variables in your code. */
// $organizationId = "YOUR_ORGANIZATION_ID"; // e.g. 'my-organization-id';

// Instantiates a client.
$client = new ModelArmorClient();

$floorSettingsName = sprintf('organizations/%s/locations/global/floorSetting', $organizationId);

$response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));

printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
// [END modelarmor_get_organizarion_floor_settings]
44 changes: 44 additions & 0 deletions modelarmor/src/get_project_floor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* Copyright 2025 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.
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\ModelArmor;

require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s PROJECT_ID\n", basename(__FILE__));
}
list($_, $projectId) = $argv;

// [START modelarmor_get_project_floor_settings]
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;

/** Uncomment and populate these variables in your code. */
// $projectId = "YOUR_PROJECT_ID"; // e.g. 'my-project-id';

// Instantiates a client.
$client = new ModelArmorClient();

$floorSettingsName = sprintf('projects/%s/locations/global/floorSetting', $projectId);

$response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));

printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
// [END modelarmor_get_project_floor_settings]
70 changes: 70 additions & 0 deletions modelarmor/src/update_folder_floor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
* Copyright 2025 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.
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\ModelArmor;

require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s FOLDER_ID\n", basename(__FILE__));
}
list($_, $folderId) = $argv;


// [START modelarmor_update_folder_floor_settings]
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
use Google\Cloud\ModelArmor\V1\RaiFilterType;
use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
use Google\Cloud\ModelArmor\V1\FilterConfig;
use Google\Cloud\ModelArmor\V1\FloorSetting;
use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;

/** Uncomment and populate these variables in your code. */
// $folderId = "YOUR_FOLDER_ID"; // e.g. 'my-folder-id';

// Instantiates a client.
$client = new ModelArmorClient();

$floorSettingsName = sprintf('folders/%s/locations/global/floorSetting', $folderId);

// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters

$raiFilterSetting = (new RaiFilterSettings())
->setRaiFilters([
(new RaiFilter())
->setFilterType(RaiFilterType::HATE_SPEECH)
->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
]);

$filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
$floorSetting = (new FloorSetting())
->setName($floorSettingsName)
->setFilterConfig($filterConfig)
->setEnableFloorSettingEnforcement(true);

$updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);

$response = $client->updateFloorSetting($updateRequest);

printf("Floor setting updated: %s\n", $response->getName());
// [END modelarmor_update_folder_floor_settings]
70 changes: 70 additions & 0 deletions modelarmor/src/update_organization_floor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
* Copyright 2025 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.
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\ModelArmor;

require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s ORGANIZATION_ID\n", basename(__FILE__));
}
list($_, $organizationId) = $argv;


// [START modelarmor_update_organizarion_floor_settings]
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
use Google\Cloud\ModelArmor\V1\RaiFilterType;
use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
use Google\Cloud\ModelArmor\V1\FilterConfig;
use Google\Cloud\ModelArmor\V1\FloorSetting;
use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;

/** Uncomment and populate these variables in your code. */
// $organizationId = "YOUR_ORGANIZATION_ID"; // e.g. 'my-organization-id';

// Instantiates a client.
$client = new ModelArmorClient();

$floorSettingsName = sprintf('organizations/%s/locations/global/floorSetting', $organizationId);

// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters

$raiFilterSetting = (new RaiFilterSettings())
->setRaiFilters([
(new RaiFilter())
->setFilterType(RaiFilterType::HATE_SPEECH)
->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
]);

$filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
$floorSetting = (new FloorSetting())
->setName($floorSettingsName)
->setFilterConfig($filterConfig)
->setEnableFloorSettingEnforcement(true);

$updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);

$response = $client->updateFloorSetting($updateRequest);

printf("Floor setting updated: %s\n", $response->getName());
// [END modelarmor_update_organizarion_floor_settings]
70 changes: 70 additions & 0 deletions modelarmor/src/update_project_floor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
* Copyright 2025 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.
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\ModelArmor;

require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 2) {
return printf("Usage: php %s PROJECT_ID\n", basename(__FILE__));
}
list($_, $projectId) = $argv;


// [START modelarmor_update_project_floor_settings]
use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
use Google\Cloud\ModelArmor\V1\RaiFilterType;
use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
use Google\Cloud\ModelArmor\V1\FilterConfig;
use Google\Cloud\ModelArmor\V1\FloorSetting;
use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;

/** Uncomment and populate these variables in your code. */
// $projectId = "YOUR_PROJECT_ID"; // e.g. 'my-project-id';

// Instantiates a client.
$client = new ModelArmorClient();

$floorSettingsName = sprintf('projects/%s/locations/global/floorSetting', $projectId);

// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters

$raiFilterSetting = (new RaiFilterSettings())
->setRaiFilters([
(new RaiFilter())
->setFilterType(RaiFilterType::HATE_SPEECH)
->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
]);

$filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
$floorSetting = (new FloorSetting())
->setName($floorSettingsName)
->setFilterConfig($filterConfig)
->setEnableFloorSettingEnforcement(true);

$updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);

$response = $client->updateFloorSetting($updateRequest);

printf("Floor setting updated: %s\n", $response->getName());
// [END modelarmor_update_project_floor_settings]
Loading