Skip to content

Commit

Permalink
adding time checking (ebauman#1)
Browse files Browse the repository at this point in the history
* added notAfter and notBefore checks

* ignoring golicense binary
  • Loading branch information
ebauman authored Feb 24, 2023
1 parent 84d992a commit 4950751
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
./golicense
*.pem
.idea/
.idea/
golicense
11 changes: 11 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
license2 "github.com/ebauman/golicense/pkg/license"
"github.com/ebauman/golicense/pkg/types"
"time"
)

func Blocking(licenseKey string, usages map[string]int, publicKeys []*rsa.PublicKey) types.LicensingResponse {
Expand All @@ -25,6 +26,16 @@ func Blocking(licenseKey string, usages map[string]int, publicKeys []*rsa.Public
return types.NewLicensingResponse(false, err)
}

// it's a license. is it expired?
if license.NotAfter.Before(time.Now()) {
return types.NewLicensingResponse(false, types.NewLicenseExpiredError())
}

// are we using it before we should?
if license.NotBefore.After(time.Now()) {
return types.NewLicensingResponse(false, types.NewLicenseNotYetValidError())
}

// valid license, check usages
for k, v := range usages {
// check to see if there is a grant for what we're trying to use
Expand Down
22 changes: 22 additions & 0 deletions pkg/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,25 @@ func (InvalidPublicKeysError) Error() string {
func NewInvalidPublicKeysError() InvalidPublicKeysError {
return InvalidPublicKeysError{}
}

type LicenseExpiredError struct {
}

func (LicenseExpiredError) Error() string {
return fmt.Sprintf("license expired")
}

func NewLicenseExpiredError() LicenseExpiredError {
return LicenseExpiredError{}
}

type LicenseNotYetValidError struct {
}

func (LicenseNotYetValidError) Error() string {
return fmt.Sprintf("license not yet valid")
}

func NewLicenseNotYetValidError() LicenseNotYetValidError {
return LicenseNotYetValidError{}
}

0 comments on commit 4950751

Please sign in to comment.