-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplatform.go
172 lines (154 loc) · 3.05 KB
/
platform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package gocommerce
import (
"context"
"errors"
"fmt"
"regexp"
"strings"
)
type (
DBConfig struct {
Host string
User string
Pass string
Name string
Prefix string
Port int
}
StoreConfig struct {
DB *DBConfig
AdminSlug string
}
Store struct {
DocRoot string
Platform PlatformInterface
Config *StoreConfig
}
basePlatform struct {
name string
configPath string
uniquePath string // A relative path that is sufficiently unique to identify a particular platform
}
PlatformInterface interface {
Name() string
ParseConfig(cfgPath string) (*StoreConfig, error)
Version(docroot string) (string, error)
BaseURLs(ctx context.Context, docroot string) ([]string, error)
ConfigPath() string
UniquePath() string
}
)
var AllPlatforms = []PlatformInterface{
&Magento1{
basePlatform{
"Magento 1",
"app/etc/local.xml",
"app/etc/local.xml",
},
"n98-magerun",
},
&Magento2{
basePlatform{
"Magento 2",
"app/etc/env.php",
"app/etc/env.php",
},
"n98-magerun2",
},
&Shopware5{
basePlatform{
"Shopware 5",
"config.php",
"engine/Shopware/Application.php",
},
},
&Shopware6{
basePlatform{
"Shopware 6",
".env",
"vendor/shopware/core/Framework/ShopwareException.php",
},
},
&Prestashop6{
basePlatform{
"Prestashop 6",
"config/settings.inc.php",
"config/settings.inc.php",
},
},
&Prestashop7{
basePlatform{
"Prestashop 7",
"app/config/parameters.php",
"app/config/parameters.php",
},
},
&WooCommerce{
basePlatform{
"WooCommerce",
"wp-config.php",
"wp-config.php",
},
},
&OpenCart4{
basePlatform{
"OpenCart 4",
"config.php",
"system/engine/config.php",
},
},
}
func (b *basePlatform) Name() string {
return b.name
}
func (b *basePlatform) ConfigPath() string {
return b.configPath
}
func (b *basePlatform) UniquePath() string {
return b.uniquePath
}
func (b *basePlatform) ParseConfig(_ string) (*StoreConfig, error) {
return nil, errors.New("not implemented")
}
func (b *basePlatform) BaseURLs(_ context.Context, _ string) ([]string, error) {
return nil, errors.New("not implemented")
}
func (b *basePlatform) Version(_ string) (string, error) {
return "", errors.New("not implemented")
}
func (c *DBConfig) DSN() string {
if c.User == "" || c.Name == "" {
return ""
}
host := c.Host
if host == "" {
host = "localhost"
}
port := c.Port
if port == 0 {
port = 3306
}
var network, address string
if strings.Contains(c.Host, "/") {
network = "unix"
address = c.Host
} else {
network = "tcp"
address = fmt.Sprintf("%s:%d", host, port)
}
// oldpasswords = Required for MySQL 4.0 servers, ugh...
return fmt.Sprintf("%s:%s@%s(%s)/%s?allowOldPasswords=true",
c.User,
c.Pass,
network,
address,
c.Name)
}
func (c *DBConfig) SafePrefix() (string, error) {
// prefix can only contain alphanum and underscores
re := regexp.MustCompile(`[^a-zA-Z0-9_]`)
if len(c.Prefix) > 0 && re.MatchString(c.Prefix) {
return "", fmt.Errorf("invalid database prefix: %s", c.Prefix)
}
return c.Prefix, nil
}