Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different TargetURLs than B2 Cloud Storage (Backblaze) #13

Open
1 of 4 tasks
hugojosefson opened this issue Oct 7, 2017 · 1 comment
Open
1 of 4 tasks

Different TargetURLs than B2 Cloud Storage (Backblaze) #13

hugojosefson opened this issue Oct 7, 2017 · 1 comment

Comments

@hugojosefson
Copy link
Owner

hugojosefson commented Oct 7, 2017

Thoughts on possible plugin API

plugins :: [] Plugin

Plugin :: (yargs :: PluginFriendlyYargs) -> {
    yargs :: PluginFriendlyYargs,  -- The same yargs object, but with possibly
                                   -- extra .command()'s tacked onto it, or
                                   -- modified via .updateCommand()

    targetUrl :: {templateUrl :: String, name :: String, argv :: {}} -> urlToUse :: String
                                                      -- argv is from yargs
}

PluginFriendlyYargs :: {
  ...yargs, 
  updateCommand :: (
    command :: String,                 -- The command to update, throws ("use .command()
                                       -- instead") if command does not exist.
    {
      alias :: OverrideCommandConfiguration,
      default :: OverrideCommandConfiguration,
      description :: OverrideCommandConfiguration,
      builder :: OverrideCommandConfiguration,
      * :: OverrideCommandConfiguration  -- Enumerate them all, use those defined.
    }
  ) -> PluginFriendlyYargs
}

OverrideCommandConfiguration :: ValueReplacer | Value

ValueReplacer :: prevValue -> updatedOrSameOrOtherValue
Value :: (Any, but not a Function)     -- Easily override with String or Boolean constant

duplicati-generate-config-plugin-b2

import { URL } from 'url'
import { compose } from 'ramda'
import {
  prepend,
  removeAnyLeadingSlash,
  cleanHostname
} from '../extractable-modules/string-manipulation'

export default yargs => ({
  yargs: yargs
    .updateCommand({
      command: 'generate',
      builder: originalBuilder => argv => originalBuilder(argv).option('name-suffix', {
        default: ' to b2 backblaze',
        description: 'Appended to each backup set name the definitions, to the resulting config file',
        type: 'string'
      }) 
    }),
  targetUrl: ({templateTargetUrl, name}) => {
    const url = new URL(templateTargetUrl)

    url.hostname = compose(
      prepend('duplicati-'),
      removeAnyLeadingSlash,
      cleanHostname
    )(name)

    url.pathname = '/'

    return url.toString()
  }
})

TODO

  • CLI argument [--plugin <module>]*
  • CLI argument [--plugin-inline <js>]*
  • Extract duplicati-generate-config-plugin-b2 ({"keywords": ["duplicati-generate-config-plugin"], "peerDependencies": {"duplicati-generate-config": "1"}).
    • --name-suffix, default " to b2 backblaze"
@hugojosefson
Copy link
Owner Author

wip on branch plugins-13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant