services -> domains
This commit is contained in:
@@ -30,9 +30,9 @@ type Config struct {
|
||||
CredentialsDir string `yaml:"credentialsDir" json:"credentialsDir"`
|
||||
}
|
||||
|
||||
// PublicService describes a service that should be exposed through the tunnel.
|
||||
type PublicService struct {
|
||||
Name string // service name (used as subdomain)
|
||||
// PublicDomain describes a domain that should be exposed through the tunnel.
|
||||
type PublicDomain struct {
|
||||
Name string // domain name (used as subdomain)
|
||||
Subdomain string // explicit subdomain override (defaults to Name)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ type cloudflaredConfig struct {
|
||||
|
||||
// GenerateConfig renders the cloudflared config.yml for the given public services.
|
||||
// Returns the YAML string, or empty string if tunnel is not configured or no services are public.
|
||||
func (m *Manager) GenerateConfig(cfg Config, services []PublicService) string {
|
||||
func (m *Manager) GenerateConfig(cfg Config, services []PublicDomain) string {
|
||||
if !cfg.Enabled || cfg.TunnelID == "" || cfg.PublicDomain == "" || cfg.GatewayDomain == "" {
|
||||
return ""
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func (m *Manager) GenerateConfig(cfg Config, services []PublicService) string {
|
||||
}
|
||||
|
||||
// WriteConfig generates and writes the cloudflared config to disk.
|
||||
func (m *Manager) WriteConfig(cfg Config, services []PublicService) error {
|
||||
func (m *Manager) WriteConfig(cfg Config, services []PublicDomain) error {
|
||||
content := m.GenerateConfig(cfg, services)
|
||||
if content == "" {
|
||||
// Remove config if tunnel is disabled or no public services
|
||||
|
||||
@@ -20,7 +20,7 @@ func testConfig() Config {
|
||||
func TestGenerateConfig_Basic(t *testing.T) {
|
||||
m := NewManager(t.TempDir())
|
||||
|
||||
services := []PublicService{
|
||||
services := []PublicDomain{
|
||||
{Name: "my-api"},
|
||||
{Name: "dashboard"},
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func TestGenerateConfig_Basic(t *testing.T) {
|
||||
func TestGenerateConfig_SubdomainOverride(t *testing.T) {
|
||||
m := NewManager(t.TempDir())
|
||||
|
||||
services := []PublicService{
|
||||
services := []PublicDomain{
|
||||
{Name: "internal-name", Subdomain: "public-name"},
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestGenerateConfig_Disabled(t *testing.T) {
|
||||
cfg := testConfig()
|
||||
cfg.Enabled = false
|
||||
|
||||
out := m.GenerateConfig(cfg, []PublicService{{Name: "my-api"}})
|
||||
out := m.GenerateConfig(cfg, []PublicDomain{{Name: "my-api"}})
|
||||
if out != "" {
|
||||
t.Errorf("expected empty config when disabled, got:\n%s", out)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func TestGenerateConfig_MissingTunnelID(t *testing.T) {
|
||||
cfg := testConfig()
|
||||
cfg.TunnelID = ""
|
||||
|
||||
out := m.GenerateConfig(cfg, []PublicService{{Name: "my-api"}})
|
||||
out := m.GenerateConfig(cfg, []PublicDomain{{Name: "my-api"}})
|
||||
if out != "" {
|
||||
t.Errorf("expected empty config with missing tunnel ID, got:\n%s", out)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func TestWriteConfig(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
m := NewManager(tmpDir)
|
||||
|
||||
services := []PublicService{{Name: "my-api"}}
|
||||
services := []PublicDomain{{Name: "my-api"}}
|
||||
if err := m.WriteConfig(testConfig(), services); err != nil {
|
||||
t.Fatalf("WriteConfig failed: %v", err)
|
||||
}
|
||||
@@ -139,14 +139,14 @@ func TestWriteConfig_RemovesWhenDisabled(t *testing.T) {
|
||||
m := NewManager(tmpDir)
|
||||
|
||||
// Write config first
|
||||
if err := m.WriteConfig(testConfig(), []PublicService{{Name: "my-api"}}); err != nil {
|
||||
if err := m.WriteConfig(testConfig(), []PublicDomain{{Name: "my-api"}}); err != nil {
|
||||
t.Fatalf("WriteConfig failed: %v", err)
|
||||
}
|
||||
|
||||
// Now disable and write again — should remove the file
|
||||
cfg := testConfig()
|
||||
cfg.Enabled = false
|
||||
if err := m.WriteConfig(cfg, []PublicService{{Name: "my-api"}}); err != nil {
|
||||
if err := m.WriteConfig(cfg, []PublicDomain{{Name: "my-api"}}); err != nil {
|
||||
t.Fatalf("WriteConfig (disable) failed: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user