Skip to content

Commit 35cec57

Browse files
authored
Merge pull request #8 from symfony-cli/tunnel-fix
Fix tunnel support
2 parents 6aedca4 + 8a04d9e commit 35cec57

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

envs/local_tunnel.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ import (
3636
"github.com/symfony-cli/symfony-cli/util"
3737
)
3838

39+
type pshtunnel struct {
40+
EnvironmentID string `json:"environmentId"`
41+
AppName string `json:"appName"`
42+
ProjectID string `json:"projectId"`
43+
Relationship string `json:"relationship"`
44+
LocalPort int `json:"localPort"`
45+
Service map[string]interface{} `json:"service"`
46+
}
47+
3948
func (l *Local) relationshipsFromTunnel() Relationships {
4049
projectRoot := util.RepositoryRootDir(l.Dir)
4150
envID, err := util.PotentialCurrentEnvironmentID(projectRoot)
@@ -65,19 +74,19 @@ func (l *Local) relationshipsFromTunnel() Relationships {
6574
}
6675
return nil
6776
}
68-
var tunnel []struct {
69-
EnvironmentID string `json:"environmentId"`
70-
AppName string `json:"appName"`
71-
ProjectID string `json:"projectId"`
72-
Relationship string `json:"relationship"`
73-
LocalPort int `json:"localPort"`
74-
Service map[string]interface{} `json:"service"`
75-
}
76-
if err := json.Unmarshal(data, &tunnel); err != nil {
77-
if l.Debug {
78-
fmt.Fprintf(os.Stderr, "ERROR: unable to unmarshal tunnel data: %s\n", err)
77+
var tunnels []pshtunnel
78+
if err := json.Unmarshal(data, &tunnels); err != nil {
79+
// For some reasons, psh sometimes dump the tunnel file as a map
80+
var alttunnels map[string]pshtunnel
81+
if err := json.Unmarshal(data, &alttunnels); err != nil {
82+
if l.Debug {
83+
fmt.Fprintf(os.Stderr, "ERROR: unable to unmarshal tunnel data: %s: %s\n", tunnelFile, err)
84+
}
85+
return nil
86+
}
87+
for _, config := range alttunnels {
88+
tunnels = append(tunnels, config)
7989
}
80-
return nil
8190
}
8291
gitConfig := util.GetProjectConfig(projectRoot, l.Debug)
8392
if gitConfig == nil {
@@ -87,7 +96,7 @@ func (l *Local) relationshipsFromTunnel() Relationships {
8796
return nil
8897
}
8998
rels := make(Relationships)
90-
for _, config := range tunnel {
99+
for _, config := range tunnels {
91100
if config.ProjectID == gitConfig.ID && config.EnvironmentID == envID && config.AppName == app.Name {
92101
config.Service["port"] = strconv.Itoa(config.LocalPort)
93102
config.Service["host"] = "127.0.0.1"
@@ -132,6 +141,9 @@ func (t *Tunnel) Expose(expose bool) error {
132141
}
133142

134143
if expose {
144+
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
145+
return err
146+
}
135147
file, err := os.Create(path + "-expose")
136148
if err != nil {
137149
return err

0 commit comments

Comments
 (0)