@@ -6,10 +6,26 @@ import (
6
6
7
7
"github.com/google/uuid"
8
8
9
+ "github.com/artefactual-sdps/enduro/internal/api/auth"
9
10
goastorage "github.com/artefactual-sdps/enduro/internal/api/gen/storage"
10
11
)
11
12
12
13
func (s * serviceImpl ) RequestAipDeletion (ctx context.Context , payload * goastorage.RequestAipDeletionPayload ) error {
14
+ // Authentication must be enabled for now.
15
+ claims := auth .UserClaimsFromContext (ctx )
16
+ if claims == nil {
17
+ return goastorage .MakeNotValid (errors .New ("authentication is required" ))
18
+ }
19
+ if claims .Email == "" {
20
+ return goastorage .MakeNotValid (errors .New ("email claim is required" ))
21
+ }
22
+ if claims .Sub == "" {
23
+ return goastorage .MakeNotValid (errors .New ("sub claim is required" ))
24
+ }
25
+ if claims .ISS == "" {
26
+ return goastorage .MakeNotValid (errors .New ("iss claim is required" ))
27
+ }
28
+
13
29
aipID , err := uuid .Parse (payload .UUID )
14
30
if err != nil {
15
31
return goastorage .MakeNotValid (errors .New ("invalid UUID" ))
@@ -18,17 +34,15 @@ func (s *serviceImpl) RequestAipDeletion(ctx context.Context, payload *goastorag
18
34
return goastorage .MakeNotValid (errors .New ("invalid reason" ))
19
35
}
20
36
21
- // TODO:
22
- // - Check AIP existence and status, same as in workflow.
23
- // - Get user details from context claim and include them in the request.
37
+ // TODO: Check AIP existence and status, same as in workflow.
24
38
25
39
_ , err = InitStorageDeleteWorkflow (ctx , s .tc , & StorageDeleteWorkflowRequest {
26
40
AIPID : aipID ,
27
41
Reason : payload .Reason ,
28
42
TaskQueue : s .config .TaskQueue ,
29
- UserEmail : "" ,
30
- UserSub : "" ,
31
- UserISS : "" ,
43
+ UserEmail : claims . Email ,
44
+ UserSub : claims . Sub ,
45
+ UserISS : claims . ISS ,
32
46
})
33
47
if err != nil {
34
48
s .logger .Error (err , "error initializing delete workflow" )
@@ -39,20 +53,33 @@ func (s *serviceImpl) RequestAipDeletion(ctx context.Context, payload *goastorag
39
53
}
40
54
41
55
func (s * serviceImpl ) ReviewAipDeletion (ctx context.Context , payload * goastorage.ReviewAipDeletionPayload ) error {
56
+ // Authentication must be enabled for now.
57
+ claims := auth .UserClaimsFromContext (ctx )
58
+ if claims == nil {
59
+ return goastorage .MakeNotValid (errors .New ("authentication is required" ))
60
+ }
61
+ if claims .Email == "" {
62
+ return goastorage .MakeNotValid (errors .New ("email claim is required" ))
63
+ }
64
+ if claims .Sub == "" {
65
+ return goastorage .MakeNotValid (errors .New ("sub claim is required" ))
66
+ }
67
+ if claims .ISS == "" {
68
+ return goastorage .MakeNotValid (errors .New ("iss claim is required" ))
69
+ }
70
+
42
71
aipID , err := uuid .Parse (payload .UUID )
43
72
if err != nil {
44
73
return goastorage .MakeNotValid (errors .New ("invalid UUID" ))
45
74
}
46
75
47
- // TODO:
48
- // - Check AIP existence and status, and DeletionRequest.
49
- // - Get user details from context claim and include them in the signal.
76
+ // TODO: Check AIP existence and status, and DeletionRequest.
50
77
51
78
signal := DeletionReviewedSignal {
52
79
Approved : payload .Approved ,
53
- UserEmail : "" ,
54
- UserSub : "" ,
55
- UserISS : "" ,
80
+ UserEmail : claims . Email ,
81
+ UserSub : claims . Sub ,
82
+ UserISS : claims . ISS ,
56
83
}
57
84
err = s .tc .SignalWorkflow (ctx , StorageDeleteWorkflowID (aipID ), "" , DeletionReviewedSignalName , signal )
58
85
if err != nil {
0 commit comments