Codota Logo
ApiKeyService
Code IndexAdd Codota to your IDE (free)

How to use
ApiKeyService
in
org.rakam.analysis

Best Java code snippets using org.rakam.analysis.ApiKeyService (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: rakam-io/rakam

@Override
public void deleteProject(String project) {
  collections.remove(project);
  apiKeyService.revokeAllKeys(project);
  super.onDeleteProject(project);
}
origin: rakam-io/rakam

@Test
public void testInvalidApiKeys() throws Exception {
  getApiKeyService().createApiKeys(PROJECT_NAME);
  try {
    getApiKeyService().getProjectOfApiKey("invalidKey", AccessKeyType.READ_KEY);
    fail();
  } catch (RakamException e) {
  }
  try {
    getApiKeyService().getProjectOfApiKey("invalidKey", AccessKeyType.WRITE_KEY);
    fail();
  } catch (RakamException e) {
  }
  try {
    getApiKeyService().getProjectOfApiKey("invalidKey", AccessKeyType.MASTER_KEY);
    fail();
  } catch (RakamException e) {
  }
}
origin: rakam-io/rakam

@JsonRequest
@ApiOperation(value = "Revoke API Keys")
@Path("/revoke-api-keys")
public SuccessMessage revokeApiKeys(@ApiParam("project") String project, @ApiParam("master_key") String masterKey) {
  apiKeyService.revokeApiKeys(project, masterKey);
  return SuccessMessage.success();
}
origin: rakam-io/rakam

    throw new RakamException("Invalid API key format.", FORBIDDEN);
  ApiKeyService.Key projectKey = apiKeyService.getProjectKey(apiKeyId, type);
  String data = CryptUtil.decryptAES(apiKey.substring(apiKeyId), projectKey.key);
  access = JsonHelper.read(data, Access.class);
String project = apiKeyService.getProjectOfApiKey(apiKey, type);
return new RequestContext(project.toLowerCase(Locale.ENGLISH), apiKey, access);
origin: rakam-io/rakam

@JsonRequest
@ApiOperation(value = "Check API Keys")
@Path("/check-api-keys")
public List<Boolean> checkApiKeys(@ApiParam("keys") List<ProjectApiKeys> keys, @ApiParam("project") String project) {
  return keys.stream().map(key -> {
    try {
      Consumer<String> stringConsumer = e -> {
        if (!e.equals(project.toLowerCase(Locale.ENGLISH))) {
          throw new RakamException(FORBIDDEN);
        }
      };
      Optional.ofNullable(key.masterKey()).map(k -> apiKeyService.getProjectOfApiKey(k, MASTER_KEY)).ifPresent(stringConsumer);
      Optional.ofNullable(key.readKey()).map(k -> apiKeyService.getProjectOfApiKey(k, READ_KEY)).ifPresent(stringConsumer);
      Optional.ofNullable(key.writeKey()).map(k -> apiKeyService.getProjectOfApiKey(k, WRITE_KEY)).ifPresent(stringConsumer);
      return true;
    } catch (RakamException e) {
      return false;
    }
  }).collect(Collectors.toList());
}
origin: rakam-io/rakam

  @Test
  public void testRevokeApiKeys() throws Exception {
    ApiKeyService.ProjectApiKeys apiKeys = getApiKeyService().createApiKeys(PROJECT_NAME);

    getApiKeyService().revokeApiKeys(PROJECT_NAME, apiKeys.masterKey());

    try {
      getApiKeyService().getProjectOfApiKey(apiKeys.readKey(), AccessKeyType.READ_KEY);
      fail();
    } catch (RakamException e) {
    }

    try {
      getApiKeyService().getProjectOfApiKey(apiKeys.writeKey(), AccessKeyType.WRITE_KEY);
      fail();
    } catch (RakamException e) {
    }

    try {
      getApiKeyService().getProjectOfApiKey(apiKeys.masterKey(), AccessKeyType.MASTER_KEY);
      fail();
    } catch (RakamException e) {
    }
  }
}
origin: rakam-io/rakam

@JsonRequest
@ApiOperation(value = "Create API Keys",
    authorizations = @Authorization(value = "master_key"))
@Path("/create-api-keys")
public ProjectApiKeys createApiKeys(@Named("project") RequestContext context) {
  return transformKeys(apiKeyService.createApiKeys(context.project));
}
origin: rakam-io/rakam

@ApiOperation(value = "Get project stats")
@JsonRequest
@Path("/stats")
public Map<String, Metastore.Stats> getStats(@BodyParam List<String> apiKeys) {
  Map<String, String> keys = new LinkedHashMap<>();
  for (String apiKey : apiKeys) {
    String project;
    try {
      project = apiKeyService.getProjectOfApiKey(apiKey, READ_KEY);
    } catch (RakamException e) {
      if (e.getStatusCode() == FORBIDDEN) {
        continue;
      }
      throw e;
    }
    keys.put(project, apiKey);
  }
  Map<String, Metastore.Stats> stats = metastore.getStats(keys.keySet());
  if (stats == null) {
    return ImmutableMap.of();
  }
  return stats.entrySet().stream()
      .collect(Collectors.toMap(e -> keys.get(e.getKey()), e -> e.getValue()));
}
origin: rakam-io/rakam

@ApiOperation(value = "Create project")
@JsonRequest
@Path("/create")
public ProjectApiKeys createProject(@ApiParam(value = "lock_key", required = false) String lockKey, @ApiParam("name") String name) {
  if (!Objects.equals(projectConfig.getLockKey(), lockKey)) {
    lockKey = lockKey == null ? "" : (lockKey.isEmpty() ? null : lockKey);
    if (!Objects.equals(projectConfig.getLockKey(), lockKey)) {
      throw new RakamException("Lock key is invalid", FORBIDDEN);
    }
  }
  String project;
  try {
    project = checkProject(name);
  } catch (IllegalArgumentException e) {
    throw new RakamException(e.getMessage(), BAD_REQUEST);
  }
  if (metastore.getProjects().contains(project)) {
    throw new RakamException("The project already exists.", BAD_REQUEST);
  }
  metastore.createProject(project);
  return transformKeys(apiKeyService.createApiKeys(project));
}
origin: rakam-io/rakam

@GET
@IgnoreApi
@ApiOperation(value = "Collect event", response = Integer.class)
@Path("/collect/*")
public void collectGet(RakamHttpRequest request) {
  String identifier = request.path().substring(20);
  List<String> writeKeyList = request.params().get("write_key");
  if (writeKeyList == null || writeKeyList.isEmpty()) {
    throw new RakamException("write_key query parameter is null", FORBIDDEN);
  }
  String project = apiKeyService.getProjectOfApiKey(writeKeyList.get(0), WRITE_KEY);
  call(request, project, identifier, request.params(), request.headers(), null);
}
origin: rakam-io/rakam

@Test
public void testCreateApiKeys() throws Exception {
  ApiKeyService.ProjectApiKeys testing = getApiKeyService().createApiKeys(PROJECT_NAME);
  assertEquals(getApiKeyService().getProjectOfApiKey(testing.readKey(), AccessKeyType.READ_KEY), PROJECT_NAME);
  assertEquals(getApiKeyService().getProjectOfApiKey(testing.writeKey(), AccessKeyType.WRITE_KEY), PROJECT_NAME);
  assertEquals(getApiKeyService().getProjectOfApiKey(testing.masterKey(), AccessKeyType.MASTER_KEY), PROJECT_NAME);
}
origin: rakam-io/rakam

@AfterMethod
public void tearDownMethod() throws Exception {
  getApiKeyService().revokeAllKeys(PROJECT_NAME);
}
origin: rakam-io/rakam

@Path("/data")
@GET
@IgnoreApi
public void data(RakamHttpRequest request) {
  Map<String, List<String>> params = request.params();
  List<String> api_key = params.get("read_key");
  if (api_key == null || api_key.isEmpty()) {
    request.response("\"read_key is missing\"", BAD_REQUEST).end();
    return;
  }
  // since this endpoint is created for clients to read the ab-testing rule,
  // the permission is WRITE_KEY
  String project = apiKeyService.getProjectOfApiKey(api_key.get(0), ApiKeyService.AccessKeyType.WRITE_KEY);
  request.response(JsonHelper.encodeAsBytes(metadata.getReports(project)))
      .end();
}
origin: rakam-io/rakam

