@@ -36,6 +36,15 @@ import (
36
36
"github.com/symfony-cli/symfony-cli/util"
37
37
)
38
38
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
+
39
48
func (l * Local ) relationshipsFromTunnel () Relationships {
40
49
projectRoot := util .RepositoryRootDir (l .Dir )
41
50
envID , err := util .PotentialCurrentEnvironmentID (projectRoot )
@@ -65,19 +74,19 @@ func (l *Local) relationshipsFromTunnel() Relationships {
65
74
}
66
75
return nil
67
76
}
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 )
79
89
}
80
- return nil
81
90
}
82
91
gitConfig := util .GetProjectConfig (projectRoot , l .Debug )
83
92
if gitConfig == nil {
@@ -87,7 +96,7 @@ func (l *Local) relationshipsFromTunnel() Relationships {
87
96
return nil
88
97
}
89
98
rels := make (Relationships )
90
- for _ , config := range tunnel {
99
+ for _ , config := range tunnels {
91
100
if config .ProjectID == gitConfig .ID && config .EnvironmentID == envID && config .AppName == app .Name {
92
101
config .Service ["port" ] = strconv .Itoa (config .LocalPort )
93
102
config .Service ["host" ] = "127.0.0.1"
@@ -132,6 +141,9 @@ func (t *Tunnel) Expose(expose bool) error {
132
141
}
133
142
134
143
if expose {
144
+ if err := os .MkdirAll (filepath .Dir (path ), 0755 ); err != nil {
145
+ return err
146
+ }
135
147
file , err := os .Create (path + "-expose" )
136
148
if err != nil {
137
149
return err
0 commit comments