Skip to content

Commit

Permalink
Pass license-proxyserver as user-agent
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Jan 17, 2025
1 parent 808ca56 commit 8c94a3f
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.75.2
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
go.bytebuilders.dev/license-verifier v0.14.4
go.bytebuilders.dev/license-verifier v0.14.6-0.20250117071237-f0e5c4336c32
gocloud.dev v0.26.0
gomodules.xyz/blobfs v0.1.14
gomodules.xyz/cert v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.bytebuilders.dev/license-verifier v0.14.4 h1:JwTGQFew4nudwv8Pk3BdfQRts8KfgUQ5xhu138w1wt4=
go.bytebuilders.dev/license-verifier v0.14.4/go.mod h1:LqWXJKee5ofDcCYM6T5WilYlUc4NlKeZz58tHwO8GEs=
go.bytebuilders.dev/license-verifier v0.14.6-0.20250117071237-f0e5c4336c32 h1:RctiY8mbN/99ygVfgRkwWsu1SvhUvgjjxwz82QuRaF0=
go.bytebuilders.dev/license-verifier v0.14.6-0.20250117071237-f0e5c4336c32/go.mod h1:LqWXJKee5ofDcCYM6T5WilYlUc4NlKeZz58tHwO8GEs=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
Expand Down
8 changes: 7 additions & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
pc "go.bytebuilders.dev/license-verifier/client"
"go.bytebuilders.dev/license-verifier/info"

