BE: Implement APIs change to verify agent mapping during workspace creation in RD

MR: Verify agent mappings when creating workspaces (!150770 - merged)

Description

Implement API changes that control what agents can be used during workspace creation as described in the technical design i.e. API 6 specifically, for the new group-agent mapping feature

Acceptance Criteria

  • Implement API changes w/ tests as mentioned in the design doc. These include
    • The workspace creation API must be modified check if the workspace project/agent conform to the constraint of the agent being mapped to at least one of the ancestor groups of the workspace project
  • Ensure that the APIs ensure the permissions model as described in the doc (if applicable)
  • Ensure that the changes to the existing API are behind the feature flag as mentioned in the doc

Technical Requirements

  • Same as the acceptance criteria
  • The underlying validation class has been implemented in this MR BE: Add new query API to list available agents ... (!146453 - merged), and can be reused in this issue.
  • There has already been some preliminary work and a patch for this here: !145387 (comment 1842487164)
  • See related backend API issue for "API 5" in the technical design: MR - BE: Add new query API to list available agents ... (!146453 - merged)

Working example in the irb console:

[7] pry(main)> RemoteDevelopment::RemoteDevelopmentNamespaceClusterAgentMapping.where(namespace_id: [1, 24], cluster_agent_id: 2)

  RemoteDevelopment::RemoteDevelopmentNamespaceClusterAgentMapping Load (1.4ms)  SELECT "remote_development_namespace_cluster_agent_mappings".* FROM "remote_development_namespace_cluster_agent_mappings" WHERE "remote_development_namespace_cluster_agent_mappings"."namespace_id" IN (1, 24) AND "remote_development_namespace_cluster_agent_mappings"."cluster_agent_id" = 2 /*application:console,db_config_name:main,console_hostname:Hunars-MacBook-Pro.local,console_username:hkhanna,line:bin/rails:4:in `<main>'*/
=> [#<RemoteDevelopment::RemoteDevelopmentNamespaceClusterAgentMapping:0x000000017219eb00
  id: 19,
  created_at: Tue, 05 Mar 2024 07:16:25.141737000 UTC +00:00,
  updated_at: Tue, 05 Mar 2024 07:16:25.141737000 UTC +00:00,
  namespace_id: 24,
  cluster_agent_id: 2,
  creator_id: 1>]
[8] pry(main)>

Design Requirements

NA

Impact Assessment

  • There should be no impact as all of the new APIs should be behind a feature flag
Edited May 06, 2024 by Chad Woolley
Assignee Loading
Time tracking Loading