Skip to content

Commit

Permalink
new license fields (#14279)
Browse files Browse the repository at this point in the history
* new license fields

* remove monthly active users field from license
  • Loading branch information
NajiObeid authored Jul 21, 2022
1 parent ef7c36d commit 8a3e682
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/types/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ type License interface {
// SetSupportsResourceAccessRequests sets resource access requests support flag
SetSupportsResourceAccessRequests(Bool)

// GetTrial returns the trial flag
GetTrial() Bool
// SetTrial sets the trial flag
SetTrial(Bool)

// SetLabels sets metadata labels
SetLabels(labels map[string]string)

Expand Down Expand Up @@ -329,12 +334,25 @@ func (c *LicenseV3) SetSupportsResourceAccessRequests(value Bool) {
c.Spec.SupportsResourceAccessRequests = value
}

// GetTrial returns the trial flag
func (c *LicenseV3) GetTrial() Bool {
return c.Spec.Trial
}

// SetTrial sets the trial flag
func (c *LicenseV3) SetTrial(value Bool) {
c.Spec.Trial = value
}

// String represents a human readable version of license enabled features
func (c *LicenseV3) String() string {
var features []string
if !c.Expiry().IsZero() {
features = append(features, fmt.Sprintf("expires at %v", c.Expiry()))
}
if c.GetTrial() {
features = append(features, "is trial")
}
if c.GetReportsUsage() {
features = append(features, "reports usage")
}
Expand Down Expand Up @@ -401,4 +419,6 @@ type LicenseSpecV3 struct {
SupportsMachineID Bool `json:"machine_id,omitempty"`
// SupportsResourceAccessRequests turns resource access request support on or off
SupportsResourceAccessRequests Bool `json:"resource_access_requests,omitempty"`
// Trial is true for trial licenses
Trial Bool `json:"trial,omitempty"`
}
24 changes: 24 additions & 0 deletions api/types/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func TestLicenseSettersAndGetters(t *testing.T) {
License.GetSupportsDatabaseAccess,
License.GetSupportsDesktopAccess,
License.GetSupportsModeratedSessions,
License.GetSupportsMachineID,
License.GetSupportsResourceAccessRequests,
License.GetTrial,
}

// unsetFields returns a list of license fields getters minus
Expand Down Expand Up @@ -96,6 +99,24 @@ func TestLicenseSettersAndGetters(t *testing.T) {
getter: License.GetSupportsModeratedSessions,
unsetFields: unsetFields(License.GetSupportsModeratedSessions),
},
{
name: "Set Machine ID Support",
setter: License.SetSupportsMachineID,
getter: License.GetSupportsMachineID,
unsetFields: unsetFields(License.GetSupportsMachineID),
},
{
name: "Set Resource Access Request Support",
setter: License.SetSupportsResourceAccessRequests,
getter: License.GetSupportsResourceAccessRequests,
unsetFields: unsetFields(License.GetSupportsResourceAccessRequests),
},
{
name: "Set Trial Support",
setter: License.SetTrial,
getter: License.GetTrial,
unsetFields: unsetFields(License.GetTrial),
},
}

for _, tc := range tt {
Expand Down Expand Up @@ -123,6 +144,9 @@ func TestLicenseSettersAndGetters(t *testing.T) {
require.False(t, bool(license.GetSupportsDatabaseAccess()))
require.False(t, bool(license.GetSupportsDesktopAccess()))
require.False(t, bool(license.GetSupportsModeratedSessions()))
require.False(t, bool(license.GetSupportsMachineID()))
require.False(t, bool(license.GetSupportsResourceAccessRequests()))
require.False(t, bool(license.GetTrial()))
}

func fnName(i interface{}) string {
Expand Down

0 comments on commit 8a3e682

Please sign in to comment.