Skip to content

Commit 8287e27

Browse files
Add latestPluginVersionV2 to security.json (#22)
* feat: add latestPluginVersionV2 to security.json This commit introduces a new field `latestPluginVersionV2` to the `security.json` file. This field contains a map of the latest compatible security plugin version for Shopware 6.4, 6.5, 6.6, and 6.7. The version is dynamically determined by finding the latest tag for each major.minor version and querying the Shopware Plugin Store API. The existing `latestPluginVersion` field is preserved with its original logic. * feat: add latestPluginVersionV2 to security.json This commit introduces a new field `latestPluginVersionV2` to the `security.json` file. This field contains a map of the latest compatible security plugin version for Shopware 6.4, 6.5, 6.6, and 6.7. The version is dynamically determined by finding the latest tag for each major.minor version and querying the Shopware Plugin Store API. The existing `latestPluginVersion` field is preserved with its original logic. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 77aeaf0 commit 8287e27

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

data/security.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"latestPluginVersion": "1.0.39",
3+
"latestPluginVersionV2": {
4+
"6.4": "1.0.39",
5+
"6.5": "2.0.15",
6+
"6.6": "3.0.11",
7+
"6.7": "4.0.5"
8+
},
39
"advisories": {
410
"PKSA-1twh-tt7h-ds25": {
511
"title": "Leak of information via Store-API aggregations in shopware/platform and shopware/core",

security.go

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"net/http"
1111
"os"
12+
"strings"
1213
)
1314

1415
type packagistSecurityResponse struct {
@@ -39,16 +40,30 @@ func generateSecurityAdvisories(ctx context.Context, tags []*github.RepositoryTa
3940
return err
4041
}
4142

42-
latestVersion, err := getSecurityPluginLatestVersion(ctx)
43+
latestVersion, err := getSecurityPluginLatestVersion(ctx, "6.4.14.0")
4344

4445
if err != nil {
4546
return err
4647
}
4748

4849
fileStruct := securityFile{
49-
LatestPluginVersion: latestVersion,
50-
Advisories: make(map[string]advisories),
51-
VersionToAdvisories: make(map[string][]string),
50+
LatestPluginVersion: latestVersion,
51+
LatestPluginVersionV2: make(map[string]string),
52+
Advisories: make(map[string]advisories),
53+
VersionToAdvisories: make(map[string][]string),
54+
}
55+
56+
for _, v := range []string{"6.7", "6.6", "6.5", "6.4"} {
57+
latest, err := findLatestVersion(tags, v)
58+
if err != nil {
59+
return err
60+
}
61+
62+
pluginVer, err := getSecurityPluginLatestVersion(ctx, latest)
63+
if err != nil {
64+
return err
65+
}
66+
fileStruct.LatestPluginVersionV2[v] = pluginVer
5267
}
5368

5469
for _, advisory := range packagistAdvisories.Advisories.ShopwarePlatform {
@@ -129,8 +144,8 @@ type shopwareApiResponse []struct {
129144
Version string `json:"version"`
130145
}
131146

132-
func getSecurityPluginLatestVersion(ctx context.Context) (string, error) {
133-
r, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.shopware.com/pluginStore/pluginsByName?locale=en-GB&shopwareVersion=6.4.14.0&technicalNames%5B0%5D=SwagPlatformSecurity", nil)
147+
func getSecurityPluginLatestVersion(ctx context.Context, shopwareVersion string) (string, error) {
148+
r, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://api.shopware.com/pluginStore/pluginsByName?locale=en-GB&shopwareVersion=%s&technicalNames%%5B0%%5D=SwagPlatformSecurity", shopwareVersion), nil)
134149

135150
if err != nil {
136151
return "", err
@@ -166,3 +181,31 @@ func getSecurityPluginLatestVersion(ctx context.Context) (string, error) {
166181

167182
return apiResponse[0].Version, nil
168183
}
184+
185+
func findLatestVersion(tags []*github.RepositoryTag, prefix string) (string, error) {
186+
var latestVer *version.Version
187+
var latestTagName string
188+
189+
for _, tag := range tags {
190+
name := tag.GetName()
191+
if !strings.HasPrefix(name, "v"+prefix) {
192+
continue
193+
}
194+
195+
v, err := version.NewVersion(name)
196+
if err != nil {
197+
continue
198+
}
199+
200+
if latestVer == nil || v.GreaterThan(latestVer) {
201+
latestVer = v
202+
latestTagName = name
203+
}
204+
}
205+
206+
if latestVer == nil {
207+
return "", fmt.Errorf("cannot find latest version for prefix %s", prefix)
208+
}
209+
210+
return strings.TrimPrefix(latestTagName, "v"), nil
211+
}

types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package main
22

33
type securityFile struct {
4-
LatestPluginVersion string `json:"latestPluginVersion"`
5-
Advisories map[string]advisories `json:"advisories"`
6-
VersionToAdvisories map[string][]string `json:"versionToAdvisories"`
4+
LatestPluginVersion string `json:"latestPluginVersion"`
5+
LatestPluginVersionV2 map[string]string `json:"latestPluginVersionV2"`
6+
Advisories map[string]advisories `json:"advisories"`
7+
VersionToAdvisories map[string][]string `json:"versionToAdvisories"`
78
}
89

910
type advisories struct {

0 commit comments

Comments
 (0)