mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-27 08:29:33 -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
641 B
Go
31 lines
641 B
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package client
|
|
|
|
import (
|
|
"errors"
|
|
"regexp"
|
|
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
var projectIDRegex = regexp.MustCompile(`(?m)^project-id = (.*)$`)
|
|
|
|
// loadProjectID loads the project id from the gce config file.
|
|
func loadProjectID(fs afero.Fs, path string) (string, error) {
|
|
rawConfig, err := afero.ReadFile(fs, path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
// find project-id line
|
|
matches := projectIDRegex.FindStringSubmatch(string(rawConfig))
|
|
if len(matches) != 2 {
|
|
return "", errors.New("invalid config: project-id not found")
|
|
}
|
|
return matches[1], nil
|
|
}
|