v "gomodules.xyz/x/version"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -190,7 +191,12 @@ func (c completedConfig) New(ctx context.Context) (*LicenseProxyServer, error) {
if c.ExtraConfig.Token == "" {
return nil, fmt.Errorf("missing --token")
}
lc, err = licenseclient.NewClient(c.ExtraConfig.BaseURL, c.ExtraConfig.Token, cid, c.ExtraConfig.CACert, c.ExtraConfig.InsecureSkipTLSVerify)
lc, err = licenseclient.NewClient(
c.ExtraConfig.BaseURL,
c.ExtraConfig.Token, cid,
c.ExtraConfig.CACert,
c.ExtraConfig.InsecureSkipTLSVerify,
fmt.Sprintf("license-proxyserver/%s", v.Version.Version))
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ limitations under the License.
package v1alpha1

func (l License) DisableAnalytics() bool {
return len(l.FeatureFlags) > 0 && l.FeatureFlags["DisableAnalytics"] == "true"
return len(l.FeatureFlags) > 0 && l.FeatureFlags[FeatureDisableAnalytics] == "true"
}

func (l License) EnableClientBilling() bool {
return len(l.FeatureFlags) > 0 && l.FeatureFlags[FeatureEnableClientBilling] == "true"
}

func (i *License) Less(j *License) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ limitations under the License.
package v1alpha1

import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -26,20 +30,20 @@ import (
type License struct {
metav1.TypeMeta `json:",inline,omitempty"`

Data []byte `json:"-"`
Issuer string `json:"issuer,omitempty"` // byte.builders
ProductLine string `json:"productLine,omitempty"`
TierName string `json:"tierName,omitempty"`
PlanName string `json:"planName,omitempty"`
Features []string `json:"features,omitempty"`
FeatureFlags map[string]string `json:"featureFlags,omitempty"`
Clusters []string `json:"clusters,omitempty"` // cluster_id ?
User *User `json:"user,omitempty"`
NotBefore *metav1.Time `json:"notBefore,omitempty"` // start of subscription start
NotAfter *metav1.Time `json:"notAfter,omitempty"` // if set, use this
ID string `json:"id,omitempty"` // license ID
Status LicenseStatus `json:"status"`
Reason string `json:"reason"`
Data []byte `json:"-"`
Issuer string `json:"issuer,omitempty"` // byte.builders
ProductLine string `json:"productLine,omitempty"`
TierName string `json:"tierName,omitempty"`
PlanName string `json:"planName,omitempty"`
Features []string `json:"features,omitempty"`
FeatureFlags FeatureFlags `json:"featureFlags,omitempty"`
Clusters []string `json:"clusters,omitempty"` // cluster_id ?
User *User `json:"user,omitempty"`
NotBefore *metav1.Time `json:"notBefore,omitempty"` // start of subscription start
NotAfter *metav1.Time `json:"notAfter,omitempty"` // if set, use this
ID string `json:"id,omitempty"` // license ID
Status LicenseStatus `json:"status"`
Reason string `json:"reason"`
}

type User struct {
Expand All @@ -62,3 +66,36 @@ type Contract struct {
StartTimestamp metav1.Time `json:"startTimestamp"`
ExpiryTimestamp metav1.Time `json:"expiryTimestamp"`
}

type FeatureFlag string

const (
FeatureDisableAnalytics FeatureFlag = "DisableAnalytics"
FeatureRestrictions FeatureFlag = "Restrictions"
FeatureEnableClientBilling FeatureFlag = "EnableClientBilling"
)

var knownFlags = sets.New[FeatureFlag](FeatureDisableAnalytics, FeatureRestrictions, FeatureEnableClientBilling)

type FeatureFlags map[FeatureFlag]string

func (f FeatureFlags) IsValid() error {
var errs []error
for k := range f {
if !knownFlags.Has(k) {
errs = append(errs, fmt.Errorf("unknown feature flag %q", k))
}
}
return errors.NewAggregate(errs)
}

func (f FeatureFlags) ToSlice() []string {
if len(f) == 0 {
return nil
}
result := make([]string, 0, len(f))
for k, v := range f {
result = append(result, fmt.Sprintf("%s=%s", k, v))
}
return result
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/go.bytebuilders.dev/license-verifier/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ type Client struct {
clusterUID string
caCert []byte
client *http.Client
userAgent string
}

func NewClient(baseURL, token, clusterUID string, caCert []byte, insecureSkipVerifyTLS bool) (*Client, error) {
func NewClient(baseURL, token, clusterUID string, caCert []byte, insecureSkipVerifyTLS bool, userAgent string) (*Client, error) {
u, err := info.LicenseIssuerAPIEndpoint(baseURL)
if err != nil {
return nil, err
Expand All @@ -54,6 +55,7 @@ func NewClient(baseURL, token, clusterUID string, caCert []byte, insecureSkipVer
token: token,
clusterUID: clusterUID,
client: http.DefaultClient,
userAgent: userAgent,
}
if len(caCert) > 0 || insecureSkipVerifyTLS {
tlsConfig := &tls.Config{
Expand Down Expand Up @@ -87,6 +89,9 @@ func (c *Client) AcquireLicense(features []string) ([]byte, *v1alpha1.Contract,
return nil, nil, err
}
req.Header.Set("Content-Type", "application/json")
if c.userAgent != "" {
req.Header.Set("User-Agent", c.userAgent)
}
// add authorization header to the req
if c.token != "" {
req.Header.Add("Authorization", "Bearer "+c.token)
Expand Down
4 changes: 2 additions & 2 deletions vendor/go.bytebuilders.dev/license-verifier/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func ParseLicense(opts ParserOptions) (v1alpha1.License, error) {
license.TierName = parts[1]
}
}
license.FeatureFlags = map[string]string{}
license.FeatureFlags = v1alpha1.FeatureFlags{}
for _, ff := range cert.Subject.Locality {
parts := strings.SplitN(ff, "=", 2)
if len(parts) == 2 {
license.FeatureFlags[parts[0]] = parts[1]
license.FeatureFlags[v1alpha1.FeatureFlag(parts[0])] = parts[1]
}
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ github.com/yudai/golcs
# github.com/zeebo/xxh3 v1.0.2
## explicit; go 1.17
github.com/zeebo/xxh3
# go.bytebuilders.dev/license-verifier v0.14.4
# go.bytebuilders.dev/license-verifier v0.14.6-0.20250117071237-f0e5c4336c32
## explicit; go 1.21
go.bytebuilders.dev/license-verifier
go.bytebuilders.dev/license-verifier/apis/licenses
Expand Down

0 comments on commit 8c94a3f

Please sign in to comment.