2021-04-06 18:19:59 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
|
|
|
)
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
type MeshConfigEntry struct {
|
2021-04-06 18:19:59 +00:00
|
|
|
// TransparentProxy contains cluster-wide options pertaining to TPROXY mode
|
|
|
|
// when enabled.
|
2021-04-28 22:13:29 +00:00
|
|
|
TransparentProxy TransparentProxyMeshConfig `alias:"transparent_proxy"`
|
2021-04-06 18:19:59 +00:00
|
|
|
|
|
|
|
Meta map[string]string `json:",omitempty"`
|
|
|
|
EnterpriseMeta `hcl:",squash" mapstructure:",squash"`
|
|
|
|
RaftIndex
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
// TransparentProxyMeshConfig contains cluster-wide options pertaining to
|
2021-04-06 18:19:59 +00:00
|
|
|
// TPROXY mode when enabled.
|
2021-04-28 22:13:29 +00:00
|
|
|
type TransparentProxyMeshConfig struct {
|
2021-04-06 18:19:59 +00:00
|
|
|
// CatalogDestinationsOnly can be used to disable the pass-through that
|
|
|
|
// allows traffic to destinations outside of the mesh.
|
|
|
|
CatalogDestinationsOnly bool `alias:"catalog_destinations_only"`
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) GetKind() string {
|
|
|
|
return MeshConfig
|
2021-04-06 18:19:59 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) GetName() string {
|
2021-04-06 18:19:59 +00:00
|
|
|
if e == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-04-29 19:54:27 +00:00
|
|
|
return MeshConfigMesh
|
2021-04-06 18:19:59 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) GetMeta() map[string]string {
|
2021-04-06 18:19:59 +00:00
|
|
|
if e == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return e.Meta
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) Normalize() error {
|
2021-04-06 18:19:59 +00:00
|
|
|
if e == nil {
|
|
|
|
return fmt.Errorf("config entry is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
e.EnterpriseMeta.Normalize()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) Validate() error {
|
2021-04-06 18:19:59 +00:00
|
|
|
if e == nil {
|
|
|
|
return fmt.Errorf("config entry is nil")
|
|
|
|
}
|
|
|
|
if err := validateConfigEntryMeta(e.Meta); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return e.validateEnterpriseMeta()
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) CanRead(authz acl.Authorizer) bool {
|
2021-04-06 18:19:59 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) CanWrite(authz acl.Authorizer) bool {
|
2021-04-06 18:19:59 +00:00
|
|
|
var authzContext acl.AuthorizerContext
|
|
|
|
e.FillAuthzContext(&authzContext)
|
|
|
|
return authz.OperatorWrite(&authzContext) == acl.Allow
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) GetRaftIndex() *RaftIndex {
|
2021-04-06 18:19:59 +00:00
|
|
|
if e == nil {
|
|
|
|
return &RaftIndex{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &e.RaftIndex
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
func (e *MeshConfigEntry) GetEnterpriseMeta() *EnterpriseMeta {
|
2021-04-06 18:19:59 +00:00
|
|
|
if e == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &e.EnterpriseMeta
|
|
|
|
}
|