mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-13 08:34:44 +08:00
handle invite link for saas tenants
This commit is contained in:
parent
e8e795ce3c
commit
d4af26b289
5 changed files with 38 additions and 26 deletions
|
@ -217,6 +217,14 @@ func inviteUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
slog.Error("failed to parse to invite url", "error", err)
|
slog.Error("failed to parse to invite url", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if servercfg.DeployedByOperator() {
|
||||||
|
u, err = url.Parse(fmt.Sprintf("%s/invite?tenant_id=%s&email=%s&invite_code=%s",
|
||||||
|
proLogic.GetAccountsHost(), url.QueryEscape(servercfg.GetNetmakerTenantID()), url.QueryEscape(invite.Email), url.QueryEscape(invite.InviteCode)))
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("failed to parse to invite url", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
invite.InviteURL = u.String()
|
invite.InviteURL = u.String()
|
||||||
err = logic.InsertUserInvite(invite)
|
err = logic.InsertUserInvite(invite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"github.com/gravitl/netmaker/logic"
|
"github.com/gravitl/netmaker/logic"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||||
|
proLogic "github.com/gravitl/netmaker/pro/logic"
|
||||||
"github.com/gravitl/netmaker/servercfg"
|
"github.com/gravitl/netmaker/servercfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ func validateLicenseKey(encryptedData []byte, publicKey *[32]byte) ([]byte, bool
|
||||||
|
|
||||||
req, err := http.NewRequest(
|
req, err := http.NewRequest(
|
||||||
http.MethodPost,
|
http.MethodPost,
|
||||||
getAccountsHost()+"/api/v1/license/validate",
|
proLogic.GetAccountsHost()+"/api/v1/license/validate",
|
||||||
bytes.NewReader(requestBody),
|
bytes.NewReader(requestBody),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -255,17 +256,6 @@ func validateLicenseKey(encryptedData []byte, publicKey *[32]byte) ([]byte, bool
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAccountsHost() string {
|
|
||||||
switch servercfg.GetEnvironment() {
|
|
||||||
case "dev":
|
|
||||||
return accountsHostDevelopment
|
|
||||||
case "staging":
|
|
||||||
return accountsHostStaging
|
|
||||||
default:
|
|
||||||
return accountsHostProduction
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cacheResponse(response []byte) error {
|
func cacheResponse(response []byte) error {
|
||||||
lrc := licenseResponseCache{
|
lrc := licenseResponseCache{
|
||||||
Body: response,
|
Body: response,
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
package pro
|
package pro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gravitl/netmaker/config"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gravitl/netmaker/config"
|
||||||
|
proLogic "github.com/gravitl/netmaker/pro/logic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_getAccountsHost(t *testing.T) {
|
func Test_GetAccountsHost(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
envK string
|
envK string
|
||||||
|
@ -69,8 +71,8 @@ func Test_getAccountsHost(t *testing.T) {
|
||||||
if tt.envK != "" {
|
if tt.envK != "" {
|
||||||
t.Setenv(tt.envK, tt.envV)
|
t.Setenv(tt.envK, tt.envV)
|
||||||
}
|
}
|
||||||
if got := getAccountsHost(); got != tt.want {
|
if got := proLogic.GetAccountsHost(); got != tt.want {
|
||||||
t.Errorf("getAccountsHost() = %v, want %v", got, tt.want)
|
t.Errorf("GetAccountsHost() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,17 @@ import (
|
||||||
"github.com/gravitl/netmaker/logger"
|
"github.com/gravitl/netmaker/logger"
|
||||||
"github.com/gravitl/netmaker/logic"
|
"github.com/gravitl/netmaker/logic"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
|
"github.com/gravitl/netmaker/servercfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
// constants for accounts api hosts
|
||||||
|
const (
|
||||||
|
// accountsHostDevelopment is the accounts api host for development environment
|
||||||
|
accountsHostDevelopment = "https://api.dev.accounts.netmaker.io"
|
||||||
|
// accountsHostStaging is the accounts api host for staging environment
|
||||||
|
accountsHostStaging = "https://api.staging.accounts.netmaker.io"
|
||||||
|
// accountsHostProduction is the accounts api host for production environment
|
||||||
|
accountsHostProduction = "https://api.accounts.netmaker.io"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NetworkPermissionsCheck(username string, r *http.Request) error {
|
func NetworkPermissionsCheck(username string, r *http.Request) error {
|
||||||
|
@ -193,3 +204,14 @@ func checkPermissionScopeWithReqMethod(scope models.RsrcPermissionScope, reqmeth
|
||||||
}
|
}
|
||||||
return errors.New("operation not permitted")
|
return errors.New("operation not permitted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAccountsHost() string {
|
||||||
|
switch servercfg.GetEnvironment() {
|
||||||
|
case "dev":
|
||||||
|
return accountsHostDevelopment
|
||||||
|
case "staging":
|
||||||
|
return accountsHostStaging
|
||||||
|
default:
|
||||||
|
return accountsHostProduction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
10
pro/types.go
10
pro/types.go
|
@ -7,16 +7,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// constants for accounts api hosts
|
|
||||||
const (
|
|
||||||
// accountsHostDevelopment is the accounts api host for development environment
|
|
||||||
accountsHostDevelopment = "https://api.dev.accounts.netmaker.io"
|
|
||||||
// accountsHostStaging is the accounts api host for staging environment
|
|
||||||
accountsHostStaging = "https://api.staging.accounts.netmaker.io"
|
|
||||||
// accountsHostProduction is the accounts api host for production environment
|
|
||||||
accountsHostProduction = "https://api.accounts.netmaker.io"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
license_cache_key = "license_response_cache"
|
license_cache_key = "license_response_cache"
|
||||||
license_validation_err_msg = "invalid license"
|
license_validation_err_msg = "invalid license"
|
||||||
|
|
Loading…
Add table
Reference in a new issue