I want to enable authentication on my test host deployed with Nebula Graph, but I cannot find a way to do it without shutting the service down. I really don't want to do this.
NebulaGraph leveraged the gflags as its configuration utils. And we exposed an HTTP interface per each process, which is configured with ws_http_port to listen on.
Note, not all configurations could be changed on the fly in this "hot update" way.
Read in-memory Configurations
$ curl graphd:19669/flags | head
check_plan_killed_frequency=8
cluster_id_path="cluster.id"
expired_time_factor=5
failed_login_attempts=0
heartbeat_interval_secs=10
meta_client_retry_interval_secs=1
meta_client_retry_times=3
meta_client_timeout_ms=60000
password_lock_time_in_secs=0
storage_client_retry_interval_ms=1000
$ curl graphd:19669/flags?flags=ws_http_port
ws_http_port=19669
Update in-memory configuration
$ curl graphd:19669/flags?flags=system_memory_high_watermark_ratio
system_memory_high_watermark_ratio=0.8
$ curl -X PUT graphd:19669/flags \
-H "Content-Type: application/json" \
-d '{"system_memory_high_watermark_ratio":"0.9"}'
$ curl graphd:19669/flags?flags=system_memory_high_watermark_ratio
system_memory_high_watermark_ratio=0.9
Ref:
We could check all webservice endpoints here
Status WebService::start(uint16_t httpPort) {
if (started_) {
LOG(INFO) << "Web service has been started.";
return Status::OK();
}
router().get("/flags").handler([](web::PathParams&& params) {
DCHECK(params.empty());
return new GetFlagsHandler();
});
router().put("/flags").handler([](web::PathParams&& params) {
DCHECK(params.empty());
return new SetFlagsHandler();
});
router().get("/stats").handler([](web::PathParams&& params) {
DCHECK(params.empty());
return new GetStatsHandler();
});
router().get("/status").handler([](web::PathParams&& params) {
DCHECK(params.empty());
return new StatusHandler();
});
router().get("/").handler([](web::PathParams&& params) {
DCHECK(params.empty());
return new StatusHandler();
});
Related
I come from a land of ASP.NET Core. Having fun learning a completely new stack.
I'm used to being able to:
name a route "orders"
give it a path like /customer-orders/{id}
register it
use the routing system to build a URL for my named route
An example of (4) might be to pass a routeName and then routeValues which is an object like { id = 193, x = "y" } and the routing system can figure out the URL /customer-orders/193?x=y - notice how it just appends extraneous key-vals as params.
Can I do something like this in oak on Deno?? Thanks.
Update: I am looking into some functions on the underlying regexp tool the routing system uses. It doesn't seem right that this often used feature should be so hard/undiscoverable/inaccessible.
https://github.com/pillarjs/path-to-regexp#compile-reverse-path-to-regexp
I'm not exactly sure what you mean by "building" a URL, but the URL associated to the incoming request is defined by the requesting client, and is available in each middleware callback function's context parameter at context.request.url as an instance of the URL class.
The documentation provides some examples of using a router and the middleware callback functions that are associated to routes in Oak.
Here's an example module which demonstrates accessing the URL-related data in a request:
so-74635313.ts:
import { Application, Router } from "https://deno.land/x/oak#v11.1.0/mod.ts";
const router = new Router({ prefix: "/customer-orders" });
router.get("/:id", async (ctx, next) => {
// An instance of the URL class:
const { url } = ctx.request;
// An instance of the URLSearchParams class:
const { searchParams } = url;
// A string:
const { id } = ctx.params;
const serializableObject = {
id,
// Iterate all the [key, value] entries and collect into an array:
searchParams: [...searchParams.entries()],
// A string representation of the full request URL:
url: url.href,
};
// Respond with the object as JSON data:
ctx.response.body = serializableObject;
ctx.response.type = "application/json";
// Log the object to the console:
console.log(serializableObject);
await next();
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
function printStartupMessage({ hostname, port, secure }: {
hostname: string;
port: number;
secure?: boolean;
}): void {
if (!hostname || hostname === "0.0.0.0") hostname = "localhost";
const address =
new URL(`http${secure ? "s" : ""}://${hostname}:${port}/`).href;
console.log(`Listening at ${address}`);
console.log("Use ctrl+c to stop");
}
app.addEventListener("listen", printStartupMessage);
await app.listen({ port: 8000 });
In a terminal shell (I'll call it shell A), the program is started:
% deno run --allow-net so-74635313.ts
Listening at http://localhost:8000/
Use ctrl+c to stop
Then, in another shell (I'll call it shell B), a network request is sent to the server at the route described in your question — and the response body (JSON text) is printed below the command:
% curl 'http://localhost:8000/customer-orders/193?x=y'
{"id":"193","searchParams":[["x","y"]],"url":"http://localhost:8000/customer-orders/193?x=y"}
Back in shell A, the output of the console.log statement can be seen:
{
id: "193",
searchParams: [ [ "x", "y" ] ],
url: "http://localhost:8000/customer-orders/193?x=y"
}
ctrl + c is used to send an interrupt signal (SIGINT) to the deno process and stop the server.
I am fortunately working with a React developer today!
Between us, we've found the .url(routeName, ...) method on the Router instance and that does exactly what I need!
Here's the help for it:
/** Generate a URL pathname for a named route, interpolating the optional
* params provided. Also accepts an optional set of options. */
Here's it in use in context:
export const routes = new Router()
.get(
"get-test",
"/test",
handleGetTest,
);
function handleGetTest(context: Context) {
console.log(`The URL for the test route is: ${routes.url("get-test")}`);
}
// The URL for the test route is: /test
I have a URL for my file type .ies that is uploaded on firebase storage and I want to read the content inside the file but when I hit URL on the browser it only returns the information about the file, not the content
Example link: https://firebasestorage.googleapis.com/v0/b/westgatedash-d1341.appspot.com/o/documents%2FIES%2FCDL2-45W-M-120V_IESNA2002.IES
but when I use query params alt=media it downloads that I don't want.
Are there any query params to get the data of the file? or any way to achieve the goal ?
According to the documentation, each call is different and for different purposes:
Listing objects:
To list the objects in a bucket:
curl -X GET -H "Authorization: Bearer OAUTH2_TOKEN" \
"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o"
Downloading objects:
curl -X GET \
-H "Authorization: Bearer OAUTH2_TOKEN" \
-o "SAVE_TO_LOCATION" \
"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME?alt=media"
The difference when hitting the endpoint is, precisely, the alt=media param. What I understand is that you might want to stream the object? If so, you can achieve it through the client libraries. For instance:
To handle the file on a Cloud Function you can follow this guide you will find more detailed info. As a summary, to download a file:
// Download file from bucket.
const bucket = admin.storage().bucket(fileBucket);
const tempFilePath = path.join(os.tmpdir(), fileName);
const metadata = {
contentType: contentType,
};
await bucket.file(filePath).download({destination: tempFilePath});
console.log('Image downloaded locally to', tempFilePath);
This will save the image to a temporary folder since this is the recommended way to do it.
Use gcs.bucket.file(filePath).download to download a file to a temporary directory on your Cloud Functions instance. In this location, you can process the file as needed.
EDIT
According to Downloads Documentation:
You can send download requests to Cloud Storage in the following ways:
Simple download: Downloading objects to a destination.
Streaming download: Downloading data to a process.
Sliced object download: Downloading large objects.
In the Docs, following the GitHub Repo: For C++ it shows a stream downloading:
void ReadObject(google::cloud::storage::Client client,
std::vector<std::string> const& argv) {
//! [read object] [START storage_download_file]
namespace gcs = google::cloud::storage;
[](gcs::Client client, std::string const& bucket_name,
std::string const& object_name) {
gcs::ObjectReadStream stream = client.ReadObject(bucket_name, object_name);
int count = 0;
std::string line;
while (std::getline(stream, line, '\n')) {
++count;
}
std::cout << "The object has " << count << " lines\n";
}
//! [read object] [END storage_download_file]
(std::move(client), argv.at(0), argv.at(1));
}
But for NodeJs, for some reason, it doesn't. I was not able to find any example of that. On the other hand there are other questions in SatckOverflow with the same question, i.e: this:
const {Storage} = require('#google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket(bucket);
const remoteFile = bucket.file(file);
let buffer = '';
remoteFile.createReadStream()
.on('error', function(err) {console.log(err)})
.on('data', function(response) {
buffer += response
})
.on('end', function() {
//console.log(buffer);
res.send(buffer);
})
On GitHub, a user can have pinned repositories.
There's also the Repositories section of the API describing how to make requests that involve repos. You can also get information about the orgs a user is part of as described in another answer (which can be pinned).
However, I want to access a user's pinned repos. For example given the following profile:
I'd like to be able to do the following:
$ curl -s <some endpoint with some parameters> | <some pipeline with some filtering>
str
liffy_diffy
spiralify
micro-twitter
kit
xdoc
So I'm wondering:
What is the endpoint and parameters do I need to get a user's pinned repos?
I was able to use the nokogiri gem to parse the html. However, it seems like I should be api to accomplish the same thing with a simple HTTP request:
$ ./get_user_pinned_repos mbigras
str
liffy_diffy
spiralify
micro-twitter
kit
xdoc
Code:
#!/usr/bin/env ruby
# get a user's pinned repos
require 'rubygems'
require 'nokogiri'
require 'open-uri'
if ARGV.length != 1
STDERR.puts "usage: get_user_pinned_repos <username>"
exit 1
end
username = ARGV.first
profile_url = "https://github.com/#{username}"
page = Nokogiri::HTML(open(profile_url))
page.css("span.repo").each { |repo| puts repo.text }
An update to the original answer:
The changelog for GitHub GraphQL schema (2019-03-30) mentions that the
pinnedRepositories will be deprecated or removed by 2019-07-01. GraphQL API users are requested to use ProfileOwner.pinnedItems instead.
Examples to retrieve pinned repositories using ProfileOwner.pinnedItems:
Example 1:
query {
user(login:"kranthilakum") {
pinnedItems(first: 5, types: [REPOSITORY, GIST]) {
totalCount
edges {
node {
... on Repository {
name
}
}
}
}
}
}
Try Example 1 in the GraphQL API Explorer
Example 2:
query {
repositoryOwner(login: "kranthilakum") {
... on ProfileOwner {
pinnedItemsRemaining
itemShowcase {
items(first: 5) {
totalCount
edges {
node {
... on Repository {
name
}
}
}
}
hasPinnedItems
}
}
}
}
Try Example 2 in GraphQL API Explorer
Outdated
You can get pinned repository using Github GraphQL API :
{
repositoryOwner(login: "bertrandmartel") {
... on User {
pinnedRepositories(first:6) {
edges {
node {
name
}
}
}
}
}
}
Try it in the explorer
You can request it with curl with :
curl -H "Authorization: bearer TOKEN" --data-binary #- https://api.github.com/graphql <<EOF
{
"query": "query { repositoryOwner(login: \"bertrandmartel\") { ... on User { pinnedRepositories(first:6) { edges { node { name } } } } } }"
}
EOF
You can parse the JSON output with jq JSON parser :
username=bertrandmartel
curl -s -H "Authorization: bearer TOKEN" \
-d '{ "query": "query { repositoryOwner(login: \"'"$username"'\") { ... on User { pinnedRepositories(first:6) { edges { node { name } } } } } }" }' \
https://api.github.com/graphql | \
jq -r '.data.repositoryOwner.pinnedRepositories.edges[].node.name'
Go to this URL and type your username and hit the "go" button. There you will see your pinned repos as a JSON responce.
Click here
Or else, you can replace your username in the below link.
https://gh-pinned-repos-5l2i19um3.vercel.app/?username={Username}
For more info: Click here or here
I'm a newbie trying to connect to my first API in Meteor.
The API docs (linked here) gave me a list of things I needed to generate (time-stamp, api-key & signature. I've generated them all and saved them as variables.) The docs say I need to make the following request:
curl -H "Request-Time: Wed, 06 Nov 2013 16:32:03 +0000" \
-H "Api-Key: 5d41402abc4b2a76b9719d911017c592" \
-H "Signature: 42d8824f24fb50e6793aa111c889b7df4d54bee9f5842a0d5fbca30cbfa469ae" \
http://wceaapi.org/v1.1/user/1234
How do I convert that in to Meteor Syntax?
Here's what I'm trying but I'm pretty sure it's totally wrong.
if (Meteor.isServer) {
Meteor.methods({
callAPI: function () {
this.unblock();
return Meteor.http.call("GET", "http://sandbox.wceaapi.org",
headers: {
"Request-Time" : timeStamp,
"Api-Key": key,
"Signature": hash});
}
});
}
//invoke the server method
if (Meteor.isClient) {
Meteor.call("callAPI", function(error, results) {
console.log(results.content); //results.data should be a JSON object
});
}
I need to pass a where constraint(where UserName = "User1") in Meteor http call for Parse Rest APIs. Currently, the result that I get after the below API call includes all the entries not just those where UserName is User1.
var authUrl = "https://api.parse.com/1/classes/ImageData";
Meteor.http.call("GET", authUrl, {
headers: {
"X-Parse-Application-Id": "2CMX1b4JY5xCOPrYEbSc69ucNDDh9pl5yFeqv3A3",
"X-Parse-REST-API-Key": "9UWpw6H7UuBaOEQgT7R3ANQ3rE67yxZxcMHJJaBu",
"content-type": "application/json"
},
params: {
"UserName": "User1",
}
}, function(error, result) {
console.log(JSON.parse(result.content));
}
);
The parse documentation for such an HTTP call in curl representation is:
curl -X GET \
-H "X-Parse-Application-Id: 2CMX1b4JY5xCOPrYEbSc69ucNDDh9pl5yFeqv3A3" \
-H "X-Parse-REST-API-Key: 9UWpw6H7UuBaOEQgT7R3ANQ3rE67yxZxcMHJJaBu" \
-G \
--data-urlencode 'where={"UserName":"User1"}' \
https://api.parse.com/1/classes/ImageData
How can I correctly write this in Meteor?
This seems like it works:
var util = Npm.require('util');
var url = 'https://api.parse.com/1/classes/ImageData';
var result = HTTP.get(url, {
headers: {
'X-Parse-Application-Id': '2CMX1b4JY5xCOPrYEbSc69ucNDDh9pl5yFeqv3A3',
'X-Parse-REST-API-Key': '9UWpw6H7UuBaOEQgT7R3ANQ3rE67yxZxcMHJJaBu',
'content-type': 'application/json'
},
query: 'where={"UserName":"User1"}'
});
console.log(util.inspect(result.data, {depth: null}));
Notes
Meteor.http.call is deprecated. Use the HTTP API instead. Note you will need to $ meteor add http.
Because you need a string and not a key/value pair, use query instead of params. For a GET, both are placed into the query string but your original code made the query ?Username=User1 rather than ?where....