-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecretController.java
90 lines (82 loc) · 2.88 KB
/
SecretController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package git.tracehub.pmo.controller;
import git.tracehub.pmo.controller.request.RqSecret;
import git.tracehub.pmo.controller.request.SecretFromReq;
import git.tracehub.pmo.secret.Secret;
import git.tracehub.pmo.secret.Secrets;
import jakarta.validation.Valid;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
/**
* Secret Controller.
*
* @todo #44:30min create an endpoint to list all keys from the project.
* This endpoint should return a list of keys using project id.
* @todo #44:30min create an endpoint to update a secret. This endpoint
* should receive a secret id and a new value to update the secret.
* @since 0.0.0
*/
@RestController
@RequestMapping("/secrets")
public class SecretController {
/**
* Tickets.
*/
private final Secrets secrets;
/**
* Constructor.
*
* @param secrets Secrets
*/
public SecretController(@Qualifier("uniqueSecrets") final Secrets secrets) {
this.secrets = secrets;
}
/**
* Secret value by key.
*
* @param project Project id
* @param key Key
* @return Secret
*/
@GetMapping
public Secret secret(
@RequestParam final UUID project,
@RequestParam final String key
) {
return this.secrets.value(project, key);
}
/**
* Create secret.
*
* @param secret Secret
* @return Secret
*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Secret create(@RequestBody @Valid final RqSecret secret) {
return this.secrets.create(new SecretFromReq(secret));
}
}