@@ -8,22 +8,23 @@ namespace Devpro.TerraformBackend.WebApi.Controllers;
88
99[ Authorize ]
1010[ ApiController ]
11- [ Route ( "state" ) ]
11+ [ Route ( "{tenant}/ state" ) ]
1212public class StateController ( IStateRepository stateRepository , IStateLockRepository stateLockRepository ) : ControllerBase
1313{
1414 /// <summary>
1515 /// Get Terraform state value.
16- /// GET /state/:name?ID=:lockId
16+ /// GET /:tenant/ state/:name?ID=:lockId
1717 /// </summary>
18+ /// <param name="tenant"></param>
1819 /// <param name="name">The name of the Terraform state</param>
1920 /// <returns>Raw string</returns>
2021 [ HttpGet ( "{name:regex([[a-zA-Z]]+)}" , Name = "GetState" ) ]
2122 [ Produces ( "text/plain" ) ]
2223 [ ProducesResponseType ( 200 ) ]
2324 [ ProducesResponseType ( 204 ) ]
24- public async Task < IActionResult > FindOne ( string name )
25+ public async Task < IActionResult > FindOne ( string tenant , string name )
2526 {
26- var state = await stateRepository . FindOneAsync ( name ) ;
27+ var state = await stateRepository . FindOneAsync ( tenant , name ) ;
2728 if ( string . IsNullOrEmpty ( state ) )
2829 {
2930 return NoContent ( ) ;
@@ -34,7 +35,7 @@ public async Task<IActionResult> FindOne(string name)
3435
3536 /// <summary>
3637 /// Get Terraform state value.
37- /// POST /state/:name?ID=:lockId
38+ /// POST /:tenant/ state/:name?ID=:lockId
3839 /// </summary>
3940 /// <param name="name">The name of the Terraform state</param>
4041 /// <param name="lockId">Terraform state lock ID</param>
@@ -44,17 +45,17 @@ public async Task<IActionResult> FindOne(string name)
4445 [ ProducesResponseType ( 200 ) ]
4546 [ ProducesResponseType ( 409 ) ]
4647 [ ProducesResponseType ( 423 ) ]
47- public async Task < IActionResult > Create ( string name , [ FromBody ] object input , [ FromQuery ( Name = "ID" ) ] string ? lockId = "" )
48+ public async Task < IActionResult > Create ( string tenant , string name , [ FromBody ] object input , [ FromQuery ( Name = "ID" ) ] string ? lockId = "" )
4849 {
49- if ( await CheckLock ( name , lockId ) is { } lockResult ) return lockResult ;
50+ if ( await CheckLock ( tenant , name , lockId ) is { } lockResult ) return lockResult ;
5051
5152 var jsonInput = JsonSerializer . Serialize ( input ) ;
52- await stateRepository . CreateAsync ( name , jsonInput ) ;
53+ await stateRepository . CreateAsync ( tenant , name , jsonInput ) ;
5354 return Ok ( ) ;
5455 }
5556
5657 /// <summary>
57- /// DELETE /state/:name?ID=:lockId
58+ /// DELETE /:tenant/ state/:name?ID=:lockId
5859 /// </summary>
5960 /// <param name="name"></param>
6061 /// <param name="lockId">Terraform state lock ID</param>
@@ -63,16 +64,16 @@ public async Task<IActionResult> Create(string name, [FromBody] object input, [F
6364 [ ProducesResponseType ( 200 ) ]
6465 [ ProducesResponseType ( 409 ) ]
6566 [ ProducesResponseType ( 423 ) ]
66- public async Task < IActionResult > Delete ( string name , [ FromQuery ( Name = "ID" ) ] string ? lockId = "" )
67+ public async Task < IActionResult > Delete ( string tenant , string name , [ FromQuery ( Name = "ID" ) ] string ? lockId = "" )
6768 {
68- if ( await CheckLock ( name , lockId ) is { } lockResult ) return lockResult ;
69+ if ( await CheckLock ( tenant , name , lockId ) is { } lockResult ) return lockResult ;
6970
70- await stateRepository . DeleteAsync ( name ) ;
71+ await stateRepository . DeleteAsync ( tenant , name ) ;
7172 return Ok ( ) ;
7273 }
7374
7475 /// <summary>
75- /// POST /state/:name/lock
76+ /// POST /:tenant/ state/:name/lock
7677 /// </summary>
7778 /// <param name="name"></param>
7879 /// <param name="input"></param>
@@ -83,17 +84,18 @@ public async Task<IActionResult> Delete(string name, [FromQuery(Name = "ID")] st
8384 [ ProducesResponseType ( 200 ) ]
8485 [ ProducesResponseType ( 409 ) ]
8586 [ ProducesResponseType ( 423 ) ]
86- public async Task < IActionResult > Lock ( string name , StateLockModel input )
87+ public async Task < IActionResult > Lock ( string tenant , string name , StateLockModel input )
8788 {
88- if ( await CheckLock ( name , input . Id ) is { } lockResult ) return lockResult ;
89+ if ( await CheckLock ( tenant , name , input . Id ) is { } lockResult ) return lockResult ;
8990
91+ input . Tenant = tenant ;
9092 input . Name = name ;
9193 var entry = await stateLockRepository . CreateAsync ( input ) ;
9294 return Ok ( entry ) ;
9395 }
9496
9597 /// <summary>
96- /// DELETE /state/:name/lock
98+ /// DELETE /:tenant/ state/:name/lock
9799 /// </summary>
98100 /// <param name="name"></param>
99101 /// <param name="input"></param>
@@ -102,16 +104,17 @@ public async Task<IActionResult> Lock(string name, StateLockModel input)
102104 [ ProducesResponseType ( 200 ) ]
103105 [ Consumes ( "application/json" , "text/json" ) ]
104106 [ Produces ( "application/json" ) ]
105- public async Task < IActionResult > Unlock ( string name , [ FromBody ] StateLockModel input )
107+ public async Task < IActionResult > Unlock ( string tenant , string name , [ FromBody ] StateLockModel input )
106108 {
109+ input . Tenant = tenant ;
107110 input . Name = name ;
108111 await stateLockRepository . DeleteAsync ( input ) ;
109112 return Ok ( ) ;
110113 }
111114
112- private async Task < ObjectResult ? > CheckLock ( string name , string ? lockId = "" )
115+ private async Task < ObjectResult ? > CheckLock ( string tenant , string name , string ? lockId = "" )
113116 {
114- var existingLock = await stateLockRepository . FindOneAsync ( name ) ;
117+ var existingLock = await stateLockRepository . FindOneAsync ( tenant , name ) ;
115118 if ( existingLock != null )
116119 {
117120 if ( string . IsNullOrEmpty ( lockId ) )
0 commit comments