2022-02-11 10:49:06 +00:00
|
|
|
package orchestration
|
|
|
|
|
|
|
|
import (
|
2022-04-27 10:51:06 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/config"
|
2022-02-11 10:49:06 +00:00
|
|
|
"github.com/cloudflare/cloudflared/ingress"
|
|
|
|
)
|
|
|
|
|
2022-04-27 10:51:06 +00:00
|
|
|
type newRemoteConfig struct {
|
2022-02-11 10:49:06 +00:00
|
|
|
ingress.RemoteConfig
|
|
|
|
// Add more fields when we support other settings in tunnel orchestration
|
|
|
|
}
|
|
|
|
|
2022-04-27 10:51:06 +00:00
|
|
|
type newLocalConfig struct {
|
|
|
|
RemoteConfig ingress.RemoteConfig
|
|
|
|
ConfigurationFlags map[string]string `json:"__configuration_flags,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config is the original config as read and parsed by cloudflared.
|
2022-02-11 10:49:06 +00:00
|
|
|
type Config struct {
|
2022-06-13 16:44:27 +00:00
|
|
|
Ingress *ingress.Ingress
|
|
|
|
WarpRouting ingress.WarpRoutingConfig
|
2022-04-27 10:51:06 +00:00
|
|
|
|
|
|
|
// Extra settings used to configure this instance but that are not eligible for remotely management
|
|
|
|
// ie. (--protocol, --loglevel, ...)
|
|
|
|
ConfigurationFlags map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rc *newLocalConfig) MarshalJSON() ([]byte, error) {
|
|
|
|
var r = struct {
|
|
|
|
ConfigurationFlags map[string]string `json:"__configuration_flags,omitempty"`
|
|
|
|
ingress.RemoteConfigJSON
|
|
|
|
}{
|
|
|
|
ConfigurationFlags: rc.ConfigurationFlags,
|
|
|
|
RemoteConfigJSON: ingress.RemoteConfigJSON{
|
|
|
|
// UI doesn't support top level configs, so we reconcile to individual ingress configs.
|
|
|
|
GlobalOriginRequest: nil,
|
|
|
|
IngressRules: convertToUnvalidatedIngressRules(rc.RemoteConfig.Ingress),
|
2022-06-13 16:44:27 +00:00
|
|
|
WarpRouting: rc.RemoteConfig.WarpRouting.RawConfig(),
|
2022-04-27 10:51:06 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertToUnvalidatedIngressRules(i ingress.Ingress) []config.UnvalidatedIngressRule {
|
|
|
|
result := make([]config.UnvalidatedIngressRule, 0)
|
|
|
|
for _, rule := range i.Rules {
|
|
|
|
var path string
|
|
|
|
if rule.Path != nil {
|
|
|
|
path = rule.Path.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
newRule := config.UnvalidatedIngressRule{
|
|
|
|
Hostname: rule.Hostname,
|
|
|
|
Path: path,
|
|
|
|
Service: rule.Service.String(),
|
|
|
|
OriginRequest: ingress.ConvertToRawOriginConfig(rule.Config),
|
|
|
|
}
|
|
|
|
|
|
|
|
result = append(result, newRule)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
2022-02-11 10:49:06 +00:00
|
|
|
}
|