2021-12-31 11:54:22 +00:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2022-01-17 06:02:13 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/envstore"
|
2021-12-31 11:54:22 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"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) {
|
2021-12-31 11:54:22 +00:00
|
|
|
gc, err := utils.GinContextFromContext(ctx)
|
2022-01-17 07:42:46 +00:00
|
|
|
var res *model.Env
|
2021-12-31 11:54:22 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !utils.IsSuperAdmin(gc) {
|
|
|
|
return res, fmt.Errorf("unauthorized")
|
|
|
|
}
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
// get clone of store
|
|
|
|
store := envstore.EnvInMemoryStoreObj.GetEnvStoreClone()
|
|
|
|
adminSecret := store[constants.EnvKeyAdminSecret].(string)
|
|
|
|
databaseType := store[constants.EnvKeyDatabaseType].(string)
|
|
|
|
databaseURL := store[constants.EnvKeyDatabaseURL].(string)
|
|
|
|
databaseName := store[constants.EnvKeyDatabaseName].(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)
|
|
|
|
allowedOrigins := store[constants.EnvKeyAllowedOrigins].([]string)
|
|
|
|
authorizerURL := store[constants.EnvKeyAuthorizerURL].(string)
|
|
|
|
appURL := store[constants.EnvKeyAppURL].(string)
|
|
|
|
redisURL := store[constants.EnvKeyRedisURL].(string)
|
|
|
|
cookieName := store[constants.EnvKeyCookieName].(string)
|
|
|
|
resetPasswordURL := store[constants.EnvKeyResetPasswordURL].(string)
|
|
|
|
disableEmailVerification := store[constants.EnvKeyDisableEmailVerification].(bool)
|
|
|
|
disableBasicAuthentication := store[constants.EnvKeyDisableBasicAuthentication].(bool)
|
|
|
|
disableMagicLinkLogin := store[constants.EnvKeyDisableMagicLinkLogin].(bool)
|
|
|
|
disableLoginPage := store[constants.EnvKeyDisableLoginPage].(bool)
|
|
|
|
roles := store[constants.EnvKeyRoles].([]string)
|
|
|
|
defaultRoles := store[constants.EnvKeyDefaultRoles].([]string)
|
|
|
|
protectedRoles := store[constants.EnvKeyProtectedRoles].([]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)
|
|
|
|
|
2022-01-17 07:42:46 +00:00
|
|
|
res = &model.Env{
|
2022-01-17 06:02:13 +00:00
|
|
|
AdminSecret: &adminSecret,
|
|
|
|
DatabaseType: &databaseType,
|
|
|
|
DatabaseURL: &databaseURL,
|
|
|
|
DatabaseName: &databaseName,
|
|
|
|
SMTPHost: &smtpHost,
|
|
|
|
SMTPPort: &smtpPort,
|
|
|
|
SMTPPassword: &smtpPassword,
|
|
|
|
SMTPUsername: &smtpUsername,
|
|
|
|
SenderEmail: &senderEmail,
|
|
|
|
JwtType: &jwtType,
|
|
|
|
JwtSecret: &jwtSecret,
|
|
|
|
JwtRoleClaim: &jwtRoleClaim,
|
|
|
|
AllowedOrigins: allowedOrigins,
|
|
|
|
AuthorizerURL: &authorizerURL,
|
|
|
|
AppURL: &appURL,
|
|
|
|
RedisURL: &redisURL,
|
|
|
|
CookieName: &cookieName,
|
|
|
|
ResetPasswordURL: &resetPasswordURL,
|
|
|
|
DisableEmailVerification: &disableEmailVerification,
|
|
|
|
DisableBasicAuthentication: &disableBasicAuthentication,
|
|
|
|
DisableMagicLinkLogin: &disableMagicLinkLogin,
|
|
|
|
DisableLoginPage: &disableLoginPage,
|
|
|
|
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
|
|
|
|
}
|