grafana api tokens

This commit is contained in:
Jonathan Shook 2020-11-16 17:22:35 -06:00
parent e6e70f713f
commit 089a29d846
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package io.nosqlbench.engine.clients.grafana;
public class ApiToken {
private String name;
private String key;
public ApiToken(String name, String key) {
this.name = name;
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public String toString() {
return "ApiToken{" +
"name='" + name + '\'' +
", key='" + key + '\'' +
'}';
}
}

View File

@ -0,0 +1,36 @@
package io.nosqlbench.engine.clients.grafana.transfer;
import java.util.Set;
public class ApiTokenRequest {
public static final Set<String> VALID_ROLES = Set.of("Admin", "Editor", "Viewer");
private final String name;
private final String role;
private final long ttl;
public ApiTokenRequest(String name, String role, long ttl) {
this.name = name;
this.role = checkRole(role);
this.ttl = ttl;
}
private String checkRole(String role) {
if (!VALID_ROLES.contains(role)) {
throw new RuntimeException("Role '" + role + "' must be one of " + VALID_ROLES.toString());
}
return role;
}
public String getName() {
return name;
}
public String getRole() {
return role;
}
public long getTtl() {
return ttl;
}
}