In the host machine I use :
curl -k -X 'POST' -v http://10.1.1.186:5000/v2.0/tokens -d '{"auth":{"passwordCredentials":{"username": "guol", "password":"123456"}}}' -H 'Content-type: application/json' | python -mjson.tool
to generate the token:
...
* Closing connection 0
{
"access": {
"metadata": {
"is_admin": 0,
"roles": []
},
"serviceCatalog": [],
"token": {
"audit_ids": [
"HqVGww9JT2G2wSKzd9v3uA"
],
"expires": "2017-08-16T13:16:14Z",
"id": "gAAAAABZlDeOO4s1MCfXFP_b9CTl_Znndpt6piBxLRiMTR2TpMp3EfA49chql2a1nfowQST-pQCqaBe53KBuRNx4moj3RYCIiS24xDALDhqpeYBSkfnVM1EP6dTSKOtEGuQGBNGe5v4RIlzu0ZXKYrmoWPgA7ZFRiw",
"issued_at": "2017-08-16T12:16:14.000000Z"
},
"user": {
"id": "2a5fa182fb1b459980db09cd1572850e",
"name": "admin",
"roles": [],
"roles_links": [],
"username": "admin"
}
}
}
I get the token success, but however my host machine's time is:2017/8/16 20:18, but the token time is below:
"issued_at": "2017-08-16T12:16:14.000000Z"
"expires": "2017-08-16T13:16:14Z"
EDIT
The host machine timezone is Asia/Shanghai.
The timestamp returned in the JSON file is represented as UTC. You can tell this because it uses the Z suffix.
As per ISO 8601:
UTC
If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".
Related
I'm trying to get the repo names under a Project using the Bitbucket API. The current link on the documentation says to use
curl -u username:pwd http://${bitbucket-url}/rest/api/1.0/projects/${projectkey}/repos/
Response:
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"slug": "my-repo",
"id": 1,
"name": "My repo",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PRJ",
"id": 1,
"name": "My Cool Project",
"description": "The description for my cool project.",
"public": true,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://link/to/project"
}
]
}
},
"public": true,
"links": {
"clone": [
{
"href": "ssh://git#/PRJ/my-repo.git",
"name": "ssh"
},
{
"href": "https:///scm/PRJ/my-repo.git",
"name": "http"
}
],
"self": [
{
"href": "http://link/to/repository"
}
]
}
}
],
"start": 0
}
But I only need the repo name from the response
from subprocess import call
import configparser
import subprocess
import json
import os
base_dir = os.getcwd()
DETACHED_PROCESS = 0x00000008
cmd = 'curl --url "' + bb_url + '?pagelen=100&page=' + str(page) + '" --user ' + bb_user + ':' + bb_pwd + ' --request GET --header "Accept: application/json"'
output = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=DETACHED_PROCESS).communicate()
datastore = json.loads(output[0].decode("utf-8"))
size = datastore.get("size")
values = datastore.get("values")
if(len(values)) == 0:
break
for repos in range(size):
repo_name = values[repos]["values"]["slug"]
f_initial = open (base_dir+"\\repositoryList.txt", "a+")
f_initial.write(repo_name)
f_initial.write("\n")
f_initial.close()
page = page + 1
This script will help you get the list of all the repositories in your project and write it under the file repositoryList.txt
With bash command
repoNamesJson=$(curl -D- -X GET -H "Authorization: Basic <encoded user pasword here>" -H "Content-Type: application/json" https://yourstash/rest/api/1.0/projects/ad/repos?limit=100000)
repoNames=$(echo $repoNamesJson | awk -v RS=',' '/{"slug":/ {print}' | sed -e 's/{"slug":/''/g' | sed -e 's/"/''/g')
echo $repoNames
With python-stash library
import stashy
bitbucket = stashy.connect("host", "username", "password")
projects = bitbucket.projects.list()
repos = bitbucket.repos.list()
for project in projects:
for repo in bitbucket.projects["%s" % (project["key"])].repos.list():
print(repo["name"])
print(repo["project"]['key'])
You can use BitBucket API partial responses in order to limit the fields returned by the API.
Taking excerpts from the doc page:
[...] use the fields query parameter.
The fields parameter supports 3 modes of operation:
Removal of select fields (e.g. -links)
Pulling in additional fields not normally returned by an endpoint, while still getting all the default fields (e.g. +reviewers)
Omitting all fields, except those specified (e.g. owner.display_name)
The fields parameter can contain a list of multiple comma-separated field names (e.g. fields=owner.display_name,uuid,links.self.href). The parameter itself is not repeated.
So in your case would be something like:
curl -u username:pwd
http://${bitbucket-url}/rest/api/1.0/projects/${projectkey}/repos?fields=values.slug
Though I must say that the JSON output is not flat, it will still retain its original structure:
{
"values": [
{
"slug": "your repo slug #1"
},
...
So, if you actually want only a list with each repo slug on its own line, there's still some leg work to do.
I have successfully tested the first few intents of my app with my webhook in the DialogFlow console, but testing in the Simulator gives the following error:
UnparseableJsonResponse API Version 2: Failed to parse JSON response
string with 'INVALID_ARGUMENT' error: ": Cannot find field.".
NB!!!
The first thing to notice is that it refers to "API Version 2".
No requests are reaching my webhook - so it appears that this is all within Google.
Using Chrome Developer Tools, I see the Network entry that gets this error response - some details below:
Request url from Simulator: https://assistant.clients6.google.com/v1/assistant:converse?alt=json&key=A.....
NB!!!
(Note it says 'v1')
Request Payload:
{"conversationToken":"","debugLevel":1,"inputType":"KEYBOARD","locale":"en-US","mockLocation":{"city":"Mountain View","coordinates":{"latitude":37.421980615353675,"longitude":-122.08419799804688},"formattedAddress":"Googleplex, Mountain View, CA 94043, United States","zipCode":"94043"},"query":"Talk to ","surface":"PHONE"}
Response:
{
"response": "Connect the docs isn't responding right now. Try again soon.",
"conversationToken": "GidzaW11bGF0b3JfZGV2aWNlXzM3MTQxRERFM0I0Nzk1Q0ZfMDAwMDA=",
"audioResponse": "//NExAAR... encoded audio ...",
"debugInfo": {
"assistantToAgentDebug": {
"curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=...token...' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: ...authorization key...' -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"...user id...\",\"locale\":\"en-US\",\"lastSeen\":\"2017-12-15T17:22:55Z\"},\"conversation\":{\"conversationId\":\"1513778713541\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"Talk to Connect The Docs\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]}]}'",
"assistantToAgentJson": "{\"user\":{\"userId\":\"...user id...\",\"locale\":\"en-US\",\"lastSeen\":\"2017-12-15T17:22:55Z\"},\"conversation\":{\"conversationId\":\"1513778713541\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"Talk to Connect The Docs\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]}]}"
},
"agentToAssistantDebug": {
"agentToAssistantJson": "{\"message\":\"Unexpected apiai response format: Empty speech response\",\"apiResponse\":{\"id\":\"24ddbf1c-3930-40c6-ba50-03c0935cd1d0\",\"timestamp\":\"2017-12-20T14:05:13.766Z\",\"lang\":\"en-us\",\"result\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"1513778713541\"}}"
},
"sharedDebugInfo": [{
"name": "ResponseValidation",
"subDebugEntry": [{
"name": "UnparseableJsonResponse",
"debugInfo": "API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: \": Cannot find field.\"."
}]
}]
},
"visualResponse": {}
}
I have been informed by Google Support that I am indeed using version V2 - I initiated this in December 2017 - long after the May 2017 "cutoff date" where V2 is supposed to be the default.
Is this a Google bug? Have I missed something setting up my intents? Or is there another setting that may be causing this?
I see that other posts in the DialogFlow forum show the same problem.
Any help is appreciated.
Added on 1/9/2018:
Contents of the Debug Tab:
{
"agentToAssistantDebug": {
"agentToAssistantJson": {
"message": "Unexpected apiai response format: Empty speech response",
"apiResponse": {
"id": "64a900d2-23e8-4833-b9de-0b207f63bffc",
"timestamp": "2018-01-08T21:08:36.821Z",
"lang": "en-us",
"result": {},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "1515445716570"
}
}
},
"assistantToAgentDebug": {
"assistantToAgentJson": {
"user": {
"userId": "ABwppHFGoTJm5fKpau6WWwufKQE5UwkebooowZF7YhvD7PPY-hUfxU2_KRpB0LLNcLPyXasbXnRxXT6fniKk",
"locale": "en-US",
"lastSeen": "2018-01-05T15:53:11Z"
},
"conversation": {
"conversationId": "1515445716570",
"type": "NEW"
},
"inputs": [
{
"intent": "actions.intent.MAIN",
"rawInputs": [
{
"inputType": "VOICE",
"query": "talk to connect the docs"
}
]
}
],
"surface": {
"capabilities": [
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
},
"isInSandbox": true,
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.SCREEN_OUTPUT"
}
]
}
]
},
"curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=0ffc8bcf72704850a4b4139d49a8d72e' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: eyJhbGciOiJSUzI1NiIsImtpZCI6IjBhYTQ1NDFlNGM4ZWVhODQ0NjhmZTYxYTkzZmIxYzA2MzJkYjVhMGYifQ.eyJhdWQiOiJhY3RpdmUtZG9jdW1lbnQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJqdGkiOiIwY2U2OTdlNmE3NGFiZmVmZTdiYzhmMGU2ZGJlMzEyMDFjOWU3MzA5IiwiaWF0IjoxNTE1NDQ1NzE2LCJleHAiOjE1MTU0NDU4MzYsIm5iZiI6MTUxNTQ0NTQxNn0.hZNpVrH4o8ObGIvZ7BQV44nymekTWR_K4_jsDKCzgj74z57IDyUXNGEZs6KUFxBM_2FXiSoOxJUQZ1OhDRpkpQ6L4LELYN_JDhly7kgy-SLgKgLG6FZ4YV-8qOgr9Uxmr9SsG6NSXdiG7HvTrHLXIwA8K2siBNGGDWAIB691gAC8qsjsq4d3VnHMTeqlJ6mDoOtZ2xdLnJbK5B-OK-rLHEhX6K1-Z7rXQL3OgSwUtRVvYfHI3jqY83Xn3-uf06izkQhwVqH-W6X1REltrlxFTPW2h72D-st-QQ9euIpK3fn0x-z3ouQ17g-rGrPjKcOop9FejtKMT1tibxSkQ7qywQ' -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"ABwppHFGoTJm5fKpau6WWwufKQE5UwkebooowZF7YhvD7PPY-hUfxU2_KRpB0LLNcLPyXasbXnRxXT6fniKk\",\"locale\":\"en-US\",\"lastSeen\":\"2018-01-05T15:53:11Z\"},\"conversation\":{\"conversationId\":\"1515445716570\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"talk to connect the docs\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.WEB_BROWSER\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]}]}'"
},
"sharedDebugInfo": [
{
"name": "ResponseValidation",
"subDebugEntry": [
{
"debugInfo": "API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: \": Cannot find field.\".",
"name": "UnparseableJsonResponse"
}
]
}
]
}
Contents of the Validation Errors Tab:
UnparseableJsonResponse
API Version 2: Failed to parse JSON response string with
'INVALID_ARGUMENT' error: ": Cannot find field.".
Screenshot of welcome intent added 1/10/2018:
The problem is a combination of two things:
There are no text replies set in the Response section.
When the Intent is triggered, it does not get sent to a webhook.
As a result, Dialogflow replies to the Assistant with no text response, which is an error.
You can correct this by making sure your welcome intent does one of the following (you don't have to do both):
Set one or more text replies. These would be sent back when the Intent is called.
Check the Use webhook box under Fulfillment. This would call your webhook when the Intent is triggered. (And then make sure that your webhook returns a valid response.)
As you speculated in your comments, you could also change the Welcome Intent to one of your other Intents that you've already tested to respond. There is nothing special about this particular Welcome Intent - it was just the one created by default for you.
I have an account of an openstack swift and I can access objects in the swift using my user name and password. And my openstack swift adopt keystore to deal with auth.
Now I want to generate a token and another one can access an object in the swift only using the token. And the token will expire after a period.Can I do this? How can I do it?
First generate a token using:
$ curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog
-H "Content-Type: application/json" -d '{ "auth": { "identity": { "methods": ["password"],
"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"},
"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } },
"scope": { "project": { "domain": { "name": "'"$OS_PROJECT_DOMAIN_NAME"'" },
"name": "'"$OS_PROJECT_NAME"'" } } }}' \
| python -m json.tool
Then get the toke using:
$Keystone token-get
I used below method to get Auth-token and i got the output as below.But if use that id as Auth-token for PUT method it's not working it's showing as explained below.
curl -sd '{"auth":{"passwordCredentials":{"username": "admin", "password": "password"}}}' -H "Content-type: application/json" http://169.0.0.11:5000/v2.0/tokens | python -m json.tool
{
"access": {
"metadata": {
"is_admin": 0,
"roles": []
},
"serviceCatalog": [],
"token": {
"audit_ids": [
"GgpxHyihQVyuI1ryerQZVw"
],
"expires": "2016-08-15T16:11:49Z",
"id": "bcced26a96304e8197fa85e110df9aa2",
"issued_at": "2016-08-15T15:11:49.386446"
},
"user": {
"id": "a5064af3b125449a9a09e9b69966f843",
"name": "admin",
"roles": [],
"roles_links": [],
"username": "admin"
}
}
}
curl -i -X PUT "X-Auth-Token:bcced26a96304e8197fa85e110df9aa2" http://169.0.0.11/dashboard/project/containers/test/mymusic/
but its saying that Could not resolve host: X-AUTH-TOKEN HTTP/1.1 301 MOVED PERMANENTLY
can any one help me to solve this problem please.
I believe you have missed to add -H for Header, rest looks fine.
curl -i -X PUT -H "X-Auth-Token:bcced26a96304e8197fa85e110df9aa2" http://169.0.0.11/dashboard/project/containers/test/mymusic/
I am trying to import a cURL command into Postman, but it says I have a missing argument, but the cURL command works when I run it at the command line, here is the cURL command:
curl -XGET 'http://scpt-wc-ap.sys.bombast.net:9200/_all/_search?pretty' -d '{
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"query_string": {
"query": "source:smart_connect"
}
}
]
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"#timestamp": {
"from": 1439899750653,
"to": 1439903350653
}
}
}
]
}
}
}
},
"highlight": {
"fields": {},
"fragment_size": 2147483647,
"pre_tags": [
"#start-highlight#"
],
"post_tags": [
"#end-highlight#"
]
},
"size": 500,
"sort": [
{
"_score": {
"order": "desc",
"ignore_unmapped": true
}
}
]
}'
the error looks like:
any idea what is wrong the cURL command? Like I said it works when I run it at the command line.
Perhaps you can just help me translate the cURL command into HTTP, I assume it's an HTTP GET, but I don't know what the -d flag is doing besides passing data in some form.
Your curl command needs a space between -X and GET
see curl -GET and -X GET for more information about curl curl GET vs curl -X GET
Edit: It looks like this is just a postman thing, weird. Bug Maybe?
I was able to successfully import your request into postman using this:
curl -X GET 'http://scpt-wc-ap.sys.bombast.net:9200/_all/_search?pretty' -d '{"query":{"filtered":{"query":{"bool":{"should":[{"query_string":{"query":"source:smart_connect"}}]}},"filter":{"bool":{"must":[{"range":{"#timestamp":{"from":1439899750653,"to":1439903350653}}}]}}}},"highlight":{"fields":{},"fragment_size":2147483647,"pre_tags":["#start-highlight#"],"post_tags":["#end-highlight#"]},"size":500,"sort":[{"_score":{"order":"desc","ignore_unmapped":true}}]}'
Copying the curl request from the webinfo window in Safari resulted in a curl request with -XGET (without a space).
Adding the space between -X and GET made importing in Postman possible.