Skip to content

Instantly share code, notes, and snippets.

@dermatologist
Forked from epustobaev/metabas_embed.java
Created July 16, 2018 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermatologist/1ffa2c5b4a04cd2c3c6e9b2c1c0ed337 to your computer and use it in GitHub Desktop.
Save dermatologist/1ffa2c5b4a04cd2c3c6e9b2c1c0ed337 to your computer and use it in GitHub Desktop.
package com.example.controllers.dashboard;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.jwt.JwtHelper;
import org.springframework.security.jwt.crypto.sign.MacSigner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = {"/dashboardUrl"})
public class DashboardController {
private final String METABASE_SITE_URL = "http://somehost/metabaseUrl";
private final String METABASE_SECRET_KEY = "SOME_SECRET_KEY";
@GetMapping("")
public DashboardParams indexAction() {
Jwt token = JwtHelper.encode("{\"resource\": {\"dashboard\": 1}, \"params\": {}}", new MacSigner(METABASE_SECRET_KEY));
String url = METABASE_SITE_URL + "/embed/dashboard/" + token.getEncoded() + "#theme=night&bordered=true&titled=true";
return new DashboardParams(url);
}
class DashboardParams {
private String url;
public DashboardParams(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment