Share Implementation

Discussion in 'LiquidFiles General' started by LRSpartan, Apr 30, 2019.

  1. LRSpartan

    LRSpartan New Member

    Joined:
    Apr 30, 2019
    Messages:
    13
    Likes Received:
    2
    We have about two hundred clients (external users). We have a network share that currently has all their files (quarterly statements for example) in separate external user folders, and they can only see their folder and files. Local users can see all files. How would I implement and automate this structure in LF? I was thinking this would be best done in shares. I have looked at the curl/json API and the Windows CLI. It doesn't seem like Windows CLI works with shares. So that leaves me with curl/json. First off, I know every little about curl/json. I ran a few test and listed a few things but that was it. I couldn't get any write access commands to work.

    My question is I have over 50K files that need to be added to various shares along with user setup. How can I automate this? Obviously user setup is more of a one off activity, but I want to make sure I keep the directory and file structure in sync. Maybe I am missing how to do batch processing in curl/json.

    Maybe shares, or LF in general, isn't the solution, but it just seems like it is. I really like LF, but struggling with how to get this done.

    John
     
  2. David

    David Administrator
    Staff Member

    Joined:
    Dec 1, 2015
    Messages:
    781
    Likes Received:
    31
    I paste here also the answer from the ticket you opened, so if somebody else was interested could see the answer:
    Currently (5/2019) the CLI does not cover Shares. For automatic upload you can use the Share upload API.
    Before you start with scripting please ensure the LF server is running on the latest version 3.3.8.
    The user account (represented by API_key) which will be used for uploading has read&write access to all required Shares. You can verify that in "Admin > Configuration > Shares > Manage Access".

    To upload files from your storage you can use the html upload. Here is an example in Linux shell and Curl which shows how to create a directory and a sub-directory in a Share and upload files in to.

    Code:
    #!/bin/sh
    
    api_key="SomeApiKey"
    server="https://lf.domain.com"
    
    #upload a doc file to  the root directory of the Share named test 
    curl -k -X POST --user "$api_key:x" -F file=@/tmp/some.doc $server/shares/test/folders/root/files
    
    #create dir multimedia in the root of the Share
    curl -k -X POST -H "Content-Type:  application/json" --user "$api_key:x" -d  '{"folder":{"name":"multimedia"}}' $server/shares/test/folders/root
    
    #create sub-dir /multimedia/video
    curl  -k -X POST -H "Content-Type: application/json" --user "$api_key:x" -d  '{"folder":{"name":"video"}}' $server/shares/test/folders/multimedia
    
    #html upload video file in to /multimededia/video sub-folder
    curl -k -X POST --user "$api_key:x" -F file=@/tmp/movie.avi $server/shares/test/folders/multimedia-video/files
    
    Note: For that simple uploads files in to directories the Curl can be used also in Windows batch scripts.
     
  3. LRSpartan

    LRSpartan New Member

    Joined:
    Apr 30, 2019
    Messages:
    13
    Likes Received:
    2
    David,

    I will need to create about 500 shares. I was thinking I would do this in a Json array. Do you have an example of creating two shares using an array or what would be the preferred method of doing this? Should I do each share creation as an individual curl to LF? What would be the best method for uploading files too?


    Here is my CURL for both.
    curl -k -v -X POST -H "Content-Type: application/json" --user SomethingSpecialGoesHere:x -d @createshares_array.json https://love.lf.com/admin/shares > curllog.txt

    I can get this non-array to work just fine...remember I am a M$FT user but doing an input file to curl.

    {"share":
    { "name": "NoArraysoIamSad",
    "revisions": 5,
    "quota": 2000
    }
    }

    My json array...assuming I have it right...remember I am new to Json. I get the following back {"error":{"path_not_found":"/500"}}.

    {"share":
    [
    { "name": "PleaseWork1",
    "revisions": 5,
    "quota": 2000
    },
    { "name": "PleaseWork2",
    "revisions": 5,
    "quota": 2000
    },
    { "name": "PleaseWork3",
    "revisions": 5,
    "quota": 2000
    }
    ]
    }


    Here is a GET and it is in an array. I was trying to use this to build my POST array.

    {
    "shares": [
    {
    "id": "SomeName1",
    "name": "SomeName1",
    "access": "write",
    "view_log": false,
    "created_at": "2019-05-15T14:21:59.810-05:00",
    "updated_at": "2019-05-15T14:47:14.961-05:00"
    },
    {
    "id": "SomeName2",
    "name": "SomeName2",
    "access": "write",
    "view_log": false,
    "created_at": "2019-05-15T14:22:40.976-05:00",
    "updated_at": "2019-05-15T14:47:25.437-05:00"
    },
    {
    "id": "SomeName3",
    "name": "SomeName3",
    "access": "read",
    "view_log": false,
    "created_at": "2019-05-14T16:01:39.165-05:00",
    "updated_at": "2019-05-21T09:29:33.687-05:00"
    }
    ]
    }




    Thank you for your help,
    John
     
    #3 LRSpartan, May 22, 2019
    Last edited: May 22, 2019
  4. LRSpartan

    LRSpartan New Member

    Joined:
    Apr 30, 2019
    Messages:
    13
    Likes Received:
    2
    Another question. Is there a way that I can assign the share id instead of the system doing this? When I create a share with a friendly name like "Firefighters Benevolent Fund" the id is "Firefighters-Benevolent-Fund". I would like to set the id myself via api.

    What is the rule set you are using to strip out non-alphanumeric characters in the id field?
     
    #4 LRSpartan, May 23, 2019
    Last edited: May 23, 2019
  5. David

    David Administrator
    Staff Member

    Joined:
    Dec 1, 2015
    Messages:
    781
    Likes Received:
    31
    I think you will need to feed the shares in a script in loop one by one.

    Code:
    #!/bin/sh
    
    api_key="AdminApiKey"
    server="https://lf.domain.com"
    share_list="sharelist.txt"
    
    while read share;
        do
           sharename=$(echo $share | awk -F"," '{ print $1 }' )
           revision=$(echo $share | awk -F"," '{ print $2 }' )
           quota=$(echo $share | awk -F"," '{ print $3 }' )
     
           echo "Share name: $sharename"
           echo "Revision: $revision"
           echo "Quota: $quota"
    
           #create shares from the list
           cat<<EOF | curl -k -X POST --user "$api_key:x" -H 'Content-Type: application/json' -d @- $server/admin/shares
                 { "share":
                        { 
                         "name": "$sharename",
                         "revisions": $revision,
                         "quota": $quota
                        }
                 }
    EOF
    
    done < $share_list
    
    The sharelist.txt covers the information about the name of the shares, revisions and qouta

    Code:
    Share Name1,2,3000
    Share Name2,3,3000
    Share Name3,4,10000
    

    The IDs of shares handles the LF server itself. These can't be set via the API. When the ID generation is up to LF appliance it's a safeguard these generated IDs will be unique. IDs are derived from the name of Shares.
     
    LRSpartan likes this.
  6. LRSpartan

    LRSpartan New Member

    Joined:
    Apr 30, 2019
    Messages:
    13
    Likes Received:
    2
    Thank you for the info and help! I will give this a try. For the initial share name/id, I am going to set it up based on our unique id, then rename it to a friendly name. I tried setting up based on friendly name and all the non-alphanumeric charters weren't playing nice.

     

Share This Page