Skip to content

Commit 2074050

Browse files
Add static login link for sandbox setup (#168)
1 parent 93fb6af commit 2074050

File tree

12 files changed

+152
-16
lines changed

12 files changed

+152
-16
lines changed

assets/src/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { OAuthCallback } from './components/OauthCallback'
1313
import 'react-toggle/style.css'
1414
import 'react-pulse-dot/dist/index.css'
1515
import { client } from './helpers/client'
16+
import { LinkLogin } from './components/LinkLogin'
1617

1718
const INTERCOM_APP_ID = 'p127zb9y'
1819

@@ -27,6 +28,10 @@ export default function App() {
2728
path="/login"
2829
component={Login}
2930
/>
31+
<Route
32+
path="/quick-login/:key"
33+
component={LinkLogin}
34+
/>
3035
<Route
3136
path="/access"
3237
component={GrantAccess}

assets/src/components/LinkLogin.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Box, Text } from 'grommet'
2+
import { useEffect } from 'react'
3+
import { useMutation } from 'react-apollo'
4+
import { useParams } from 'react-router'
5+
6+
import { setToken } from '../helpers/auth'
7+
8+
import { LOGIN_LINK } from './graphql/users'
9+
import { LoginPortal } from './Login'
10+
import { LoopingLogo } from './utils/AnimatedLogo'
11+
12+
export function LinkLogin() {
13+
const { key } = useParams()
14+
const [mutation, { error }] = useMutation(LOGIN_LINK, {
15+
variables: { key },
16+
onCompleted: ({ loginLink: { jwt } }) => {
17+
setToken(jwt)
18+
window.location = '/'
19+
},
20+
onError: console.log,
21+
})
22+
23+
useEffect(() => {
24+
mutation()
25+
}, [])
26+
27+
if (error) {
28+
return (
29+
<Box
30+
fill
31+
align="center"
32+
justify="center"
33+
>
34+
<Box>
35+
<Text>This login link is invalid</Text>
36+
</Box>
37+
</Box>
38+
)
39+
}
40+
41+
return (
42+
<LoginPortal>
43+
<LoopingLogo />
44+
</LoginPortal>
45+
)
46+
}

assets/src/components/graphql/users.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ export const SIGNUP = gql`
164164
${UserFragment}
165165
`
166166

167+
export const LOGIN_LINK = gql`
168+
mutation Link($key: String!) {
169+
loginLink(key: $key) {
170+
...UserFragment
171+
jwt
172+
}
173+
}
174+
${UserFragment}
175+
`
176+
167177
export const NOTIFICATIONS_Q = gql`
168178
query Notifs($all: Boolean, $cursor: String) {
169179
notifications(all: $all, after: $cursor, first: 50) {

config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ config :console, Console.PartitionedCache,
7575
allocated_memory: 1000 * 1000 * 500
7676
]
7777

78+
config :console, :login_link, []
79+
7880
import_config "#{Mix.env()}.exs"

config/test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ config :console,
3030
git_ssh_key: :pass,
3131
grafana_dns: "grafana.example.com"
3232

33+
config :console, :login_link,
34+
key: "test-key",
35+
36+
3337
config :console, :consumers, [Console.EchoConsumer]
3438

3539
config :kazan, :server, %{url: "kubernetes.default", auth: %{token: "your_token"}}

lib/console/graphql/resolvers/user.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ defmodule Console.GraphQl.Resolvers.User do
99
def query(RoleBinding, _), do: RoleBinding
1010
def query(_, _), do: User
1111

12+
def login_link(%{key: k}, _) do
13+
Console.conf(:login_link)
14+
|> Map.new()
15+
|> case do
16+
%{key: ^k, email: email} when is_binary(email) ->
17+
Users.get_user_by_email(email)
18+
|> ok()
19+
|> with_jwt()
20+
_ -> {:error, "unauthorized"}
21+
end
22+
end
23+
1224
def list_users(args, _) do
1325
User.ordered()
1426
|> maybe_search(User, args)

lib/console/graphql/users.ex

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ defmodule Console.GraphQl.Users do
182182
field :role, :role do
183183
middleware Authenticated
184184

185-
resolve safe_resolver(&User.resolve_role/2)
185+
safe_resolve &User.resolve_role/2
186186
end
187187

188188
connection field :roles, node_type: :role do
@@ -205,13 +205,20 @@ defmodule Console.GraphQl.Users do
205205
arg :email, non_null(:string)
206206
arg :password, non_null(:string)
207207

208-
resolve safe_resolver(&User.signin_user/2)
208+
safe_resolve &User.signin_user/2
209+
end
210+
211+
field :login_link, :user do
212+
middleware AllowJwt
213+
arg :key, non_null(:string)
214+
215+
safe_resolve &User.login_link/2
209216
end
210217

211218
field :read_notifications, :user do
212219
middleware Authenticated
213220

214-
resolve safe_resolver(&User.read_notifications/2)
221+
safe_resolve &User.read_notifications/2
215222
end
216223

217224
field :signup, :user do
@@ -220,23 +227,23 @@ defmodule Console.GraphQl.Users do
220227
arg :invite_id, non_null(:string)
221228
arg :attributes, non_null(:user_attributes)
222229

223-
resolve safe_resolver(&User.signup_user/2)
230+
safe_resolve &User.signup_user/2
224231
end
225232

226233
field :oauth_callback, :user do
227234
middleware AllowJwt
228235
arg :code, non_null(:string)
229236
arg :redirect, :string
230237

231-
resolve safe_resolver(&User.oauth_callback/2)
238+
safe_resolve &User.oauth_callback/2
232239
end
233240

234241
field :create_invite, :invite do
235242
middleware Authenticated
236243
middleware Sandboxed
237244
arg :attributes, non_null(:invite_attributes)
238245

239-
resolve safe_resolver(&User.create_invite/2)
246+
safe_resolve &User.create_invite/2
240247
end
241248

242249
field :update_user, :user do
@@ -245,7 +252,7 @@ defmodule Console.GraphQl.Users do
245252
arg :id, :id
246253
arg :attributes, non_null(:user_attributes)
247254

248-
resolve safe_resolver(&User.update_user/2)
255+
safe_resolve &User.update_user/2
249256
end
250257

251258
field :create_group, :group do
@@ -254,7 +261,7 @@ defmodule Console.GraphQl.Users do
254261
middleware Sandboxed
255262
arg :attributes, non_null(:group_attributes)
256263

257-
resolve safe_resolver(&User.create_group/2)
264+
safe_resolve &User.create_group/2
258265
end
259266

260267
field :delete_group, :group do
@@ -263,7 +270,7 @@ defmodule Console.GraphQl.Users do
263270
middleware Sandboxed
264271
arg :group_id, non_null(:id)
265272

266-
resolve safe_resolver(&User.delete_group/2)
273+
safe_resolve &User.delete_group/2
267274
end
268275

269276
field :update_group, :group do
@@ -273,7 +280,7 @@ defmodule Console.GraphQl.Users do
273280
arg :group_id, non_null(:id)
274281
arg :attributes, non_null(:group_attributes)
275282

276-
resolve safe_resolver(&User.update_group/2)
283+
safe_resolve &User.update_group/2
277284
end
278285

279286
field :create_group_member, :group_member do
@@ -283,7 +290,7 @@ defmodule Console.GraphQl.Users do
283290
arg :group_id, non_null(:id)
284291
arg :user_id, non_null(:id)
285292

286-
resolve safe_resolver(&User.create_group_member/2)
293+
safe_resolve &User.create_group_member/2
287294
end
288295

289296
field :delete_group_member, :group_member do
@@ -293,7 +300,7 @@ defmodule Console.GraphQl.Users do
293300
arg :group_id, non_null(:id)
294301
arg :user_id, non_null(:id)
295302

296-
resolve safe_resolver(&User.delete_group_member/2)
303+
safe_resolve &User.delete_group_member/2
297304
end
298305

299306
field :create_role, :role do
@@ -302,7 +309,7 @@ defmodule Console.GraphQl.Users do
302309
middleware Sandboxed
303310
arg :attributes, non_null(:role_attributes)
304311

305-
resolve safe_resolver(&User.create_role/2)
312+
safe_resolve &User.create_role/2
306313
end
307314

308315
field :update_role, :role do
@@ -312,7 +319,7 @@ defmodule Console.GraphQl.Users do
312319
arg :id, non_null(:id)
313320
arg :attributes, non_null(:role_attributes)
314321

315-
resolve safe_resolver(&User.update_role/2)
322+
safe_resolve &User.update_role/2
316323
end
317324

318325
field :delete_role, :role do
@@ -321,7 +328,7 @@ defmodule Console.GraphQl.Users do
321328
middleware Sandboxed
322329
arg :id, non_null(:id)
323330

324-
resolve safe_resolver(&User.delete_role/2)
331+
safe_resolve &User.delete_role/2
325332
end
326333
end
327334

plural/helm/console/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: 0.3.6
33
description: A chart for plural console
44
name: console
5-
version: 0.7.28
5+
version: 0.7.30
66
dependencies:
77
- name: test-base
88
repository: https://pluralsh.github.io/module-library

plural/helm/console/templates/secrets.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ data:
3535
{{ if .Values.is_demo }}
3636
IS_DEMO_PROJECT: 'true'
3737
{{ end }}
38+
{{- range $key, $value := .Values.extraSecretEnv -}}
39+
{{ $key }}: {{ $value | quote }}
40+
{{- end -}}
3841
{{ if .Values.secrets.id_rsa }}
3942
---
4043
apiVersion: v1

plural/helm/console/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ serviceAccount:
1313
create: true
1414
annotations: {}
1515

16+
extraSecretEnv: []
17+
1618
configOverlays:
1719
- name: console-cpu
1820
labels:

0 commit comments

Comments
 (0)