constellation/internal/cloud/cloudprovider/cloudprovider.go

58 lines
939 B
Go
Raw Normal View History

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package cloudprovider
2022-10-11 06:24:33 -04:00
import (
"encoding/json"
"strings"
)
2022-04-13 07:01:38 -04:00
//go:generate stringer -type=Provider
2022-04-13 09:09:33 -04:00
// Provider is cloud provider used by the CLI.
type Provider uint32
const (
2022-04-13 09:09:33 -04:00
Unknown Provider = iota
AWS
Azure
GCP
QEMU
)
2022-04-13 07:01:38 -04:00
2022-10-11 06:24:33 -04:00
// MarshalJSON marshals the Provider to JSON string.
func (p Provider) MarshalJSON() ([]byte, error) {
return json.Marshal(p.String())
}
// UnmarshalJSON unmarshals the Provider from JSON string.
func (p *Provider) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*p = FromString(s)
return nil
}
2022-04-13 07:01:38 -04:00
// FromString returns cloud provider from string.
2022-04-13 09:09:33 -04:00
func FromString(s string) Provider {
2022-04-13 07:01:38 -04:00
s = strings.ToLower(s)
switch s {
case "aws":
return AWS
case "azure":
return Azure
case "gcp":
return GCP
case "qemu":
return QEMU
2022-04-13 07:01:38 -04:00
default:
return Unknown
}
}