Skip to content

Commit 78fe346

Browse files
Better api scope setup
Just adopt `{resource}.{action}` scope format, which is pretty standard and can be shoehorned into gql. Also fix some scraper behavior
1 parent bee29df commit 78fe346

33 files changed

+1537
-710
lines changed

lib/console/graphql/deployments/agent.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,19 @@ defmodule Console.GraphQl.Deployments.Agent do
319319
object :agent_queries do
320320
field :shared_agent_run, :agent_run do
321321
middleware Authenticated
322+
middleware Scope,
323+
resource: :agent,
324+
action: :read
322325
arg :id, non_null(:id)
323326

324327
resolve &Deployments.shared_agent_run/2
325328
end
326329

327330
connection field :agent_runtimes, node_type: :agent_runtime do
328331
middleware Authenticated
332+
middleware Scope,
333+
resource: :agent,
334+
action: :read
329335
arg :q, :string
330336
arg :type, :agent_runtime_type
331337

@@ -334,6 +340,9 @@ defmodule Console.GraphQl.Deployments.Agent do
334340

335341
connection field :agent_runs, node_type: :agent_run do
336342
middleware Authenticated
343+
middleware Scope,
344+
resource: :agent,
345+
action: :read
337346
arg :runtime_id, :id
338347

339348
resolve &Deployments.agent_runs/2
@@ -343,13 +352,19 @@ defmodule Console.GraphQl.Deployments.Agent do
343352
object :agent_mutations do
344353
field :cancel_agent_run, :agent_run do
345354
middleware Authenticated
355+
middleware Scope,
356+
resource: :agent,
357+
action: :write
346358
arg :id, non_null(:id)
347359

348360
resolve &Deployments.cancel_agent_run/2
349361
end
350362

351363
field :create_agent_run, :agent_run do
352364
middleware Authenticated
365+
middleware Scope,
366+
resource: :agent,
367+
action: :write
353368
arg :runtime_id, non_null(:id)
354369
arg :attributes, non_null(:agent_run_attributes)
355370

@@ -358,6 +373,9 @@ defmodule Console.GraphQl.Deployments.Agent do
358373

359374
field :share_agent_run, :agent_run do
360375
middleware Authenticated
376+
middleware Scope,
377+
resource: :agent,
378+
action: :write
361379
arg :id, non_null(:id)
362380

363381
resolve &Deployments.share_agent_run/2

lib/console/graphql/deployments/cluster.ex

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
12481248
@desc "a relay connection of all clusters visible to the current user"
12491249
connection field :clusters, node_type: :cluster do
12501250
middleware Authenticated
1251+
middleware Scope,
1252+
resource: :cluster,
1253+
action: :read
12511254
arg :q, :string
12521255
arg :healthy, :boolean
12531256
arg :tag, :tag_input
@@ -1310,7 +1313,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
13101313
@desc "fetches an individual cluster"
13111314
field :cluster, :cluster do
13121315
middleware Authenticated, :cluster
1313-
middleware Scope, api: "cluster"
1316+
middleware Scope,
1317+
resource: :cluster,
1318+
action: :read
13141319
arg :id, :id
13151320
arg :handle, :string
13161321

@@ -1320,6 +1325,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
13201325
@desc "fetches an individual cluster provider"
13211326
field :cluster_provider, :cluster_provider do
13221327
middleware Authenticated
1328+
middleware Scope,
1329+
resource: :cluster,
1330+
action: :read
13231331
arg :id, :id
13241332
arg :cloud, :string
13251333
arg :name, :string
@@ -1344,6 +1352,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
13441352

13451353
connection field :cluster_usages, node_type: :cluster_usage do
13461354
middleware Authenticated
1355+
middleware Scope,
1356+
resource: :cluster,
1357+
action: :read
13471358
arg :q, :string
13481359
arg :tag_query, :tag_query
13491360
arg :project_id, :id
@@ -1353,19 +1364,28 @@ defmodule Console.GraphQl.Deployments.Cluster do
13531364