@ApiOperation(value = "Delete project",
    authorizations = @Authorization(value = "master_key")
)
@JsonRequest
@DELETE
@Path("/delete")
public SuccessMessage deleteProject(@Named("project") RequestContext context) {
  if (!projectConfig.getAllowProjectDeletion()) {
    throw new RakamException("Project deletion is disabled, you can enable it with `allow-project-deletion` config.", NOT_IMPLEMENTED);
  }
  checkProject(context.project);
  metastore.deleteProject(context.project);
  List<MaterializedView> views = materializedViewService.list(context.project);
  for (MaterializedView view : views) {
    materializedViewService.delete(context, view.tableName);
  }
  apiKeyService.revokeAllKeys(context.project);
  return SuccessMessage.success();
}
origin: rakam-io/rakam

@POST
@IgnoreApi
@ApiOperation(value = "Collect event", response = Integer.class)
@Path("/collect/*")
public void collectPost(RakamHttpRequest request) {
  String identifier = request.path().substring(20);
  List<String> writeKeyList = request.params().get("write_key");
  if (writeKeyList == null || writeKeyList.isEmpty()) {
    throw new RakamException("write_key query parameter is null", FORBIDDEN);
  }
  String project = apiKeyService.getProjectOfApiKey(writeKeyList.get(0), WRITE_KEY);
  request.bodyHandler(inputStream -> {
    String data;
    try {
      data = new String(ByteStreams.toByteArray(inputStream), CharsetUtil.UTF_8);
    } catch (IOException e) {
      throw new RakamException("Unable to parse data: " + e.getMessage(), INTERNAL_SERVER_ERROR);
    }
    call(request, project, identifier, request.params(), request.headers(), data);
  });
}
origin: rakam-io/rakam

String project = apiKeyService.getProjectOfApiKey(master_key, MASTER_KEY);
origin: rakam-io/rakam

String project = apiKeyService.getProjectOfApiKey(readKey.get(0), READ_KEY);
origin: rakam-io/rakam

@ApiOperation(value = "Batch operation on a single user properties",
    request = SingleUserBatchOperationRequest.class, response = Integer.class,
    authorizations = {@Authorization(value = "write_key")})
@ApiResponses(value = {@ApiResponse(code = 404, message = "User does not exist.")})
@Path("/batch")
@JsonRequest
public void batchSingleUserOperations(RakamHttpRequest request) {
  request.bodyHandler(s -> {
    SingleUserBatchOperationRequest req;
    try {
      req = JsonHelper.read(s, SingleUserBatchOperationRequest.class);
    } catch (Exception e) {
      returnError(request, e.getMessage(), BAD_REQUEST);
      return;
    }
    String project = apiKeyService.getProjectOfApiKey(req.api.apiKey, WRITE_KEY);
    InetAddress socketAddress = ((InetSocketAddress) request.context().channel()
        .remoteAddress()).getAddress();
    DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, wrappedBuffer(OK_MESSAGE));
    List<Cookie> cookies = mapEvent(mapper ->
        mapper.map(project, req.data, new HttpRequestParams(request), socketAddress));
    service.batch(project, req.data);
    setBrowser(request, response);
    if (cookies != null && !cookies.isEmpty()) {
      response.headers().add(SET_COOKIE, STRICT.encode(cookies));
    }
    request.response(response).end();
  });
}
origin: rakam-io/rakam

    .map((v) -> v.get(0))
    .orElseGet(() -> request.headers().get("master_key"));
String project = apiKeyService.getProjectOfApiKey(masterKey, MASTER_KEY);
origin: rakam-io/rakam

      project = apiKeyService.getProjectOfApiKey(api.apiKey, WRITE_KEY);
    } catch (RakamException e) {
      try {
        project = apiKeyService.getProjectOfApiKey(api.apiKey, MASTER_KEY);
      } catch (Exception e1) {
        if (e.getStatusCode() == FORBIDDEN) {
  project = apiKeyService.getProjectOfApiKey(api.apiKey, WRITE_KEY);
} catch (RakamException e) {
  try {
    project = apiKeyService.getProjectOfApiKey(api.apiKey, MASTER_KEY);
  } catch (RakamException e1) {
    if (e1.getStatusCode() == FORBIDDEN) {
org.rakam.analysisApiKeyService

Most used methods

  • revokeAllKeys
  • createApiKeys
  • getProjectOfApiKey
  • revokeApiKeys
  • getProjectKey

Popular in Java

  • Updating database using SQL prepared statement
  • getSharedPreferences (Context)
  • getApplicationContext (Context)
  • onCreateOptionsMenu (Activity)
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • PrintStream (java.io)
    A PrintStream adds functionality to another output stream, namely the ability to print representatio
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now