Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ActiveDestination method to move into podman #1640

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,34 +1100,6 @@ func Reload() (*Config, error) {
return New(&Options{SetDefault: true})
}

func (c *Config) ActiveDestination() (uri, identity string, machine bool, err error) {
if uri, found := os.LookupEnv("CONTAINER_HOST"); found {
if v, found := os.LookupEnv("CONTAINER_SSHKEY"); found {
identity = v
}
return uri, identity, false, nil
}
connEnv := os.Getenv("CONTAINER_CONNECTION")
switch {
case connEnv != "":
d, found := c.Engine.ServiceDestinations[connEnv]
if !found {
return "", "", false, fmt.Errorf("environment variable CONTAINER_CONNECTION=%q service destination not found", connEnv)
}
return d.URI, d.Identity, d.IsMachine, nil

case c.Engine.ActiveService != "":
d, found := c.Engine.ServiceDestinations[c.Engine.ActiveService]
if !found {
return "", "", false, fmt.Errorf("%q service destination not found", c.Engine.ActiveService)
}
return d.URI, d.Identity, d.IsMachine, nil
case c.Engine.RemoteURI != "":
return c.Engine.RemoteURI, c.Engine.RemoteIdentity, false, nil
}
return "", "", false, errors.New("no service destination configured")
}

var (
bindirFailed = false
bindirCached = ""
Expand Down
125 changes: 0 additions & 125 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,131 +708,6 @@ image_copy_tmp_dir="storage"`
"/.ssh/id_rsa")
})

It("succeed ActiveDestinations()", func() {
cfg, err := ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg.Engine.ActiveService = "QA"
cfg.Engine.ServiceDestinations = map[string]Destination{
"QB": {
URI: "https://qb/run/podman/podman.sock",
Identity: "/.ssh/qb_id_rsa",
},
"QA": {
URI: "https://qa/run/podman/podman.sock",
Identity: "/.ssh/id_rsa",
},
}
err = cfg.Write()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg, err = ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

u, i, m, err := cfg.ActiveDestination()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

gomega.Expect(m).To(gomega.Equal(false))
gomega.Expect(u).To(gomega.Equal("https://qa/run/podman/podman.sock"))
gomega.Expect(i).To(gomega.Equal("/.ssh/id_rsa"))
})

It("succeed ActiveDestinations() CONTAINER_CONNECTION environment", func() {
cfg, err := ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg.Engine.ActiveService = "QA"
cfg.Engine.ServiceDestinations = map[string]Destination{
"QA": {
URI: "https://qa/run/podman/podman.sock",
Identity: "/.ssh/id_rsa",
},
"QB": {
URI: "https://qb/run/podman/podman.sock",
Identity: "/.ssh/qb_id_rsa",
},
}
err = cfg.Write()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg, err = ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

// Given we do
oldContainerConnection, hostEnvSet := os.LookupEnv("CONTAINER_CONNECTION")
os.Setenv("CONTAINER_CONNECTION", "QB")

u, i, m, err := cfg.ActiveDestination()
// Undo that
if hostEnvSet {
os.Setenv("CONTAINER_CONNECTION", oldContainerConnection)
} else {
os.Unsetenv("CONTAINER_CONNECTION")
}
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(m).To(gomega.Equal(false))

gomega.Expect(u).To(gomega.Equal("https://qb/run/podman/podman.sock"))
gomega.Expect(i).To(gomega.Equal("/.ssh/qb_id_rsa"))
})

It("succeed ActiveDestinations CONTAINER_HOST ()", func() {
cfg, err := ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg.Engine.ActiveService = "QA"
cfg.Engine.ServiceDestinations = map[string]Destination{
"QB": {
URI: "https://qb/run/podman/podman.sock",
Identity: "/.ssh/qb_id_rsa",
},
"QA": {
URI: "https://qa/run/podman/podman.sock",
Identity: "/.ssh/id_rsa",
},
}
err = cfg.Write()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg, err = ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

// Given we do
oldContainerHost, hostEnvSet := os.LookupEnv("CONTAINER_HOST")
oldContainerSSH, sshEnvSet := os.LookupEnv("CONTAINER_SSHKEY")
os.Setenv("CONTAINER_HOST", "foo.bar")
os.Setenv("CONTAINER_SSHKEY", "/.ssh/newid_rsa")

u, i, m, err := cfg.ActiveDestination()

// Undo that
if hostEnvSet {
os.Setenv("CONTAINER_HOST", oldContainerHost)
} else {
os.Unsetenv("CONTAINER_HOST")
}
// Undo that
if sshEnvSet {
os.Setenv("CONTAINER_SSHKEY", oldContainerSSH)
} else {
os.Unsetenv("CONTAINER_SSHKEY")
}

gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(m).To(gomega.Equal(false))

gomega.Expect(u).To(gomega.Equal("foo.bar"))
gomega.Expect(i).To(gomega.Equal("/.ssh/newid_rsa"))
})

It("fail ActiveDestination() no configuration", func() {
cfg, err := ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

_, _, _, err = cfg.ActiveDestination()
gomega.Expect(err).Should(gomega.HaveOccurred())
})

It("test addConfigs", func() {
tmpFilePath := func(dir, prefix string) string {
file, err := os.CreateTemp(dir, prefix)
Expand Down