13541365
field :cluster_usage, :cluster_usage do
13551366
middleware Authenticated
1367+
middleware Scope,
1368+
resource: :cluster,
1369+
action: :read
13561370
arg :id, non_null(:id)
13571371

13581372
resolve &Deployments.resolve_cluster_usage/2
13591373
end
13601374

13611375
connection field :project_usage_history, node_type: :project_usage_history do
13621376
middleware Authenticated
1377+
middleware Scope,
1378+
resource: :project,
1379+
action: :read
13631380

13641381
resolve &Deployments.list_aggregated_cluster_usage_history/2
13651382
end
13661383

13671384
field :cluster_registration, :cluster_registration do
13681385
middleware Authenticated
1386+
middleware Scope,
1387+
resource: :cluster,
1388+
action: :read
13691389
arg :id, :id
13701390
arg :machine_id, :string
13711391

@@ -1374,12 +1394,18 @@ defmodule Console.GraphQl.Deployments.Cluster do
13741394

13751395
connection field :cluster_registrations, node_type: :cluster_registration do
13761396
middleware Authenticated
1397+
middleware Scope,
1398+
resource: :cluster,
1399+
action: :read
13771400

13781401
resolve &Deployments.list_cluster_registrations/2
13791402
end
13801403

13811404
field :cluster_iso_image, :cluster_iso_image do
13821405
middleware Authenticated
1406+
middleware Scope,
1407+
resource: :cluster,
1408+
action: :read
13831409
arg :id, :id
13841410
arg :image, :string
13851411

@@ -1388,6 +1414,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
13881414

13891415
connection field :cluster_iso_images, node_type: :cluster_iso_image do
13901416
middleware Authenticated
1417+
middleware Scope,
1418+
resource: :cluster,
1419+
action: :read
13911420

13921421
resolve &Deployments.list_cluster_iso_images/2
13931422
end
@@ -1404,7 +1433,10 @@ defmodule Console.GraphQl.Deployments.Cluster do
14041433
field :create_cluster, :cluster do
14051434
middleware Authenticated
14061435
middleware Feature, :cd
1407-
middleware Scope, api: "createCluster"
1436+
middleware Scope,
1437+
resource: :cluster,
1438+
action: :write,
1439+
api: "createCluster"
14081440
arg :attributes, non_null(:cluster_attributes)
14091441

14101442
safe_resolve &Deployments.create_cluster/2
@@ -1413,7 +1445,10 @@ defmodule Console.GraphQl.Deployments.Cluster do
14131445
field :update_cluster, :cluster do
14141446
middleware Authenticated
14151447
middleware Feature, :cd
1416-
middleware Scope, api: "updateCluster"
1448+
middleware Scope,
1449+
resource: :cluster,
1450+
action: :write,
1451+
api: "updateCluster"
14171452
arg :id, non_null(:id)
14181453
arg :attributes, non_null(:cluster_update_attributes)
14191454

@@ -1422,7 +1457,10 @@ defmodule Console.GraphQl.Deployments.Cluster do
14221457

14231458
field :delete_cluster, :cluster do
14241459
middleware Authenticated
1425-
middleware Scope, api: "deleteCluster"
1460+
middleware Scope,
1461+
resource: :cluster,
1462+
action: :write,
1463+
api: "deleteCluster"
14261464
arg :id, non_null(:id)
14271465

14281466
safe_resolve &Deployments.delete_cluster/2
@@ -1431,7 +1469,10 @@ defmodule Console.GraphQl.Deployments.Cluster do
14311469
@desc "soft deletes a cluster, by deregistering it in our system but not disturbing any kubernetes objects"
14321470
field :detach_cluster, :cluster do
14331471
middleware Authenticated
1434-
middleware Scope, api: "deleteCluster"
1472+
middleware Scope,
1473+
resource: :cluster,
1474+
action: :write,
1475+
api: "deleteCluster"
14351476
arg :id, non_null(:id)
14361477

