-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Implement license manager stub
- Loading branch information
Showing
8 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package licensemanager | ||
|
||
import ( | ||
"github.com/pion/logging" | ||
|
||
stnrv1 "github.com/l7mp/stunner/pkg/apis/v1" | ||
) | ||
|
||
var constructor = NewStub | ||
var _ Manager = &baseManager{} | ||
|
||
type Manager interface { | ||
Update(config *stnrv1.LicenseConfig) | ||
Close() | ||
Validate(feature string) bool | ||
GetTier() string | ||
GetConfig() *stnrv1.LicenseConfig | ||
Status() string | ||
} | ||
|
||
func New(log logging.LeveledLogger) Manager { | ||
return constructor(log) | ||
} | ||
|
||
// baseManager implements the basic functionality so that all license manager implementations can embed it | ||
type baseManager struct { | ||
config *stnrv1.LicenseConfig | ||
log logging.LeveledLogger | ||
} | ||
|
||
func newBaseManager(log logging.LeveledLogger) baseManager { | ||
m := baseManager{log: log} | ||
return m | ||
} | ||
|
||
func (m *baseManager) Update(config *stnrv1.LicenseConfig) { m.config = config } | ||
func (m *baseManager) Close() {} | ||
func (m *baseManager) Validate(feature string) bool { return false } | ||
func (m *baseManager) GetTier() string { return "<N/A>" } | ||
func (m *baseManager) GetConfig() *stnrv1.LicenseConfig { return m.config } | ||
func (m *baseManager) Status() string { return "<N/A>" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package licensemanager | ||
|
||
import ( | ||
"fmt" | ||
|
||
stnrv1 "github.com/l7mp/stunner/pkg/apis/v1" | ||
"github.com/pion/logging" | ||
) | ||
|
||
var _ Manager = &Stub{} | ||
|
||
// Stub is the default license manager that implements the free/open-source tier. | ||
type Stub struct{ baseManager } | ||
|
||
func NewStub(log logging.LeveledLogger) Manager { | ||
s := &Stub{baseManager: newBaseManager(log)} | ||
return s | ||
} | ||
|
||
func (s *Stub) Update(config *stnrv1.LicenseConfig) { | ||
s.log.Tracef("Licensing status update triggered using config %q", stnrv1.LicensingStatus(config)) | ||
s.baseManager.Update(config) | ||
} | ||
|
||
func (s *Stub) GetTier() string { return "free" } | ||
|
||
func (s *Stub) Status() string { | ||
return fmt.Sprintf("{tier=%q,conf=%s}", s.GetTier(), stnrv1.LicensingStatus(s.GetConfig())) | ||
} |