|
9 | 9 | "io"
|
10 | 10 | "net/http"
|
11 | 11 | "reflect"
|
| 12 | + "regexp" |
12 | 13 | "slices"
|
| 14 | + "strconv" |
13 | 15 | "strings"
|
14 | 16 | "sync"
|
15 | 17 | "time"
|
@@ -1569,17 +1571,26 @@ func (client *NginxClient) GetNginxInfo(ctx context.Context) (*NginxInfo, error)
|
1569 | 1571 |
|
1570 | 1572 | // GetNginxLicense returns Nginx License data with a context.
|
1571 | 1573 | func (client *NginxClient) GetNginxLicense(ctx context.Context) (*NginxLicense, error) {
|
1572 |
| - var info NginxLicense |
| 1574 | + var data NginxLicense |
1573 | 1575 |
|
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) |
1576 | 1583 | }
|
1577 | 1584 |
|
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) |
1579 | 1590 | if err != nil {
|
1580 | 1591 | return nil, fmt.Errorf("failed to get license: %w", err)
|
1581 | 1592 | }
|
1582 |
| - return &info, nil |
| 1593 | + return &data, nil |
1583 | 1594 | }
|
1584 | 1595 |
|
1585 | 1596 | // GetCaches returns Cache stats with a context.
|
@@ -2017,3 +2028,22 @@ func (client *NginxClient) GetWorkers(ctx context.Context) ([]*Workers, error) {
|
2017 | 2028 | }
|
2018 | 2029 | return workers, nil
|
2019 | 2030 | }
|
| 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