14371478
resolve &Deployments.detach_cluster/2
@@ -1486,20 +1527,29 @@ defmodule Console.GraphQl.Deployments.Cluster do
14861527

14871528
field :create_agent_migration, :agent_migration do
14881529
middleware Authenticated
1530+
middleware Scope,
1531+
resource: :settings,
1532+
action: :write
14891533
arg :attributes, non_null(:agent_migration_attributes)
14901534

14911535
resolve &Deployments.create_agent_migration/2
14921536
end
14931537

14941538
field :create_pinned_custom_resource, :pinned_custom_resource do
14951539
middleware Authenticated
1540+
middleware Scope,
1541+
resource: :cluster,
1542+
action: :write
14961543
arg :attributes, non_null(:pinned_custom_resource_attributes)
14971544

14981545
resolve &Deployments.create_pinned_custom_resource/2
14991546
end
15001547

15011548
field :delete_pinned_custom_resource, :pinned_custom_resource do
15021549
middleware Authenticated
1550+
middleware Scope,
1551+
resource: :cluster,
1552+
action: :write
15031553
arg :id, non_null(:id)
15041554

15051555
resolve &Deployments.delete_pinned_custom_resource/2
@@ -1514,6 +1564,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
15141564

15151565
field :apply_scaling_recommendation, :pull_request do
15161566
middleware Authenticated
1567+
middleware Scope,
1568+
resource: :cluster,
1569+
action: :write
15171570
arg :id, non_null(:id), description: "the id of the scaling recommendation to fix"
15181571

15191572
resolve &Deployments.scaling_pr/2
@@ -1528,13 +1581,19 @@ defmodule Console.GraphQl.Deployments.Cluster do
15281581

15291582
field :create_cluster_registration, :cluster_registration do
15301583
middleware Authenticated
1584+
middleware Scope,
1585+
resource: :cluster,
1586+
action: :write
15311587
arg :attributes, non_null(:cluster_registration_create_attributes)
15321588

15331589
resolve &Deployments.create_cluster_registration/2
15341590
end
15351591

15361592
field :update_cluster_registration, :cluster_registration do
15371593
middleware Authenticated
1594+
middleware Scope,
1595+
resource: :cluster,
1596+
action: :write
15381597
arg :id, non_null(:id)
15391598
arg :attributes, non_null(:cluster_registration_update_attributes)
15401599

@@ -1543,20 +1602,29 @@ defmodule Console.GraphQl.Deployments.Cluster do
15431602

15441603
field :delete_cluster_registration, :cluster_registration do
15451604
middleware Authenticated
1605+
middleware Scope,
1606+
resource: :cluster,
1607+
action: :write
15461608
arg :id, non_null(:id)
15471609

15481610
resolve &Deployments.delete_cluster_registration/2
15491611
end
15501612

15511613
field :create_cluster_iso_image, :cluster_iso_image do
15521614
middleware Authenticated
1615+
middleware Scope,
1616+
resource: :cluster,
1617+
action: :write
15531618
arg :attributes, non_null(:cluster_iso_image_attributes)
15541619

15551620
resolve &Deployments.create_cluster_iso_image/2
15561621
end
15571622

15581623
field :update_cluster_iso_image, :cluster_iso_image do
15591624
middleware Authenticated
1625+
middleware Scope,
1626+
resource: :cluster,
1627+
action: :write
15601628
arg :id, non_null(:id)
15611629
arg :attributes, non_null(:cluster_iso_image_attributes)
15621630

@@ -1565,6 +1633,9 @@ defmodule Console.GraphQl.Deployments.Cluster do
15651633

15661634
field :delete_cluster_iso_image, :cluster_iso_image do
15671635
middleware Authenticated
1636+
middleware Scope,
1637+
resource: :cluster,
1638+
action: :write
15681639
arg :id, non_null(:id)
15691640

15701641
resolve &Deployments.delete_cluster_iso_image/2

0 commit comments

Comments
 (0)