Upload file on Linux (CLI) to Dropbox (via bash/sh)? - linux

I need to save (and overwrite) a file via the cron (hourly) to my dropbox account. The file needs to be stored in a predefined location (which is shared with some other users).
I have seen the possibility to create a Dropbox App, but that create its own dropbox folder.
Also looked at Dropbox Saver but that seems for browsers.
I was thinking (hoping) something super lightweight, a long the lines of CURL, so i don't need to install libraries. Just a simple sh script would be awesome. I only need to PUT the file (overwrite), no need to read (GET) it back.
Was going thru the dropbox developer API documentation, but kind of got lost.
Anybody a good hint?

First, since you need to access an existing shared folder, register a "Dropbox API" app with "Full Dropbox" access:
https://www.dropbox.com/developers/apps/create
Then, get an access token for your account for your app. The easiest way is to use the "Generate" button on your app's page, where you'll be sent after you create the app. It's also accessible via the App Console.
Then, you can upload to a specified path via curl as shown in this example:
This uploads a file from the local path matrices.txt in the current folder to /Homework/math/Matrices.txt in the Dropbox account, and returns the metadata for the uploaded file:
echo "some content here" > matrices.txt
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <ACCESS_TOKEN>" \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary #matrices.txt
<ACCESS_TOKEN> should be replaced with the OAuth 2 access token.

#Greg's answer also works but seems like a long chore.
I used Dropbox's official command-line interface here: https://github.com/dropbox/dbxcli.
As the date of posting, it is working fine and provides lots of helpful commands for downloading and uploading.

Another solution I just tried is a bash utility called Dropbox-Uploader.
After configuration through the same steps as above (app creation and token generation), you can just do: ./dropbox_uploader.sh upload mylocal_file my_remote_file, which I find pretty convenient.

Related

How do I download a raw file from my IBM Cloud Git Repos and Issue Tracking repository?

I'm trying to download a raw file from one of my IBM Cloud Git Repos and Issue Tracking repositories. I had a script that was able to fetch raw file contents using the following curl command:
curl -H "Private-Token: $PERSONAL_ACCESS_TOKEN" https://git.ng.bluemix.net/:owner/:repo/raw/:branch/:filename
but it recently started failing with a 302 response that is redirecting to a UI login page.
Is there a supported way to download raw file contents from an IBM Cloud Git Repos and Issue Tracking repository?
The curl request above is attempting to use a personal access token to authenticate to a UI endpoint. There was a security fix in GitLab 11.3.11 that limited the scope of personal access tokens to API calls only. That would explain why personal access tokens are no longer working on that request.
The supported method of downloading raw file contents would be to call the repository files API.
For example, to fetch myFolder/myFile.txt from the master branch of myRepo, owned by myUser, you can make a curl call like this:
curl -H "Private-Token: $PERSONAL_ACCESS_TOKEN" https://git.ng.bluemix.net/api/v4/projects/myUser%2FmyRepo/repository/files/myFolder%2FmyFile.txt/raw?ref=master

How can I GET a json of all the projects I have access to using Gitlab API?

I want to get a json file with all the projects that appear on my Dashboard and that I have developer access to. I though it would be a very simple job using the Gitlab API, more specifically the projects API, but so far, I can't. Is it possible?
Note : I generated a token with api scope.
Here's what I tried and the results :
curl --header "PRIVATE-TOKEN: XXXXX" https://gitlab.com/api/v3/projects
It gives me all the projects I don't own but I have master access to. It doesn't include the ones I have developer/other access to. The result is the closest to what I'm looking for so far.
curl --header "PRIVATE-TOKEN: XXXXX" https://gitlab.com/api/v4/projects
It gives me a list of projects I seem to have access to, even though I have no idea what they are.
curl --header "PRIVATE-TOKEN: XXXXX" https://gitlab.com/api/v4/users/myUser/projects
It gives me all the projects I own. I thought that one would work since the documentation says Get a list of visible projects for the given user. I also tried with the membership attribute set to true or false, but there is no difference.
Any advice/help would be appreciated!
I know this is old question, but maybe other will stumble over this as I just did.
My solution was adding the per_page option
curl -s -X GET -H 'Private-Token: ' 'https://gitlab.com/api/v4/projects?per_page=100'

Keycloak change registration flow / create user API

