1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 21:33:18 +01:00

fix: adds port and schema to connection again to fix clashes between same host. fixes #2279 (#2289)

* fix: adds port and schema to connection again to fix clashes between same host. fixes #2279

* fixes tests
This commit is contained in:
Amir Raminfar
2023-07-06 09:22:22 -07:00
committed by GitHub
parent e4ef784be7
commit 2c909dab09
10 changed files with 34 additions and 34 deletions

View File

@@ -16,7 +16,7 @@
<transition :name="sessionHost ? 'slide-left' : 'slide-right'" mode="out-in"> <transition :name="sessionHost ? 'slide-left' : 'slide-right'" mode="out-in">
<ul class="menu-list" v-if="!sessionHost"> <ul class="menu-list" v-if="!sessionHost">
<li v-for="host in config.hosts"> <li v-for="host in config.hosts">
<a @click.prevent="setHost(host.host)">{{ host.name }}</a> <a @click.prevent="setHost(host.id)">{{ host.name }}</a>
</li> </li>
</ul> </ul>
<ul class="menu-list" v-else> <ul class="menu-list" v-else>
@@ -88,10 +88,10 @@ const sortedContainers = computed(() =>
const hosts = computed(() => const hosts = computed(() =>
config.hosts.reduce( config.hosts.reduce(
(acc, item) => { (acc, item) => {
acc[item.host] = item; acc[item.id] = item;
return acc; return acc;
}, },
{} as Record<string, { name: string; host: string }>, {} as Record<string, { name: string; id: string }>,
), ),
); );

View File

@@ -33,7 +33,7 @@
</o-button> </o-button>
</template> </template>
<o-dropdown-item :value="value.host" aria-role="listitem" v-for="value in config.hosts" :key="value"> <o-dropdown-item :value="value.id" aria-role="listitem" v-for="value in config.hosts" :key="value">
<span>{{ value.name }}</span> <span>{{ value.name }}</span>
</o-dropdown-item> </o-dropdown-item>
</o-dropdown> </o-dropdown>
@@ -115,10 +115,10 @@ const sortedContainers = computed(() =>
const hosts = computed(() => const hosts = computed(() =>
config.hosts.reduce( config.hosts.reduce(
(acc, item) => { (acc, item) => {
acc[item.host] = item; acc[item.id] = item;
return acc; return acc;
}, },
{} as Record<string, { name: string; host: string }>, {} as Record<string, { name: string; id: string }>,
), ),
); );
</script> </script>

View File

@@ -3,7 +3,7 @@ import { Container } from "@/models/Container";
const sessionHost = useSessionStorage<string | null>("host", null); const sessionHost = useSessionStorage<string | null>("host", null);
if (config.hosts.length === 1 && !sessionHost.value) { if (config.hosts.length === 1 && !sessionHost.value) {
sessionHost.value = config.hosts[0].host; sessionHost.value = config.hosts[0].id;
} }
function persistentVisibleKeys(container: ComputedRef<Container>) { function persistentVisibleKeys(container: ComputedRef<Container>) {

View File

@@ -7,7 +7,7 @@ interface Config {
secured: boolean; secured: boolean;
maxLogs: number; maxLogs: number;
hostname: string; hostname: string;
hosts: { name: string; host: string }[]; hosts: { name: string; id: string }[];
} }
const pageConfig = JSON.parse(text); const pageConfig = JSON.parse(text);

View File

@@ -87,7 +87,7 @@ func NewClientWithFilters(f map[string][]string) (Client, error) {
return nil, err return nil, err
} }
return &dockerClient{cli, filterArgs, &Host{Name: "localhost", Host: "localhost"}}, nil return &dockerClient{cli, filterArgs, &Host{Name: "localhost", ID: "localhost"}}, nil
} }
func NewClientWithTlsAndFilter(f map[string][]string, host Host) (Client, error) { func NewClientWithTlsAndFilter(f map[string][]string, host Host) (Client, error) {
@@ -170,7 +170,7 @@ func (d *dockerClient) ListContainers() ([]Container, error) {
Created: c.Created, Created: c.Created,
State: c.State, State: c.State,
Status: c.Status, Status: c.Status,
Host: d.host.Host, Host: d.host.ID,
Health: findBetweenParentheses(c.Status), Health: findBetweenParentheses(c.Status),
} }
containers = append(containers, container) containers = append(containers, container)
@@ -287,7 +287,7 @@ func (d *dockerClient) Events(ctx context.Context, messages chan<- ContainerEven
messages <- ContainerEvent{ messages <- ContainerEvent{
ActorID: message.Actor.ID[:12], ActorID: message.Actor.ID[:12],
Name: message.Action, Name: message.Action,
Host: d.host.Host, Host: d.host.ID,
} }
} }
} }

