getObjectSignedUrl

The Google Cloud storage signed URL data source generates a signed URL for a given storage object. Signed URLs provide a way to give time-limited read or write access to anyone in possession of the URL, regardless of whether they have a Google account. For more info about signed URL's is available here.

Example Usage

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.storage.StorageFunctions;
import com.pulumi.gcp.storage.inputs.GetObjectSignedUrlArgs;
import com.pulumi.gcp.compute.Instance;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var artifact = StorageFunctions.getObjectSignedUrl(GetObjectSignedUrlArgs.builder()
.bucket("install_binaries")
.path("path/to/install_file.bin")
.build());
var vm = new Instance("vm");
}
}

Full Example

import * as pulumi from "@pulumi/pulumi";
import * as fs from "fs";
import * as gcp from "@pulumi/gcp";
const getUrl = gcp.storage.getObjectSignedUrl({
bucket: "fried_chicken",
path: "path/to/file",
contentMd5: "pRviqwS4c4OTJRTe03FD1w==",
contentType: "text/plain",
duration: "2d",
credentials: fs.readFileSync("path/to/credentials.json"),
extensionHeaders: {
"x-goog-if-generation-match": "1",
},
});
import pulumi
import pulumi_gcp as gcp
get_url = gcp.storage.get_object_signed_url(bucket="fried_chicken",
path="path/to/file",
content_md5="pRviqwS4c4OTJRTe03FD1w==",
content_type="text/plain",
duration="2d",
credentials=(lambda path: open(path).read())("path/to/credentials.json"),
extension_headers={
"x-goog-if-generation-match": "1",
})
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var getUrl = Gcp.Storage.GetObjectSignedUrl.Invoke(new()
{
Bucket = "fried_chicken",
Path = "path/to/file",
ContentMd5 = "pRviqwS4c4OTJRTe03FD1w==",
ContentType = "text/plain",
Duration = "2d",
Credentials = File.ReadAllText("path/to/credentials.json"),
ExtensionHeaders =
{
{ "x-goog-if-generation-match", "1" },
},
});
});
package main
import (
"os"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func readFileOrPanic(path string) pulumi.StringPtrInput {
data, err := os.ReadFile(path)
if err != nil {
panic(err.Error())
}
return pulumi.String(string(data))
}
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := storage.GetObjectSignedUrl(ctx, &storage.GetObjectSignedUrlArgs{
Bucket: "fried_chicken",
Path: "path/to/file",
ContentMd5: pulumi.StringRef("pRviqwS4c4OTJRTe03FD1w=="),
ContentType: pulumi.StringRef("text/plain"),
Duration: pulumi.StringRef("2d"),
Credentials: pulumi.StringRef(readFileOrPanic("path/to/credentials.json")),
ExtensionHeaders: map[string]interface{}{
"x-goog-if-generation-match": "1",
},
}, nil)
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.storage.StorageFunctions;
import com.pulumi.gcp.storage.inputs.GetObjectSignedUrlArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var getUrl = StorageFunctions.getObjectSignedUrl(GetObjectSignedUrlArgs.builder()
.bucket("fried_chicken")
.path("path/to/file")
.contentMd5("pRviqwS4c4OTJRTe03FD1w==")
.contentType("text/plain")
.duration("2d")
.credentials(Files.readString(Paths.get("path/to/credentials.json")))
.extensionHeaders(Map.of("x-goog-if-generation-match", 1))
.build());
}
}
variables:
getUrl:
fn::invoke:
Function: gcp:storage:getObjectSignedUrl
Arguments:
bucket: fried_chicken
path: path/to/file
contentMd5: pRviqwS4c4OTJRTe03FD1w==
contentType: text/plain
duration: 2d
credentials:
fn::readFile: path/to/credentials.json
extensionHeaders:
x-goog-if-generation-match: 1

Return

A collection of values returned by getObjectSignedUrl.

Parameters

argument

A collection of arguments for invoking getObjectSignedUrl.


suspend fun getObjectSignedUrl(bucket: String, contentMd5: String? = null, contentType: String? = null, credentials: String? = null, duration: String? = null, extensionHeaders: Map<String, String>? = null, httpMethod: String? = null, path: String): GetObjectSignedUrlResult

Return

A collection of values returned by getObjectSignedUrl.

Parameters

bucket

The name of the bucket to read the object from

contentMd5

The MD5 digest value in Base64. Typically retrieved from google_storage_bucket_object.object.md5hash attribute. If you provide this in the datasource, the client (e.g. browser, curl) must provide the Content-MD5 HTTP header with this same value in its request.

contentType

If you specify this in the datasource, the client must provide the Content-Type HTTP header with the same value in its request.

credentials

What Google service account credentials json should be used to sign the URL. This data source checks the following locations for credentials, in order of preference: data source credentials attribute, provider credentials attribute and finally the GOOGLE_APPLICATION_CREDENTIALS environment variable.

NOTE the default google credentials configured by gcloud sdk or the service account associated with a compute instance cannot be used, because these do not include the private key required to sign the URL. A valid json service account credentials key file must be used, as generated via Google cloud console.

duration

For how long shall the signed URL be valid (defaults to 1 hour - i.e. 1h). See here for info on valid duration formats.

extensionHeaders

As needed. The server checks to make sure that the client provides matching values in requests using the signed URL. Any header starting with x-goog- is accepted but see the Google Docs for list of headers that are supported by Google.

httpMethod

What HTTP Method will the signed URL allow (defaults to GET)

path

The full path to the object inside the bucket

See also


Return

A collection of values returned by getObjectSignedUrl.

Parameters

argument

Builder for com.pulumi.gcp.storage.kotlin.inputs.GetObjectSignedUrlPlainArgs.

See also