{"id":22832577,"url":"https://github.com/waldner/hubic-lib","last_synced_at":"2025-08-10T18:32:01.901Z","repository":{"id":92012184,"uuid":"118360721","full_name":"waldner/hubic-lib","owner":"waldner","description":"Shell library to interact with HubiC storage","archived":true,"fork":false,"pushed_at":"2018-12-29T18:34:51.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T02:18:53.411Z","etag":null,"topics":["bash","hubic","hubic-api","hubic-storage","shell"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waldner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-21T18:14:22.000Z","updated_at":"2023-12-19T22:48:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"ad5fbb1c-43bb-4bf9-8206-a1a56e03e8de","html_url":"https://github.com/waldner/hubic-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/waldner/hubic-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Fhubic-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Fhubic-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Fhubic-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Fhubic-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waldner","download_url":"https://codeload.github.com/waldner/hubic-lib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Fhubic-lib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269770605,"owners_count":24473307,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","hubic","hubic-api","hubic-storage","shell"],"created_at":"2024-12-12T21:08:03.083Z","updated_at":"2025-08-10T18:32:01.889Z","avatar_url":"https://github.com/waldner.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hubic_lib\n\nThis is a knocked-together, \"Works for me (TM)\" shell library to interact with HubiC storage: upload/download files, create containers, etc. NOT ALL OF THE API IS IMPLEMENTED. See https://developer.openstack.org/api-ref/object-store/ for the full API.\n\n## Dependencies\n\nThe only dependencies needed are [bash](https://www.gnu.org/software/bash/), [curl](https://curl.haxx.se/) and [perl](https://www.perl.org/). Well, and **rm**, but if you don't have that you have bigger problems than not being able to use this library.\n\n## Installation\n\nNo special installation needed. Just put **`hubic-lib.sh`** wherever you want. You have to know the location because you'll have to source it in your script.\n\n## Getting started\n\n- Create an application in your HubiC control panel. Name it whatever you want, and use a made-up return URL (eg, http://localhost/). It's not used here, but it has to be present.\n\n- Source `hubic-lib.sh` in your script\n\n- Implement a function called `hubic_get_userdef_credentials` that sets some environment variables with suitable values (`hubic_lib[login]` and `hubic_lib[pass]` you should know, and the others can be found in your HubiC control panel app settings). See below.\n\n- Call `hubic_api_init` and check that it returns without errors.\n\n- At this point, you can perform storage operation by invoking functions like `hubic_upload_file`, `hubic_delete_container` and others. See below for more.\n\n- When you're done using the storage, call `hubic_api_cleanup`.\n\n- Profit. \n\n## Logging\n\nSourcing the library gives you access to a very rudimentary log function called `hubic_log`. Its arguments are a log level (one of  DEBUG, INFO, NOTICE, WARNING, ERROR) and the message to log. You can use this function to log your application messages together with those coming from the library. By default, the library detects automatically whether to log to file or to stdout (if stdout is not a terminal, log to file; otherwise log to stdout). This allows eg running from cron without getting output, but still being able to manually run on the command line and see the messages. The log destination can however be forced. The minimum logging level can also be configured, or logging can be turned off altogether. See code below for examples.\n\n## Internals\n\nAll the variables used by the library are kept in an associative array called `hubic_lib`. \n\nSince the REST API sometimes fails with transient errors, each operation defines a series of HTTP return codes upon which the function is considered to have completed; any other HTTP code produces a retry of the operation, up to a maximum, by default, of 3 times.\n\nAfter each file API function invocation, the three variables `hubic_lib['last_http_headers']`, `hubic_lib['last_http_body']` and `hubic_lib['last_http_code']` contain what their name says, so they can be inspected in your code for extra control. Additionally, after operations that return lists of objects, `hubic_lib['object_list']` is set with such list (a single variable of newline-separated strings), and can be accessed from your code.\n\nEach file API operation ends up invoking `hubic_do_operation` internally, after setting the appropriate (global) parameters (via `hubic_parse_args`). `hubic_do_operation`, in turn, calls `hubic_do_single_operation`, handling retries in case of transient errors. Finally, `hubic_do_single_operation` calls `hubic_do_curl` (which does the actual curl invocation) and returns success or failure (based on the HTTP return code) all the way up.\n\n## Sample code\n\n(See also the included `sample-backup.sh` script.)\n\n```\n#!/bin/bash\n\nhubic_get_userdef_credentials(){\n  hubic_lib['client_id']=XXXXX\n  hubic_lib['client_key']=YYYYY\n  hubic_lib['login']=foo@foo.com\n  hubic_lib['pass']=ZZZZZZ\n  hubic_lib['return_url']=\"http://localhost/\"   # or whatever you used in the app\n  \n  # or read them from a file, from vault, whatever, as long as you set the above variables\n}\n\n. /path/to/hubic-lib.sh\n\n# OPTIONAL: configure logging\n\n# hubic_set_log_level DEBUG        # valid values: DEBUG, INFO, NOTICE, WARNING], ERROR\n# hubic_set_logging_enabled 1      # valid values: 0 = logging disabled, anything else = enabled\n# hubic_set_log_destination file   # valid values: file = log to file, stdout = log to stdout (doh!)\n                                   # default file: /tmp/hubic_YYYY-MM-DD_hh:mm:ss.log\n\n# OPTIONAL: configure retry behaviour\n# hubic_set_retries 4              # retry up to 4 times when operation fails\n\n# OPTIONAL: configure OAuth flow (\"serverside\" or \"implicit\"), default \"serverside\"\n# hubic_set_oauth_flow implicit\n\n# Init API (auth app, get tokens, etc)\nif ! hubic_api_init; then\n  echo \"Hubic library API initialization failed\" \u003e\u00262\n  exit 1\nfi\n\n# now do actual operations\n# following switches are supported:\n#\n# -c container: container name (defaults to \"default\" if omitted)\n# -p path: remote path (ok, they're pseudo, but let's pretend they are real), defaults to \"\"\n# -l localfile: local file name\n# -r remotefile: remote file name\n\n# create a container\nhubic_create_container -c newcontainer\n\n# create (pseudo)directory \"foobar\" in container \"newcontainer\"\nhubic_create_directory -c newcontainer -p foobar\n\n# upload local file /tmp/backup.tgz to remote file \"newcontainer/foobar/backup-last.tgz\"\nhubic_upload_file -c newcontainer -p foobar -r backup-last.tgz -l /tmp/backup.tgz \n\nhubic_log INFO \"Now I'm going to download a file\"\n\n# get remote file \"default/archive.tar.gz\", saves to local file /tmp/archive.tar.gz\nhubic_download_file -p \"\" -r \"archive.tar.gz\" -l /tmp/archive.tar.gz\n\n# delete an object\nhubic_delete_object -c oldcontainer -p somepath -r file.tar\n\n# delete a container (fails if not empty)\nhubic_delete_container -c oldcontainer\n\n# list containers\nhubic_list_containers\n\ndeclare -a containers\n\noIFS=$IFS\nIFS=$'\\n'\ncontainers=( ${hubic_lib['object_list']} )\nIFS=$oIFS\n\n# hubic_object_list is set by the previous function\nfor container in \"${containers[@]}\"; do\n  : # do something with \"$container\"\ndone\n\n# list files (really objects), optionally specify a path\nhubic_list_files -c newcontainer -p foobar\n\ndeclare -a objects\n\noIFS=$IFS\nIFS=$'\\n'\nobjects=( ${hubic_lib['object_list']} )\nIFS=$oIFS\n\nfor object in \"${objects[@]}\"; do\n  : # do something with \"$object\"\ndone\n\n# when done, cleanup\nhubic_api_cleanup\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaldner%2Fhubic-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaldner%2Fhubic-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaldner%2Fhubic-lib/lists"}