Skip to content

Commit

Permalink
pass user token to zeppelinhub rest api handler
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonycorbacho committed Nov 18, 2016
1 parent 674fb93 commit 25f6215
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ private String getUserToken(String principal) {

@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
String response = restApiClient.asyncGet("");
if (subject == null) {
return Collections.emptyList();
}
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, StringUtils.EMPTY);
List<NoteInfo> notes = GSON.fromJson(response, new TypeToken<List<NoteInfo>>() {}.getType());
if (notes == null) {
return Collections.emptyList();
Expand All @@ -201,8 +205,8 @@ public Note get(String noteId, AuthenticationInfo subject) throws IOException {
if (StringUtils.isBlank(noteId)) {
return EMPTY_NOTE;
}
//String response = zeppelinhubHandler.get(noteId);
String response = restApiClient.asyncGet(noteId);
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, noteId);
Note note = GSON.fromJson(response, Note.class);
if (note == null) {
return EMPTY_NOTE;
Expand All @@ -216,15 +220,17 @@ public void save(Note note, AuthenticationInfo subject) throws IOException {
if (note == null) {
throw new IOException("Zeppelinhub failed to save empty note");
}
String notebook = GSON.toJson(note);
restApiClient.asyncPut(notebook);
LOG.info("ZeppelinHub REST API saving note {} ", note.getId());
String jsonNote = GSON.toJson(note);
String token = getUserToken(subject.getUser());
LOG.info("ZeppelinHub REST API saving note {} ", note.getId());
restApiClient.asyncPut(token, jsonNote);
}

@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
restApiClient.asyncDel(noteId);
String token = getUserToken(subject.getUser());
LOG.info("ZeppelinHub REST API removing note {} ", noteId);
restApiClient.asyncDel(token, noteId);
}

@Override
Expand All @@ -240,8 +246,10 @@ public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationIn
}
String endpoint = Joiner.on("/").join(noteId, "checkpoint");
String content = GSON.toJson(ImmutableMap.of("message", checkpointMsg));
String response = restApiClient.asyncPutWithResponseBody(endpoint, content);

String token = getUserToken(subject.getUser());
String response = restApiClient.asyncPutWithResponseBody(token, endpoint, content);

return GSON.fromJson(response, Revision.class);
}

Expand All @@ -251,7 +259,10 @@ public Note get(String noteId, String revId, AuthenticationInfo subject) throws
return EMPTY_NOTE;
}
String endpoint = Joiner.on("/").join(noteId, "checkpoint", revId);
String response = restApiClient.asyncGet(endpoint);

String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, endpoint);

Note note = GSON.fromJson(response, Note.class);
if (note == null) {
return EMPTY_NOTE;
Expand All @@ -268,7 +279,8 @@ public List<Revision> revisionHistory(String noteId, AuthenticationInfo subject)
String endpoint = Joiner.on("/").join(noteId, "checkpoint");
List<Revision> history = Collections.emptyList();
try {
String response = restApiClient.asyncGet(endpoint);
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, endpoint);
history = GSON.fromJson(response, new TypeToken<List<Revision>>(){}.getType());
} catch (IOException e) {
LOG.error("Cannot get note history", e);
Expand Down

0 comments on commit 25f6215

Please sign in to comment.