mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-18 12:24:32 -05:00
bd63aa3c6b
sed -i '1i/*\nCopyright (c) Edgeless Systems GmbH\n\nSPDX-License-Identifier: AGPL-3.0-only\n*/\n' `grep -rL --include='*.go' 'DO NOT EDIT'` gofumpt -w .
31 lines
941 B
Go
31 lines
941 B
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package gcpshared
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
var providerIDRegex = regexp.MustCompile(`^gce://([^/]+)/([^/]+)/([^/]+)$`)
|
|
|
|
// SplitProviderID splits a provider's id into core components.
|
|
// A providerID is build after the schema 'gce://<project-id>/<zone>/<instance-name>'
|
|
func SplitProviderID(providerID string) (project, zone, instance string, err error) {
|
|
matches := providerIDRegex.FindStringSubmatch(providerID)
|
|
if len(matches) != 4 {
|
|
return "", "", "", fmt.Errorf("error splitting providerID: %v", providerID)
|
|
}
|
|
return matches[1], matches[2], matches[3], nil
|
|
}
|
|
|
|
// JoinProviderID builds a k8s provider ID for GCP instances.
|
|
// A providerID is build after the schema 'gce://<project-id>/<zone>/<instance-name>'
|
|
func JoinProviderID(project, zone, instanceName string) string {
|
|
return fmt.Sprintf("gce://%v/%v/%v", project, zone, instanceName)
|
|
}
|