blob: 1277c2ab3e34e4371b53c9ef1f584abdee9f386e [file] [log] [blame]
Serge Bazanski42e61c62021-03-18 15:07:18 +01001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package cluster
18
19import (
20 "fmt"
21
22 "source.monogon.dev/metropolis/pkg/pki"
23)
24
25type ClusterState int
26
27const (
28 ClusterUnknown ClusterState = iota
29 ClusterForeign
30 ClusterTrusted
31 ClusterHome
32 ClusterDisowning
33)
34
35type Cluster struct {
36 State ClusterState
37}
38
39func (s ClusterState) String() string {
40 switch s {
41 case ClusterForeign:
42 return "ClusterForeign"
43 case ClusterTrusted:
44 return "ClusterTrusted"
45 case ClusterHome:
46 return "ClusterHome"
47 case ClusterDisowning:
48 return "ClusterDisowning"
49 }
50 return fmt.Sprintf("Invalid(%d)", s)
51}
52
53var clusterStateTransitions = map[ClusterState][]ClusterState{
54 ClusterUnknown: {ClusterForeign, ClusterHome, ClusterDisowning},
55 ClusterForeign: {ClusterTrusted},
56 ClusterTrusted: {ClusterHome},
57 ClusterHome: {ClusterHome, ClusterDisowning},
58}
59
60var (
61 PKINamespace = pki.Namespaced("/cluster-pki/")
62 PKICA = PKINamespace.New(pki.SelfSigned, "cluster-ca", pki.CA("Metropolis Cluster CA"))
63)