File: urls.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (54 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package containers

import (
	"fmt"
	"strings"

	"github.com/gophercloud/gophercloud"
)

const forbiddenContainerRunes = "/"

func CheckContainerName(s string) error {
	if strings.ContainsAny(s, forbiddenContainerRunes) {
		return ErrInvalidContainerName{}
	}

	// The input could (and should) already have been escaped. This cycle
	// checks for the escaped versions of the forbidden characters. Note
	// that a simple "contains" is sufficient, because Go's http library
	// won't accept invalid escape sequences (e.g. "%%2F").
	for _, r := range forbiddenContainerRunes {
		if strings.Contains(strings.ToLower(s), fmt.Sprintf("%%%x", r)) {
			return ErrInvalidContainerName{}
		}
	}
	return nil
}

func listURL(c *gophercloud.ServiceClient) string {
	return c.Endpoint
}

func createURL(c *gophercloud.ServiceClient, container string) (string, error) {
	if err := CheckContainerName(container); err != nil {
		return "", err
	}
	return c.ServiceURL(container), nil
}

func getURL(c *gophercloud.ServiceClient, container string) (string, error) {
	return createURL(c, container)
}

func deleteURL(c *gophercloud.ServiceClient, container string) (string, error) {
	return createURL(c, container)
}

func updateURL(c *gophercloud.ServiceClient, container string) (string, error) {
	return createURL(c, container)
}

func bulkDeleteURL(c *gophercloud.ServiceClient) string {
	return c.Endpoint + "?bulk-delete=true"
}