Lately, I am playing with keylock server. I have an application which has a bit of complication in the registration flow, and I need to change the basic flow of keycloak. Is this possible? For example, when a user fills the needed data, and
clicks to register, I want to redirect him directly to my site and not to keycloak server ( profile manager ).
Also, I am trying to add a user via API, using 'node.js', which would be the easiest way. However, it seems I can't get it done. Does anyone have or know of some kind of tutorial, that can help me, or point me in the right direction?
EDIT:
What I tried is create bash script and add user via rest
#!/bin/bash
export TKN=$(curl -X POST 'http://localhost:8080/auth/realms/master/protocol/openid-connect/token' \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin" \
-d 'password=admin' \
-d 'grant_type=password' \
-d 'client_id=admin-cli' | jq -r '.access_token')
curl -X POST 'http://localhost:8080/auth/admin/realms/demo/users' \
-H "Accept: application/json" \
-d "username=abc
-H "Authorization: Bearer $TKN" | jq .
It doesn't throw any error. But in keycloak I can't see any new user.
Is this possible? For example, when a user fills the needed data, and clicks to register, I want to redirect him directly to my site and not to keycloak server ( profile manager ).
Yes. You can add a user via REST API.
Also, I am trying to add a user via API, using 'node.js', which would be the easiest way. However, it seems I can't get it done. Does anyone have or know of some kind of tutorial, that can help me, or point me in the right direction?
This is an example how to create a user using Keycloak REST API:
https://github.com/v-ladynev/keycloak-nodejs-example/blob/master/lib/adminClient.js#L35
It doesn't throw any error. But in keycloak I can't see any new user.
Looks like, you provided incorrect parameters, or didn't provide mandatory parameters.
I think what you are asking can be broken down to two questions...
how to change the flow ( This is what i m currently trying to find out),
what keycloak command line commands allow for user registration etc.
These should be the CLI commands e.g. client-registration-cli though there is as you say a REST API as well.
you add the role managerusers to your user that you will create the new user with in keycloak

Dashboard with builds, commits and files from GitLab

How do I do dashboard with information from my GitLab repo? I don't know how I get information about builds, commits and files and create dashboard with this information. Any idea? Thank you very much.
You can use GitLab's API to obtain the information from GitLab. You will need to have an user account which can access a particular project. Get this user's "Private Token" from the /profile/account page and then you can make requests for which you would get a JSON response.
Retrieving latest commits
curl -H "PRIVATE-TOKEN: [TOKEN]" \
"https://[HOST]/api/v3/projects/[PROJECT ID]/repository/commits"
Retrieving latest builds
curl -H "PRIVATE-TOKEN: [TOKEN]" \
"https://[HOST]/api/v3/projects/[PROJECT ID]/repository/builds"
These are examples using curl. Depending on the programming language you are going to use, you will have to make a GET request while setting a HTTP header (that is what -H in my example stands for) named PRIVATE-TOKEN.

How to auto upload and check in the files to sharepoint using curl?

I am trying to upload a file from linux to sharepoint with my sharepoint login credentials.
I use the cURL utility to achieve this. The upload is successful.
The command used is : curl --ntlm --user username:password --upload-file myfile.txt -k https://sharepointserver.com/sites/mysite/myfile.txt
-k option is used to overcome the certificate errors for the non-secure sharepoint site.
However, this uploaded file is showing up in "checked out" view(green arrow) in sharepoint from my login.
As a result, this file is non-existent for users from other logins.
My login has the write access previlege to sharepoint.
Any ideas on how to "check in" this file to sharepoint with cURL so that the file can be viewed from anyone's login ?
I don't have curl available to test right now but you might be able to fashion something out of the following information.
Check in and check out is handled by /_layouts/CheckIn.aspx
The page has the following querystring variables:
List - A GUID that identifies the current list.
FileName - The name of the file with extension.
Source - The full url to the allitems.aspx page in the library.
I was able to get the CheckIn.aspx page to load correctly just using the FileName and Source parameters and omitting the List parameter. This is good because you don't have to figure out a way to look up the List GUID.
The CheckIn.aspx page postbacks to itself with the following form parameters that control checkin:
PostBack - boolean set to true.
CheckInAction - string set to ActionCheckin
KeepCheckout - set to 1 to keep checkout and 0 to keep checked in
CheckinDescription - string of text
Call this in curl like so
curl --data "PostBack=true&CheckinAction=ActionCheckin&KeepCheckout=0&CheckinDescription=SomeTextForCheckIn" http://{Your Server And Site}/_layouts/checkin.aspx?Source={Full Url To Library}/Forms/AllItems.aspx&FileName={Doc And Ext}
As I said I don't have curl to test but I got this to work using the Composer tab in Fiddler 2
I'm trying this with curl now and there is an issue getting it to work. Fiddler was executing the request as a POST. If you try to do this as a GET request you will get a 500 error saying that the AllowUnsafeUpdates property of the SPWeb will not allow this request over GET. Sending the request as a POST should correct this.
Edit I am currently going through the checkin.aspx source in the DotPeek decompiler and seeing some additional options for the ActionCheckin parameter that may be relevant such as ActionCheckinPublish and ActionCheckinFromClientPublish. I will update this with any additional findings. The page is located at Microsoft.SharePoint.ApplicationPages.Checkin for anyone else interested.
The above answer by Junx is correct. However, Filename variable is not only the document filename and the extension, but should also include the library name. I was able to get this to work using the following.
Example: http://domain/_layouts/Checkin.aspx?Filename=Shared Documents/filename.txt
My question about Performing multiple requests using cURL has a pretty comprehensive example using bash and cURL, although it suffers from having to reenter the password for each request.

Resources