This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
11 changed files
with
467 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ SMTP_HOST=localhost:1025 | |
SMTP_USER= | ||
SMTP_PASS= | ||
SMTP_FROM="Crust" <[email protected]> | ||
|
||
SUBSCRIPTION_KEY=E7ox7cDMmBzsFS15Ub43KKdbBg6gqOYiUhK3nRN0BlpNzt88mHLycahhVfrJCccc | ||
SUBSCRIPTION_DOMAIN=local.crust.tech |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,33 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/namsral/flag" | ||
) | ||
|
||
type ( | ||
Subscription struct { | ||
Key string | ||
Domain string | ||
} | ||
) | ||
|
||
var subscription *Subscription | ||
|
||
func (c *Subscription) Validate() error { | ||
if c == nil { | ||
return nil | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (*Subscription) Init(prefix ...string) *Subscription { | ||
if subscription != nil { | ||
return subscription | ||
} | ||
|
||
subscription = new(Subscription) | ||
flag.StringVar(&subscription.Key, "subscription-key", "", "Subscription key") | ||
flag.StringVar(&subscription.Domain, "subscription-domain", "", "Domain") | ||
return subscription | ||
} |
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,52 @@ | ||
package subscription | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/crusttech/permit/pkg/permit" | ||
) | ||
|
||
// Check for subscription | ||
func Check(ctx context.Context) error { | ||
p := permit.Permit{ | ||
Key: flags.subscription.Key, | ||
Domain: flags.subscription.Domain, | ||
} | ||
|
||
// Do not collect stats on local domains. | ||
// if p.Domain != "local.crust.tech" { | ||
// @todo collect & pass attributes (no of users....) to be validated by permit.crust.tech subscription server. | ||
p.Attributes = map[string]int{ | ||
"messaging.enabled": 1, | ||
// "messaging.max-public-channels": 1, | ||
// "messaging.max-messages": 1, | ||
// "messaging.max-users": 1, | ||
// "messaging.max-private-channels": 1, | ||
|
||
"system.enabled": 1, | ||
// "system.max-organisations": 1, | ||
// "system.max-users": 1, | ||
// "system.max-teams": 1, | ||
|
||
"compose.enabled": 1, | ||
// "compose.max-modules": 1, | ||
// "compose.max-pages": 1, | ||
// "compose.max-triggers": 1, | ||
// "compose.max-users": 1, | ||
// "compose.max-namespaces": 1, | ||
// "compose.max-charts": 1, | ||
} | ||
// } | ||
|
||
if p, err := permit.Check(ctx, p); err != nil { | ||
return errors.Wrap(err, "unable to check for licence") | ||
} else if !p.IsValid() { | ||
return err | ||
} else if p.Domain != flags.subscription.Domain { | ||
return errors.Errorf("subscription domains do not match (%s <> %s)", p.Domain, flags.subscription.Domain) | ||
} | ||
|
||
return nil | ||
} |
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,35 @@ | ||
package subscription | ||
|
||
import ( | ||
"github.com/crusttech/crust/internal/config" | ||
) | ||
|
||
type ( | ||
localFlags struct { | ||
subscription *config.Subscription | ||
} | ||
) | ||
|
||
var flags *localFlags | ||
|
||
// Flags matches signature for main() | ||
func Flags(prefix ...string) { | ||
new(localFlags).Init(prefix...) | ||
} | ||
|
||
func (f *localFlags) Validate() error { | ||
if err := f.subscription.Validate(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (f *localFlags) Init(prefix ...string) *localFlags { | ||
if flags != nil { | ||
return flags | ||
} | ||
flags = &localFlags{ | ||
new(config.Subscription).Init(prefix...), | ||
} | ||
return flags | ||
} |
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
Oops, something went wrong.