// CreateTempURL is a function for creating a temporary URL for an object. It // allows users to have "GET" or "POST" access to a particular tenant's object // for a limited amount of time. func CreateTempURL(c *gophercloud.ServiceClient, containerName, objectName string, opts CreateTempURLOpts) (string, error) { if opts.Split == "" { opts.Split = "/v1/" } duration := time.Duration(opts.TTL) * time.Second expiry := time.Now().Add(duration).Unix() getHeader, err := accounts.Get(c, nil).Extract() if err != nil { return "", err } secretKey := []byte(getHeader.TempURLKey) url := getURL(c, containerName, objectName) splitPath := strings.Split(url, opts.Split) baseURL, objectPath := splitPath[0], splitPath[1] objectPath = opts.Split + objectPath body := fmt.Sprintf("%s\n%d\n%s", opts.Method, expiry, objectPath) hash := hmac.New(sha1.New, secretKey) hash.Write([]byte(body)) hexsum := fmt.Sprintf("%x", hash.Sum(nil)) return fmt.Sprintf("%s%s?temp_url_sig=%s&temp_url_expires=%d", baseURL, objectPath, hexsum, expiry), nil }
// Get is a function that retrieves an account's metadata. To extract just the // custom metadata, call the ExtractMetadata method on the GetResult. To extract // all the headers that are returned (including the metadata), call the // ExtractHeader method on the GetResult. func Get(c *gophercloud.ServiceClient) os.GetResult { return os.Get(c, nil) }