I’d ideally like to generate permanent access grants for each of my users, who in turn might want to generate public share links. I understand I can create restricted access grants with expirations, but I really want to create ephemeral share links from the access grants I create for my users. Is this possible?
My code:
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"storj.io/uplink"
)
func main() {
err := godotenv.Load("../.env")
if err != nil {
log.Fatal("Error loading .env file")
}
satelliteURL := os.Getenv("STORJ_SATELLITE_ADDRESS")
apiKey := os.Getenv("STORJ_API_KEY")
bucketName := os.Getenv("STORJ_BUCKET")
prefix := "/user123/"
ctx := context.Background()
config := edge.Config{
AuthServiceAddress: "auth.storjshare.io:7777",
}
access, err := uplink.RequestAccessWithPassphrase(ctx, satelliteURL, apiKey, "")
if err != nil {
log.Fatalf("Could not request access: %v", err)
}
permission := uplink.Permission{
AllowDownload: true,
AllowUpload: false,
AllowList: false,
AllowDelete: false,
}
sharePrefix := uplink.SharePrefix{
Bucket: bucketName,
Prefix: prefix,
}
// Create a derived access grant with the specified permissions and path restriction
restrictedAccess, err := access.Share(permission, sharePrefix)
if err != nil {
log.Fatalf("Could not create restricted access: %v", err)
}
// Serialize the restricted access grant to a string
restrictedAccessGrant, err := restrictedAccess.Serialize()
if err != nil {
log.Fatalf("Could not serialize restricted access: %v", err)
}
credentials, err := config.RegisterAccess(ctx, restrictedAccessGrant, &edge.RegisterAccessOptions{Public: true})
if err != nil {
return "", fmt.Errorf("could not register access: %w", err)
}
url, err := edge.JoinShareURL("https://link.storjshare.io", credentials.AccessKeyID, bucketName, "", nil)
if err != nil {
return "", fmt.Errorf("could not create a shared link: %w", err)
}
}
Or, after I give users an access grant, they, in turn, create sub-sub-restricted grants which have expirations?