1package api
2
3import "encoding/json"
4
5// ExportedServicesConfigEntry manages the exported services for a single admin partition.
6// Admin Partitions are a Consul Enterprise feature.
7type ExportedServicesConfigEntry struct {
8	// Name is the name of the partition the ExportedServicesConfigEntry applies to.
9	// Partitioning is a Consul Enterprise feature.
10	Name string `json:",omitempty"`
11
12	// Partition is the partition where the ExportedServicesConfigEntry is stored.
13	// If the partition does not match the name, the name will overwrite the partition.
14	// Partitioning is a Consul Enterprise feature.
15	Partition string `json:",omitempty"`
16
17	// Services is a list of services to be exported and the list of partitions
18	// to expose them to.
19	Services []ExportedService
20
21	Meta map[string]string `json:",omitempty"`
22
23	// CreateIndex is the Raft index this entry was created at. This is a
24	// read-only field.
25	CreateIndex uint64
26
27	// ModifyIndex is used for the Check-And-Set operations and can also be fed
28	// back into the WaitIndex of the QueryOptions in order to perform blocking
29	// queries.
30	ModifyIndex uint64
31}
32
33// ExportedService manages the exporting of a service in the local partition to
34// other partitions.
35type ExportedService struct {
36	// Name is the name of the service to be exported.
37	Name string
38
39	// Namespace is the namespace to export the service from.
40	Namespace string `json:",omitempty"`
41
42	// Consumers is a list of downstream consumers of the service to be exported.
43	Consumers []ServiceConsumer
44}
45
46// ServiceConsumer represents a downstream consumer of the service to be exported.
47type ServiceConsumer struct {
48	// Partition is the admin partition to export the service to.
49	Partition string
50}
51
52func (e *ExportedServicesConfigEntry) GetKind() string            { return ExportedServices }
53func (e *ExportedServicesConfigEntry) GetName() string            { return e.Name }
54func (e *ExportedServicesConfigEntry) GetPartition() string       { return e.Name }
55func (e *ExportedServicesConfigEntry) GetNamespace() string       { return IntentionDefaultNamespace }
56func (e *ExportedServicesConfigEntry) GetMeta() map[string]string { return e.Meta }
57func (e *ExportedServicesConfigEntry) GetCreateIndex() uint64     { return e.CreateIndex }
58func (e *ExportedServicesConfigEntry) GetModifyIndex() uint64     { return e.ModifyIndex }
59
60// MarshalJSON adds the Kind field so that the JSON can be decoded back into the
61// correct type.
62func (e *ExportedServicesConfigEntry) MarshalJSON() ([]byte, error) {
63	type Alias ExportedServicesConfigEntry
64	source := &struct {
65		Kind string
66		*Alias
67	}{
68		Kind:  ExportedServices,
69		Alias: (*Alias)(e),
70	}
71	return json.Marshal(source)
72}
73