Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 1 | // 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 | |
| 17 | package cluster |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | |
| 22 | "source.monogon.dev/metropolis/pkg/pki" |
| 23 | ) |
| 24 | |
| 25 | type ClusterState int |
| 26 | |
| 27 | const ( |
| 28 | ClusterUnknown ClusterState = iota |
| 29 | ClusterForeign |
| 30 | ClusterTrusted |
| 31 | ClusterHome |
| 32 | ClusterDisowning |
| 33 | ) |
| 34 | |
| 35 | type Cluster struct { |
| 36 | State ClusterState |
| 37 | } |
| 38 | |
| 39 | func (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 | |
| 53 | var clusterStateTransitions = map[ClusterState][]ClusterState{ |
| 54 | ClusterUnknown: {ClusterForeign, ClusterHome, ClusterDisowning}, |
| 55 | ClusterForeign: {ClusterTrusted}, |
| 56 | ClusterTrusted: {ClusterHome}, |
| 57 | ClusterHome: {ClusterHome, ClusterDisowning}, |
| 58 | } |
| 59 | |
| 60 | var ( |
| 61 | PKINamespace = pki.Namespaced("/cluster-pki/") |
| 62 | PKICA = PKINamespace.New(pki.SelfSigned, "cluster-ca", pki.CA("Metropolis Cluster CA")) |
| 63 | ) |