Skip to content

Commit 9492957

Browse files
committed
update to check if plus release is r33+
1 parent c6e0fbe commit 9492957

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

client/nginx.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"io"
1010
"net/http"
1111
"reflect"
12+
"regexp"
1213
"slices"
14+
"strconv"
1315
"strings"
1416
"sync"
1517
"time"
@@ -1569,17 +1571,26 @@ func (client *NginxClient) GetNginxInfo(ctx context.Context) (*NginxInfo, error)
15691571

15701572
// GetNginxLicense returns Nginx License data with a context.
15711573
func (client *NginxClient) GetNginxLicense(ctx context.Context) (*NginxLicense, error) {
1572-
var info NginxLicense
1574+
var data NginxLicense
15731575

1574-
if client.apiVersion < 9 {
1575-
return nil, fmt.Errorf("unsupported API version %v: %w by the client for the licensing endpoint", client.apiVersion, ErrNotSupported)
1576+
info, err := client.GetNginxInfo(ctx)
1577+
if err != nil {
1578+
return nil, fmt.Errorf("failed to get nginx info: %w", err)
1579+
}
1580+
release, err := extractPlusVersionValues(info.Build)
1581+
if err != nil {
1582+
return nil, fmt.Errorf("failed to get nginx plus release: %w", err)
15761583
}
15771584

1578-
err := client.get(ctx, "license", &info)
1585+
if (client.apiVersion < 9) || (release < 33) {
1586+
return &data, nil
1587+
}
1588+
1589+
err = client.get(ctx, "license", &data)
15791590
if err != nil {
15801591
return nil, fmt.Errorf("failed to get license: %w", err)
15811592
}
1582-
return &info, nil
1593+
return &data, nil
15831594
}
15841595

15851596
// GetCaches returns Cache stats with a context.
@@ -2017,3 +2028,22 @@ func (client *NginxClient) GetWorkers(ctx context.Context) ([]*Workers, error) {
20172028
}
20182029
return workers, nil
20192030
}
2031+
2032+
var rePlus = regexp.MustCompile(`-r(\d+)`)
2033+
2034+
// extractPlusVersionValues
2035+
func extractPlusVersionValues(input string) (int, error) {
2036+
var rValue int
2037+
matches := rePlus.FindStringSubmatch(input)
2038+
2039+
if len(matches) < 1 {
2040+
return 0, fmt.Errorf("no matches found in the input string")
2041+
}
2042+
2043+
rValue, err := strconv.Atoi(matches[1])
2044+
if err != nil {
2045+
return 0, fmt.Errorf("failed to convert rValue to integer: %w", err)
2046+
}
2047+
2048+
return rValue, nil
2049+
}

0 commit comments

Comments
 (0)