mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-14 01:35:34 -04:00
Add method for building resource URIs
This commit is contained in:
parent
a02a46e454
commit
14ef07aca9
3 changed files with 87 additions and 4 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
compute "cloud.google.com/go/compute/apiv1"
|
||||
admin "cloud.google.com/go/iam/admin/apiv1"
|
||||
|
@ -323,6 +324,44 @@ func (c *Client) generateUID() (string, error) {
|
|||
return string(uid), nil
|
||||
}
|
||||
|
||||
func (c *Client) resourceURI(scope resourceScope, resourceType, resourceName string) string {
|
||||
const baseURI = "https://www.googleapis.com/compute/v1/projects/"
|
||||
|
||||
builder := strings.Builder{}
|
||||
|
||||
builder.WriteString(baseURI)
|
||||
builder.WriteString(c.project)
|
||||
|
||||
switch scope {
|
||||
case scopeGlobal:
|
||||
builder.WriteString("/global/")
|
||||
case scopeRegion:
|
||||
builder.WriteString("/regions/")
|
||||
builder.WriteString(c.region)
|
||||
builder.WriteString("/")
|
||||
case scopeZone:
|
||||
builder.WriteString("/zones/")
|
||||
builder.WriteString(c.zone)
|
||||
builder.WriteString("/")
|
||||
default:
|
||||
panic("unknown scope")
|
||||
}
|
||||
|
||||
builder.WriteString(resourceType)
|
||||
builder.WriteString("/")
|
||||
builder.WriteString(resourceName)
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
type resourceScope string
|
||||
|
||||
const (
|
||||
scopeGlobal resourceScope = "global"
|
||||
scopeRegion resourceScope = "region"
|
||||
scopeZone resourceScope = "zone"
|
||||
)
|
||||
|
||||
type closer interface {
|
||||
Close() error
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue