blob: 45aefc0456ac39cc2817cd1323d4eff9f2f09880 (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.role;
import com.yahoo.jdisc.http.HttpRequest;
import java.util.EnumSet;
/**
* Action defines an operation, typically a HTTP method, that may be performed on an entity in the controller
* (e.g. tenant or application).
*
* @author mpolden
*/
public enum Action {
create,
read,
update,
delete;
static EnumSet<Action> all() {
return EnumSet.allOf(Action.class);
}
static EnumSet<Action> write() {
return EnumSet.of(create, update, delete);
}
/** Returns the appropriate action for given HTTP method */
public static Action from(HttpRequest.Method method) {
switch (method) {
case POST: return Action.create;
case GET:
case OPTIONS:
case HEAD: return Action.read;
case PUT:
case PATCH: return Action.update;
case DELETE: return Action.delete;
default: throw new IllegalArgumentException("No action defined for method " + method);
}
}
}
|