github.com/gophercloud/gophercloud@v1.11.0/openstack/objectstorage/v1/containers/urls.go (about)

     1  package containers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/gophercloud/gophercloud"
     8  )
     9  
    10  const forbiddenContainerRunes = "/"
    11  
    12  func CheckContainerName(s string) error {
    13  	if strings.ContainsAny(s, forbiddenContainerRunes) {
    14  		return ErrInvalidContainerName{}
    15  	}
    16  
    17  	// The input could (and should) already have been escaped. This cycle
    18  	// checks for the escaped versions of the forbidden characters. Note
    19  	// that a simple "contains" is sufficient, because Go's http library
    20  	// won't accept invalid escape sequences (e.g. "%%2F").
    21  	for _, r := range forbiddenContainerRunes {
    22  		if strings.Contains(strings.ToLower(s), fmt.Sprintf("%%%x", r)) {
    23  			return ErrInvalidContainerName{}
    24  		}
    25  	}
    26  	return nil
    27  }
    28  
    29  func listURL(c *gophercloud.ServiceClient) string {
    30  	return c.Endpoint
    31  }
    32  
    33  func createURL(c *gophercloud.ServiceClient, container string) (string, error) {
    34  	if err := CheckContainerName(container); err != nil {
    35  		return "", err
    36  	}
    37  	return c.ServiceURL(container), nil
    38  }
    39  
    40  func getURL(c *gophercloud.ServiceClient, container string) (string, error) {
    41  	return createURL(c, container)
    42  }
    43  
    44  func deleteURL(c *gophercloud.ServiceClient, container string) (string, error) {
    45  	return createURL(c, container)
    46  }
    47  
    48  func updateURL(c *gophercloud.ServiceClient, container string) (string, error) {
    49  	return createURL(c, container)
    50  }
    51  
    52  func bulkDeleteURL(c *gophercloud.ServiceClient) string {
    53  	return c.Endpoint + "?bulk-delete=true"
    54  }