Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Create remote dashboard #2416

Closed
caiohcl opened this issue Aug 23, 2018 · 11 comments
Closed

Create remote dashboard #2416

caiohcl opened this issue Aug 23, 2018 · 11 comments

Comments

@caiohcl
Copy link

caiohcl commented Aug 23, 2018

Hey!!

I've been working on automate the creation of team dashboards through Hygieia API, calling the POST /dashboard/remoteCreate API.
I can successfully run and create the team dashboard on swagger. However, when I run the same curl code on my cmd, I get the following unauthorized message:

"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/api/dashboard/remoteCreate"

The curl command is the following:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "metaData": { "applicationName": "String new application", "componentName": "String new application", "owner": { "authType": "STANDARD", "username": "admin" }, "template": "testing", "title": "dash new application", "type": "team" } }' 'http://localhost:9080/api/dashboard/remoteCreate?api_key=$apiKey'

Have anyone faced the same problem? Did I forget to include some information?

@beasknees
Copy link
Collaborator

beasknees commented Aug 24, 2018

@caiohcl - you need to create an api token for yourself. Log in as admin, then go your admin settings. Then click Generate API tokens > New. Enter the username you want to use then set your expiration date to an acceptable future date, click Create. Write you token down as you will not be able to see it again. Now take that token and insert it into this command: echo 'PasswordIsAuthToken:{"apiKey":"<api-token-you-created>"} | base64. Save the output.

Now when you issue create dashboard requests you need to set two headers. apiUser and Authorization. apiUser value is the user you create and Authorization value will be apiToken <base64 encoded result>.

@caiohcl
Copy link
Author

caiohcl commented Aug 24, 2018

@matthewbeasley , it worked! Thank you!!!

@caiohcl caiohcl closed this as completed Aug 24, 2018
@alekya123
Copy link

Hi caiohcl
could you please provide the whole working curl command. so that it will be useful for me.

@caiohcl
Copy link
Author

caiohcl commented Apr 24, 2019

Hey @alekya123
Following the curl command I've been using. It creates a brand new team dashboard, adding Build, Deploy, Code Quality (sonar), Jira and Bitbucket widgets.

curl -X POST --header 'Content-Type: application/json' --header 'apiUser: <apiUser>' --header 'Authorization: apiToken <apiToken>' --header 'Accept: application/json' -d '{ "buildEntries": [ { "description": "<jenkins_job_name>", "niceName":"<niceName>", "options": { "instanceUrl": "<build_url>", "jobName": "<jenkins_job_name>", "jobUrl": "<jenkins_job_url>" }, "pushed": false, "toolName": "Hudson" } ], "deploymentEntries":[ { "description": "<application_name>", "niceName": "<niceName>", "pushed": true, "toolName": "Jenkins", "options": { "applicationName": "<application_name>", "instanceUrl": "<deploy_url>" } } ], "staticCodeEntries":[ { "description": "<sonar_project_Name>", "pushed": false, "options":{ "projectName": "<sonar_project_Name>", "instanceUrl":"<sonar_url>" }, "toolName":"Sonar" } ], "codeRepoEntries": [ { "description": "Hygieia-dashboard", "options": { "password": "<pwd>", "userID": "<user>", "url": "<code_repo_url>", "branch": "<branch_name>" }, "pushed": false, "toolName": "Bitbucket" } ], "featureEntries": [ { "toolName":"Jira", "description": "<jiraProjectName>", "pushed": false, "options":{ "teamName": "<$jiraTeamName"'", "featureTool":"Jira", "projectId":"<projectID>", "teamId":"<teamId>", "projectName" : "'"$jiraProjectName"'", "estimateMetricType":"count", "listType":"issues", "sprintType":"kanban", "showStatus" : { "kanban" : true, "scrum" : false } } } ], "metaData": { "applicationName": "'"$dashTitle"'", "componentName": "'"$dashTitle"'", "owner": { "authType": "STANDARD", "username": "admin" }, "template": "<template_name>", "title": "'"$dashTitle"'", "type": "team" } }' echo $hygieiaURL':9080/api/dashboard/remoteCreate'

@chenthilan
Copy link

@matthewbeasley , it worked! Thank you!!!

@caiohcl - i tried doing

echo 'PasswordIsAuthToken:{"apiKey":""}' | base64
and
echo '{"apiKey":""}' | base64
Both the above fail at 'attemptAuthentication' method with the below exception:-

image

PFA the values passed in the request and the 401 response i get...
image

what am i missing? Please let me know.

@caiohcl
Copy link
Author

caiohcl commented Jul 31, 2019

Hey @chenthilan ,

First off, log into your Hygieia instance as admin. Then, go to Settings -> Generate ApiTokens -> New. Save the apiUser you created and the apiKey generated.

After that, open your CLI and run the following command:
echo 'PasswordIsAuthToken:{"apiKey":"<key generated>"}' | base64
*replace to the apiKey you just got in the previous step.

This command will generate two lines, something like this:
image

Join them, and use the result as apiToken. Your Rest API call should be something like this:

curl -X POST --header 'Content-Type: application/json' --header 'apiUser: <apiUser>' --header 'Authorization: apiToken <UGFzc3dvcmRJc0F1dGhUb2tlbjp7ImFwaUtleSI6IkZtNi9jMUxPTkl3QndnUndRR0t1dVN6cGFMOGxyVnRiIn0K>' --header 'Accept: application/json'
*replace to the apiUser you have set in the first step.

You should be authorized now. Let me know if you face any other issue.

@hammad-bbc
Copy link

hello, I am trying to use the above Authorization token for github webhook. There is no option to set it up within in github webhook setup interface. Is there a way to set it up please?

@rvema
Copy link
Contributor

rvema commented Sep 17, 2019

@hammad-bbc github webhook does not require web token. However it needs webHook.gitHub.userAgent=GitHub-Hookshot and
webHook.gitHub.githubEnterpriseHosts[0]=<give your enterprise host name>properties added to api properties

@hammad-bbc
Copy link

hammad-bbc commented Sep 19, 2019

@rvema thanks for your reply. our url is www.github.com/[companyname]. Should we just use this url as value for webHook.gitHub.githubEnterpriseHosts[0] as we are not on enterprise github?

Also, we use 2 factor auth, is that going to create any hurdles when we use github collector or webhook?

I have also tried postman to post the github webhook payload along with adding a authorisation header that hygieia required and did manage to post it to hygiei. I can see the commit info on to the widget.

@rvema
Copy link
Contributor

rvema commented Sep 19, 2019

@hammad-bbc just github.com should be enough

@rzheng7
Copy link

rzheng7 commented Jan 4, 2021

@caiohcl @matthewbeasley @rvema,

Currently, I'm able to create a dashboard, but no widgets. I found the activeWidgets attribute is empty after the remoteCreate API finishes. Do you think that adding the activeWidgets in DashboardMetaData would be the right approach to fix this problem?

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants