2021-12-31 11:54:22 +00:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2022-05-24 07:12:29 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2021-12-31 11:54:22 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
2022-05-30 03:49:55 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
2022-01-22 19:54:41 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/token"
|
2021-12-31 11:54:22 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/utils"
|
|
|
|
)
|
|
|
|
|
2022-01-17 07:42:46 +00:00
|
|
|
// EnvResolver is a resolver for config query
|
2022-01-17 06:02:13 +00:00
|
|
|
// This is admin only query
|
2022-01-17 07:42:46 +00:00
|
|
|
func EnvResolver(ctx context.Context) (*model.Env, error) {
|
|
|
|
var res *model.Env
|
2021-12-31 11:54:22 +00:00
|
|
|
|
2022-05-24 07:12:29 +00:00
|
|
|
gc, err := utils.GinContextFromContext(ctx)
|
2021-12-31 11:54:22 +00:00
|
|
|
if err != nil {
|
2022-05-25 07:00:22 +00:00
|
|
|
log.Debug("Failed to get GinContext: ", err)
|
2021-12-31 11:54:22 +00:00
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2022-01-22 19:54:41 +00:00
|
|
|
if !token.IsSuperAdmin(gc) {
|
2022-05-24 07:12:29 +00:00
|
|
|
log.Debug("Not logged in as super admin.")
|
2021-12-31 11:54:22 +00:00
|
|
|
return res, fmt.Errorf("unauthorized")
|
|
|
|
}
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
// get clone of store
|
2022-05-30 03:49:55 +00:00
|
|
|
store, err := memorystore.Provider.GetEnvStore()
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("Failed to get env store: ", err)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
accessTokenExpiryTime := store[constants.EnvKeyAccessTokenExpiryTime].(string)
|
|
|
|
adminSecret := store[constants.EnvKeyAdminSecret].(string)
|
|
|
|
clientID := store[constants.EnvKeyClientID].(string)
|
|
|
|
clientSecret := store[constants.EnvKeyClientSecret].(string)
|
|
|
|
databaseURL := store[constants.EnvKeyDatabaseURL].(string)
|
|
|
|
databaseName := store[constants.EnvKeyDatabaseName].(string)
|
|
|
|
databaseType := store[constants.EnvKeyDatabaseType].(string)
|
|
|
|
databaseUsername := store[constants.EnvKeyDatabaseUsername].(string)
|
|
|
|
databasePassword := store[constants.EnvKeyDatabasePassword].(string)
|
|
|
|
databaseHost := store[constants.EnvKeyDatabaseHost].(string)
|
|
|
|
databasePort := store[constants.EnvKeyDatabasePort].(string)
|
|
|
|
customAccessTokenScript := store[constants.EnvKeyCustomAccessTokenScript].(string)
|
|
|
|
smtpHost := store[constants.EnvKeySmtpHost].(string)
|
|
|
|
smtpPort := store[constants.EnvKeySmtpPort].(string)
|
|
|
|
smtpUsername := store[constants.EnvKeySmtpUsername].(string)
|
|
|
|
smtpPassword := store[constants.EnvKeySmtpPassword].(string)
|
|
|
|
senderEmail := store[constants.EnvKeySenderEmail].(string)
|
|
|
|
jwtType := store[constants.EnvKeyJwtType].(string)
|
|
|
|
jwtSecret := store[constants.EnvKeyJwtSecret].(string)
|
|
|
|
jwtRoleClaim := store[constants.EnvKeyJwtRoleClaim].(string)
|
|
|
|
jwtPublicKey := store[constants.EnvKeyJwtPublicKey].(string)
|
|
|
|
jwtPrivateKey := store[constants.EnvKeyJwtPrivateKey].(string)
|
|
|
|
appURL := store[constants.EnvKeyAppURL].(string)
|
|
|
|
redisURL := store[constants.EnvKeyRedisURL].(string)
|
|
|
|
resetPasswordURL := store[constants.EnvKeyResetPasswordURL].(string)
|
|
|
|
googleClientID := store[constants.EnvKeyGoogleClientID].(string)
|
|
|
|
googleClientSecret := store[constants.EnvKeyGoogleClientSecret].(string)
|
|
|
|
facebookClientID := store[constants.EnvKeyFacebookClientID].(string)
|
|
|
|
facebookClientSecret := store[constants.EnvKeyFacebookClientSecret].(string)
|
|
|
|
githubClientID := store[constants.EnvKeyGithubClientID].(string)
|
|
|
|
githubClientSecret := store[constants.EnvKeyGithubClientSecret].(string)
|
|
|
|
organizationName := store[constants.EnvKeyOrganizationName].(string)
|
|
|
|
organizationLogo := store[constants.EnvKeyOrganizationLogo].(string)
|
|
|
|
|
|
|
|
// string slice vars
|
|
|
|
allowedOrigins := utils.ConvertInterfaceToStringSlice(store[constants.EnvKeyAllowedOrigins])
|
|
|
|
roles := utils.ConvertInterfaceToStringSlice(store[constants.EnvKeyRoles])
|
|
|
|
defaultRoles := utils.ConvertInterfaceToStringSlice(store[constants.EnvKeyDefaultRoles])
|
|
|
|
protectedRoles := utils.ConvertInterfaceToStringSlice(store[constants.EnvKeyProtectedRoles])
|
|
|
|
|
|
|
|
// bool vars
|
|
|
|
disableEmailVerification := store[constants.EnvKeyDisableEmailVerification].(bool)
|
|
|
|
disableBasicAuthentication := store[constants.EnvKeyDisableBasicAuthentication].(bool)
|
|
|
|
disableMagicLinkLogin := store[constants.EnvKeyDisableMagicLinkLogin].(bool)
|
|
|
|
disableLoginPage := store[constants.EnvKeyDisableLoginPage].(bool)
|
|
|
|
disableSignUp := store[constants.EnvKeyDisableSignUp].(bool)
|
2022-01-17 06:02:13 +00:00
|
|
|
|
2022-03-25 14:59:00 +00:00
|
|
|
if accessTokenExpiryTime == "" {
|
|
|
|
accessTokenExpiryTime = "30m"
|
|
|
|
}
|
|
|
|
|
2022-01-17 07:42:46 +00:00
|
|
|
res = &model.Env{
|
2022-03-25 12:21:20 +00:00
|
|
|
AccessTokenExpiryTime: &accessTokenExpiryTime,
|
2022-01-17 06:02:13 +00:00
|
|
|
AdminSecret: &adminSecret,
|
2022-02-26 15:06:22 +00:00
|
|
|
DatabaseName: databaseName,
|
|
|
|
DatabaseURL: databaseURL,
|
|
|
|
DatabaseType: databaseType,
|
2022-04-22 15:54:39 +00:00
|
|
|
DatabaseUsername: databaseUsername,
|
|
|
|
DatabasePassword: databasePassword,
|
|
|
|
DatabaseHost: databaseHost,
|
|
|
|
DatabasePort: databasePort,
|
2022-02-26 15:06:22 +00:00
|
|
|
ClientID: clientID,
|
2022-02-28 07:44:16 +00:00
|
|
|
ClientSecret: clientSecret,
|
2022-01-24 04:52:55 +00:00
|
|
|
CustomAccessTokenScript: &customAccessTokenScript,
|
2022-01-17 06:02:13 +00:00
|
|
|
SMTPHost: &smtpHost,
|
|
|
|
SMTPPort: &smtpPort,
|
|
|
|
SMTPPassword: &smtpPassword,
|
|
|
|
SMTPUsername: &smtpUsername,
|
|
|
|
SenderEmail: &senderEmail,
|
|
|
|
JwtType: &jwtType,
|
|
|
|
JwtSecret: &jwtSecret,
|
2022-02-12 14:04:22 +00:00
|
|
|
JwtPrivateKey: &jwtPrivateKey,
|
|
|
|
JwtPublicKey: &jwtPublicKey,
|
2022-01-17 06:02:13 +00:00
|
|
|
JwtRoleClaim: &jwtRoleClaim,
|
|
|
|
AllowedOrigins: allowedOrigins,
|
|
|
|
AppURL: &appURL,
|
|
|
|
RedisURL: &redisURL,
|
|
|
|
ResetPasswordURL: &resetPasswordURL,
|
|
|
|
DisableEmailVerification: &disableEmailVerification,
|
|
|
|
DisableBasicAuthentication: &disableBasicAuthentication,
|
|
|
|
DisableMagicLinkLogin: &disableMagicLinkLogin,
|
|
|
|
DisableLoginPage: &disableLoginPage,
|
2022-03-16 17:19:18 +00:00
|
|
|
DisableSignUp: &disableSignUp,
|
2022-01-17 06:02:13 +00:00
|
|
|
Roles: roles,
|
|
|
|
ProtectedRoles: protectedRoles,
|
|
|
|
DefaultRoles: defaultRoles,
|
|
|
|
GoogleClientID: &googleClientID,
|
|
|
|
GoogleClientSecret: &googleClientSecret,
|
|
|
|
GithubClientID: &githubClientID,
|
|
|
|
GithubClientSecret: &githubClientSecret,
|
|
|
|
FacebookClientID: &facebookClientID,
|
|
|
|
FacebookClientSecret: &facebookClientSecret,
|
|
|
|
OrganizationName: &organizationName,
|
|
|
|
OrganizationLogo: &organizationLogo,
|
2021-12-31 11:54:22 +00:00
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|