mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-11-21 16:27:51 -06:00
remove curl in lieu of direct HTTP grafana auth, fix docker deps
This commit is contained in:
parent
99a7be3a25
commit
1dcade630b
@ -1,7 +1,6 @@
|
||||
FROM eclipse-temurin:17-jdk
|
||||
RUN apk --no-cache add curl
|
||||
|
||||
COPY nb5/target/nb5.jar nb5.jar
|
||||
ENTRYPOINT ["java","-jar", "nb5.jar"]
|
||||
RUN apk add --update udev
|
||||
#RUN apk add --update udev
|
||||
RUN mkdir -p /nosqlbench
|
||||
|
@ -20,7 +20,6 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.nosqlbench.engine.clients.grafana.annotator.GrafanaMetricsAnnotator;
|
||||
import io.nosqlbench.engine.clients.grafana.authorizers.CurlCmdInjector;
|
||||
import io.nosqlbench.engine.clients.grafana.authorizers.RawSocketInjector;
|
||||
import io.nosqlbench.engine.clients.grafana.transfer.*;
|
||||
import io.nosqlbench.engine.clients.prometheus.PMatrixData;
|
||||
@ -545,11 +544,6 @@ public class GrafanaClient {
|
||||
if (token.isPresent()) {
|
||||
return token;
|
||||
}
|
||||
token = CurlCmdInjector.submit(apirq, rq);
|
||||
if (token.isPresent()) {
|
||||
return token;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
logger.error("Error while using secondary method to init grafana client key after auth failure: " + e2, e2);
|
||||
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.clients.grafana.authorizers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.nosqlbench.engine.clients.grafana.ApiToken;
|
||||
import io.nosqlbench.engine.clients.grafana.transfer.ApiTokenRequest;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CurlCmdInjector {
|
||||
private final static Logger logger = LogManager.getLogger("GRAFANA-CURL-AUTH");
|
||||
|
||||
public static Optional<ApiToken> submit(ApiTokenRequest apirq, HttpRequest rq) {
|
||||
try {
|
||||
ProcessBuilder curlProcessSpec = new ProcessBuilder();
|
||||
String requestJson = """
|
||||
{
|
||||
"Name": "NAME",
|
||||
"Role": "ROLE"
|
||||
}
|
||||
""".replace("NAME", apirq.getName() + "_" + System.currentTimeMillis())
|
||||
.replace("ROLE", apirq.getRole())
|
||||
.replaceAll("\n", "");
|
||||
|
||||
String binname=null;
|
||||
for (String potentialPath : new String[]{"/bin", "/usr/bin", "/usr/local/bin"}) {
|
||||
String filename = potentialPath+ File.separator + "curl";
|
||||
if (Files.exists(Path.of(filename))) {
|
||||
binname=filename;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (binname==null) {
|
||||
logger.error("Unable to find binary path for curl command");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
String[] args = new String[]{
|
||||
binname, "-s", "-XPOST", rq.uri().toString(),
|
||||
"-H", "Content-Type: application/json",
|
||||
"-d", requestJson
|
||||
};
|
||||
|
||||
curlProcessSpec.command(
|
||||
args
|
||||
);
|
||||
|
||||
// curlProcessSpec.inheritIO();
|
||||
Process curlProcess = curlProcessSpec.start();
|
||||
|
||||
|
||||
// OutputStream stdinStream = curlProcess.getOutputStream();
|
||||
|
||||
InputStream stdoutStream = curlProcess.getInputStream();
|
||||
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdoutStream));
|
||||
InputStream errorStream = curlProcess.getErrorStream();
|
||||
BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream));
|
||||
|
||||
curlProcess.waitFor();
|
||||
|
||||
CharBuffer errorBuffer = CharBuffer.allocate(1000000);
|
||||
while (errorReader.ready()) {
|
||||
errorReader.read(errorBuffer);
|
||||
}
|
||||
errorBuffer.flip();
|
||||
String errorContents = errorBuffer.toString();
|
||||
if (errorContents.length() > 0) {
|
||||
logger.error("stderr from curl command follows:\n" + errorContents);
|
||||
}
|
||||
|
||||
int status = curlProcess.exitValue();
|
||||
if (status != 0) {
|
||||
logger.error("exit status " + status + " from curl command indicates error");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
CharBuffer stdoutBuffer = CharBuffer.allocate(1000000);
|
||||
while (stdoutReader.ready()) {
|
||||
stdoutReader.read(stdoutBuffer);
|
||||
}
|
||||
stdoutBuffer.flip();
|
||||
String stdoutContents = stdoutBuffer.toString();
|
||||
if (stdoutContents.length() == 0) {
|
||||
logger.error("unable to read contents of curl command output");
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
ApiToken apiToken = gson.fromJson(stdoutContents, ApiToken.class);
|
||||
return Optional.of(apiToken);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while parsing response from api token request: " + stdoutContents);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("error while trying to authorized grafana client via curl comment: " + e, e);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.clients.grafana.authorizers;
|
||||
|
||||
import io.nosqlbench.engine.clients.grafana.ApiToken;
|
||||
import io.nosqlbench.engine.clients.grafana.transfer.ApiTokenRequest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CurlCmdInjectorTest {
|
||||
|
||||
private static ApiTokenRequest apiRequest;
|
||||
private static HttpRequest rq;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
apiRequest = new ApiTokenRequest("testrole", "Admin", 1000000);
|
||||
HttpRequest.Builder rqB = HttpRequest.newBuilder(URI.create("http://admin:admin@localhost:3000/api/auth/keys"));
|
||||
rqB.header("Content-Type","application/json");
|
||||
rq = rqB.build();
|
||||
}
|
||||
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
public void testCurlCmdAuthorizer() {
|
||||
Optional<ApiToken> result = CurlCmdInjector.submit(apiRequest, rq);
|
||||
System.out.println("result:\n"+ result);
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
public void testDirectSocketAuthorizer() {
|
||||
Optional<ApiToken> result = RawSocketInjector.submit(apiRequest, rq);
|
||||
System.out.println("result:\n" + result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user