2021-12-31 11:54:22 +00:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-05-31 07:41:54 +00:00
|
|
|
"strings"
|
2021-12-31 11:54:22 +00:00
|
|
|
|
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-07-15 16:41:08 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/refs"
|
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) {
|
2022-05-31 07:41:54 +00:00
|
|
|
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
|
|
|
|
}
|
2022-05-31 07:41:54 +00:00
|
|
|
|
|
|
|
if val, ok := store[constants.EnvKeyAccessTokenExpiryTime]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.AccessTokenExpiryTime = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyAdminSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.AdminSecret = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyClientID]; ok {
|
|
|
|
res.ClientID = val.(string)
|
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyClientSecret]; ok {
|
|
|
|
res.ClientSecret = val.(string)
|
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabaseURL]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabaseURL = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabaseName]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabaseName = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabaseType]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabaseType = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabaseUsername]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabaseUsername = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabasePassword]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabasePassword = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabaseHost]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabaseHost = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDatabasePort]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.DatabasePort = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyCustomAccessTokenScript]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.CustomAccessTokenScript = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeySmtpHost]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.SMTPHost = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeySmtpPort]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.SMTPPort = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeySmtpUsername]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.SMTPUsername = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeySmtpPassword]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.SMTPPassword = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeySenderEmail]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.SenderEmail = refs.NewStringRef(val.(string))
|
2022-10-25 02:48:29 +00:00
|
|
|
}
|
2023-05-15 21:46:22 +00:00
|
|
|
if val, ok := store[constants.EnvKeySenderName]; ok {
|
|
|
|
res.SenderName = refs.NewStringRef(val.(string))
|
|
|
|
}
|
2022-10-25 02:48:29 +00:00
|
|
|
if val, ok := store[constants.EnvKeySmtpLocalName]; ok {
|
|
|
|
res.SMTPLocalName = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyJwtType]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.JwtType = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyJwtSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.JwtSecret = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyJwtRoleClaim]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.JwtRoleClaim = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyJwtPublicKey]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.JwtPublicKey = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyJwtPrivateKey]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.JwtPrivateKey = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyAppURL]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.AppURL = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyRedisURL]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.RedisURL = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyResetPasswordURL]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.ResetPasswordURL = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyGoogleClientID]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.GoogleClientID = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyGoogleClientSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.GoogleClientSecret = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyFacebookClientID]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.FacebookClientID = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyFacebookClientSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.FacebookClientSecret = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyGithubClientID]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.GithubClientID = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyGithubClientSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.GithubClientSecret = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
2022-06-06 16:38:32 +00:00
|
|
|
if val, ok := store[constants.EnvKeyLinkedInClientID]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.LinkedinClientID = refs.NewStringRef(val.(string))
|
2022-06-06 16:38:32 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyLinkedInClientSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.LinkedinClientSecret = refs.NewStringRef(val.(string))
|
2022-06-06 16:38:32 +00:00
|
|
|
}
|
2022-06-12 09:19:48 +00:00
|
|
|
if val, ok := store[constants.EnvKeyAppleClientID]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.AppleClientID = refs.NewStringRef(val.(string))
|
2022-06-12 09:19:48 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyAppleClientSecret]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.AppleClientSecret = refs.NewStringRef(val.(string))
|
2022-06-12 09:19:48 +00:00
|
|
|
}
|
2022-08-13 07:05:00 +00:00
|
|
|
if val, ok := store[constants.EnvKeyTwitterClientID]; ok {
|
|
|
|
res.TwitterClientID = refs.NewStringRef(val.(string))
|
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyTwitterClientSecret]; ok {
|
|
|
|
res.TwitterClientSecret = refs.NewStringRef(val.(string))
|
|
|
|
}
|
2023-02-25 23:53:02 +00:00
|
|
|
if val, ok := store[constants.EnvKeyMicrosoftClientID]; ok {
|
|
|
|
res.MicrosoftClientID = refs.NewStringRef(val.(string))
|
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyMicrosoftClientSecret]; ok {
|
|
|
|
res.MicrosoftClientSecret = refs.NewStringRef(val.(string))
|
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyMicrosoftActiveDirectoryTenantID]; ok {
|
|
|
|
res.MicrosoftActiveDirectoryTenantID = refs.NewStringRef(val.(string))
|
|
|
|
}
|
2022-08-13 07:05:00 +00:00
|
|
|
|
2022-05-31 07:41:54 +00:00
|
|
|
if val, ok := store[constants.EnvKeyOrganizationName]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.OrganizationName = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyOrganizationLogo]; ok {
|
2022-07-15 16:41:08 +00:00
|
|
|
res.OrganizationLogo = refs.NewStringRef(val.(string))
|
2022-05-31 07:41:54 +00:00
|
|
|
}
|
2023-04-01 12:06:07 +00:00
|
|
|
if val, ok := store[constants.EnvKeyDefaultAuthorizeResponseType]; ok {
|
|
|
|
res.DefaultAuthorizeResponseType = refs.NewStringRef(val.(string))
|
|
|
|
}
|
|
|
|
if val, ok := store[constants.EnvKeyDefaultAuthorizeResponseMode]; ok {
|
|
|
|
res.DefaultAuthorizeResponseMode = refs.NewStringRef(val.(string))
|
|
|
|
}
|
2022-05-30 03:49:55 +00:00
|
|
|
|
|
|
|
// string slice vars
|
2022-05-31 07:41:54 +00:00
|
|
|
res.AllowedOrigins = strings.Split(store[constants.EnvKeyAllowedOrigins].(string), ",")
|
|
|
|
res.Roles = strings.Split(store[constants.EnvKeyRoles].(string), ",")
|
|
|
|
res.DefaultRoles = strings.Split(store[constants.EnvKeyDefaultRoles].(string), ",")
|
2022-06-07 02:00:01 +00:00
|
|
|
// since protected role is optional default split gives array with empty string
|
|
|
|
protectedRoles := strings.Split(store[constants.EnvKeyProtectedRoles].(string), ",")
|
|
|
|
res.ProtectedRoles = []string{}
|
|
|
|
for _, role := range protectedRoles {
|
|
|
|
if strings.Trim(role, " ") != "" {
|
|
|
|
res.ProtectedRoles = append(res.ProtectedRoles, strings.Trim(role, " "))
|
|
|
|
}
|
|
|
|
}
|
2022-05-30 03:49:55 +00:00
|
|
|
|
|
|
|
// bool vars
|
2022-05-31 07:41:54 +00:00
|
|
|
res.DisableEmailVerification = store[constants.EnvKeyDisableEmailVerification].(bool)
|
|
|
|
res.DisableBasicAuthentication = store[constants.EnvKeyDisableBasicAuthentication].(bool)
|
|
|
|
res.DisableMagicLinkLogin = store[constants.EnvKeyDisableMagicLinkLogin].(bool)
|
|
|
|
res.DisableLoginPage = store[constants.EnvKeyDisableLoginPage].(bool)
|
|
|
|
res.DisableSignUp = store[constants.EnvKeyDisableSignUp].(bool)
|
2022-06-18 10:01:57 +00:00
|
|
|
res.DisableStrongPassword = store[constants.EnvKeyDisableStrongPassword].(bool)
|
2022-08-02 08:42:36 +00:00
|
|
|
res.EnforceMultiFactorAuthentication = store[constants.EnvKeyEnforceMultiFactorAuthentication].(bool)
|
2022-08-03 17:50:23 +00:00
|
|
|
res.DisableMultiFactorAuthentication = store[constants.EnvKeyDisableMultiFactorAuthentication].(bool)
|
2022-10-02 16:31:22 +00:00
|
|
|
res.AdminCookieSecure = store[constants.EnvKeyAdminCookieSecure].(bool)
|
|
|
|
res.AppCookieSecure = store[constants.EnvKeyAppCookieSecure].(bool)
|
2023-08-28 14:21:42 +00:00
|
|
|
res.DisablePlayground = store[constants.EnvKeyDisablePlayGround].(bool)
|
2023-11-16 13:00:54 +00:00
|
|
|
res.DisableMailOtpLogin = store[constants.EnvKeyDisableMailOTPLogin].(bool)
|
|
|
|
res.DisableTotpLogin = store[constants.EnvKeyDisableTOTPLogin].(bool)
|
2022-03-25 14:59:00 +00:00
|
|
|
|
2021-12-31 11:54:22 +00:00
|
|
|
return res, nil
|
|
|
|
}
|