using Google.Api.Gax.ResourceNames;
using Google.Cloud.Asset.V1;
public class ExportAssetsSample
{
public ExportAssetsResponse ExportAssets(string bucketName, string projectId)
{
string assetDumpFile = $"gs://{bucketName}/my-assets.txt";
// Create the client
AssetServiceClient client = AssetServiceClient.Create();
// Build the request
ExportAssetsRequest request = new ExportAssetsRequest
{
ParentAsResourceName = ProjectName.FromProject(projectId),
OutputConfig = new OutputConfig
{
GcsDestination = new GcsDestination { Uri = assetDumpFile }
}
};
// Start the long-running export operation
var operation = client.ExportAssets(request);
// Wait for it to complete (or fail)
operation = operation.PollUntilCompleted();
// Return the result
return operation.Result;
}
}
use Google\Cloud\Asset\V1\AssetServiceClient;
use Google\Cloud\Asset\V1\GcsDestination;
use Google\Cloud\Asset\V1\OutputConfig;
/**
* Export assets for given project to specified dump file path.
*
* @param string $projectId the project Id for export assets.
* @param string $dumpFilePath the file path where the assets will be dumped to.
* e.g.: gs://[bucket-name]/[asset-file-name].
*/
function export_assets(string $projectId, string $dumpFilePath)
{
$client = new AssetServiceClient();
$gcsDestination = new GcsDestination(['uri' => $dumpFilePath]);
$outputConfig = new OutputConfig(['gcs_destination' => $gcsDestination]);
$resp = $client->exportAssets("projects/$projectId", $outputConfig);
$resp->pollUntilComplete();
if ($resp->operationSucceeded()) {
print('The result is dumped to $dumpFilePath successfully.' . PHP_EOL);
} else {
$error = $resp->getError();
printf('There was an error: "%s".' . PHP_EOL, $error->getMessage());
// handleError($error)
}
}