View File

@@ -54,7 +54,7 @@ func (m *mockedProxy) ContainerStats(ctx context.Context, containerID string, st
func Test_dockerClient_ListContainers_null(t *testing.T) { func Test_dockerClient_ListContainers_null(t *testing.T) {
proxy := new(mockedProxy) proxy := new(mockedProxy)
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(nil, nil) proxy.On("ContainerList", mock.Anything, mock.Anything).Return(nil, nil)
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
list, err := client.ListContainers() list, err := client.ListContainers()
assert.Empty(t, list, "list should be empty") assert.Empty(t, list, "list should be empty")
@@ -66,7 +66,7 @@ func Test_dockerClient_ListContainers_null(t *testing.T) {
func Test_dockerClient_ListContainers_error(t *testing.T) { func Test_dockerClient_ListContainers_error(t *testing.T) {
proxy := new(mockedProxy) proxy := new(mockedProxy)
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(nil, errors.New("test")) proxy.On("ContainerList", mock.Anything, mock.Anything).Return(nil, errors.New("test"))
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
list, err := client.ListContainers() list, err := client.ListContainers()
assert.Nil(t, list, "list should be nil") assert.Nil(t, list, "list should be nil")
@@ -89,7 +89,7 @@ func Test_dockerClient_ListContainers_happy(t *testing.T) {
proxy := new(mockedProxy) proxy := new(mockedProxy)
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil) proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil)
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
list, err := client.ListContainers() list, err := client.ListContainers()
require.NoError(t, err, "error should not return an error.") require.NoError(t, err, "error should not return an error.")
@@ -129,7 +129,7 @@ func Test_dockerClient_ContainerLogs_happy(t *testing.T) {
json := types.ContainerJSON{Config: &container.Config{Tty: false}} json := types.ContainerJSON{Config: &container.Config{Tty: false}}
proxy.On("ContainerInspect", mock.Anything, id).Return(json, nil) proxy.On("ContainerInspect", mock.Anything, id).Return(json, nil)
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
logReader, _ := client.ContainerLogs(context.Background(), id, "since", STDALL) logReader, _ := client.ContainerLogs(context.Background(), id, "since", STDALL)
actual, _ := io.ReadAll(logReader) actual, _ := io.ReadAll(logReader)
@@ -150,7 +150,7 @@ func Test_dockerClient_ContainerLogs_happy_with_tty(t *testing.T) {
json := types.ContainerJSON{Config: &container.Config{Tty: true}} json := types.ContainerJSON{Config: &container.Config{Tty: true}}
proxy.On("ContainerInspect", mock.Anything, id).Return(json, nil) proxy.On("ContainerInspect", mock.Anything, id).Return(json, nil)
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
logReader, _ := client.ContainerLogs(context.Background(), id, "", STDALL) logReader, _ := client.ContainerLogs(context.Background(), id, "", STDALL)
actual, _ := io.ReadAll(logReader) actual, _ := io.ReadAll(logReader)
@@ -165,7 +165,7 @@ func Test_dockerClient_ContainerLogs_error(t *testing.T) {
proxy.On("ContainerLogs", mock.Anything, id, mock.Anything).Return(nil, errors.New("test")) proxy.On("ContainerLogs", mock.Anything, id, mock.Anything).Return(nil, errors.New("test"))
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
reader, err := client.ContainerLogs(context.Background(), id, "", STDALL) reader, err := client.ContainerLogs(context.Background(), id, "", STDALL)
@@ -188,7 +188,7 @@ func Test_dockerClient_FindContainer_happy(t *testing.T) {
proxy := new(mockedProxy) proxy := new(mockedProxy)
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil) proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil)
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
container, err := client.FindContainer("abcdefghijkl") container, err := client.FindContainer("abcdefghijkl")
require.NoError(t, err, "error should not be thrown") require.NoError(t, err, "error should not be thrown")
@@ -216,7 +216,7 @@ func Test_dockerClient_FindContainer_error(t *testing.T) {
proxy := new(mockedProxy) proxy := new(mockedProxy)
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil) proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil)
client := &dockerClient{proxy, filters.NewArgs(), &Host{Host: "localhost"}} client := &dockerClient{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
_, err := client.FindContainer("not_valid") _, err := client.FindContainer("not_valid")
require.Error(t, err, "error should be thrown") require.Error(t, err, "error should be thrown")

View File

@@ -11,7 +11,7 @@ import (
type Host struct { type Host struct {
Name string `json:"name"` Name string `json:"name"`
Host string `json:"host"` ID string `json:"id"`
URL *url.URL `json:"-"` URL *url.URL `json:"-"`
CertPath string `json:"-"` CertPath string `json:"-"`
CACertPath string `json:"-"` CACertPath string `json:"-"`
@@ -56,8 +56,8 @@ func ParseConnection(connection string) (Host, error) {
} }
return Host{ return Host{
ID: strings.ReplaceAll(remoteUrl.String(), "/", ""),
Name: name, Name: name,
Host: host,
URL: remoteUrl, URL: remoteUrl,
CertPath: certPath, CertPath: certPath,
CACertPath: cacertPath, CACertPath: cacertPath,

View File

@@ -141,7 +141,7 @@ func createClients(args args, localClientFactory func(map[string][]string) (dock
clients := make(map[string]docker.Client) clients := make(map[string]docker.Client)
if localClient := createLocalClient(args, localClientFactory); localClient != nil { if localClient := createLocalClient(args, localClientFactory); localClient != nil {
clients[localClient.Host().Host] = localClient clients[localClient.Host().ID] = localClient
} }
for _, remoteHost := range args.RemoteHost { for _, remoteHost := range args.RemoteHost {
@@ -154,12 +154,12 @@ func createClients(args args, localClientFactory func(map[string][]string) (dock
if client, err := remoteClientFactory(args.Filter, host); err == nil { if client, err := remoteClientFactory(args.Filter, host); err == nil {
if _, err := client.ListContainers(); err == nil { if _, err := client.ListContainers(); err == nil {
log.Debugf("Connected to local Docker Engine") log.Debugf("Connected to local Docker Engine")
clients[client.Host().Host] = client clients[client.Host().ID] = client
} else { } else {
log.Warnf("Could not connect to remote host %s: %s", host.Host, err) log.Warnf("Could not connect to remote host %s: %s", host.ID, err)
} }
} else { } else {
log.Warnf("Could not create client for %s: %s", host.Host, err) log.Warnf("Could not create client for %s: %s", host.ID, err)
} }
} }

View File

@@ -29,7 +29,7 @@ func Test_valid_localhost(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, nil) client.On("ListContainers").Return([]docker.Container{}, nil)
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "localhost", ID: "localhost",
}) })
return client, nil return client, nil
} }
@@ -46,7 +46,7 @@ func Test_invalid_localhost(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, errors.New("error")) client.On("ListContainers").Return([]docker.Container{}, errors.New("error"))
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "localhost", ID: "localhost",
}) })
return client, nil return client, nil
} }
@@ -63,7 +63,7 @@ func Test_valid_remote(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, errors.New("error")) client.On("ListContainers").Return([]docker.Container{}, errors.New("error"))
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "localhost", ID: "localhost",
}) })
return client, nil return client, nil
@@ -73,7 +73,7 @@ func Test_valid_remote(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, nil) client.On("ListContainers").Return([]docker.Container{}, nil)
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "test", ID: "test",
}) })
return client, nil return client, nil
} }
@@ -94,7 +94,7 @@ func Test_valid_remote_and_local(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, nil) client.On("ListContainers").Return([]docker.Container{}, nil)
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "localhost", ID: "localhost",
}) })
return client, nil return client, nil
} }
@@ -103,7 +103,7 @@ func Test_valid_remote_and_local(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, nil) client.On("ListContainers").Return([]docker.Container{}, nil)
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "test", ID: "test",
}) })
return client, nil return client, nil
} }
@@ -124,7 +124,7 @@ func Test_no_clients(t *testing.T) {
client := new(fakeClient) client := new(fakeClient)
client.On("ListContainers").Return([]docker.Container{}, errors.New("error")) client.On("ListContainers").Return([]docker.Container{}, errors.New("error"))
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "localhost", ID: "localhost",
}) })
return client, nil return client, nil
} }
@@ -132,7 +132,7 @@ func Test_no_clients(t *testing.T) {
fakeRemoteClientFactory := func(filter map[string][]string, host docker.Host) (docker.Client, error) { fakeRemoteClientFactory := func(filter map[string][]string, host docker.Host) (docker.Client, error) {
client := new(fakeClient) client := new(fakeClient)
client.On("Host").Return(&docker.Host{ client.On("Host").Return(&docker.Host{
Host: "test", ID: "test",
}) })
return client, nil return client, nil
} }

View File

@@ -59,7 +59,7 @@ func createHandler(client docker.Client, content fs.FS, config Config) *chi.Mux
client = new(MockedClient) client = new(MockedClient)
client.(*MockedClient).On("ListContainers").Return([]docker.Container{}, nil) client.(*MockedClient).On("ListContainers").Return([]docker.Container{}, nil)
client.(*MockedClient).On("Host").Return(&docker.Host{ client.(*MockedClient).On("Host").Return(&docker.Host{
Host: "localhost", ID: "localhost",
}) })
} }