diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-03-19 19:13:05 -0400 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-01 17:32:53 -0400 |
| commit | 18842a049784cdbba66010fb30f06525e9016600 (patch) | |
| tree | a6826096ad0f0f36e847a68434087407be35e1f3 | |
| parent | 655eacf345a108247ba6ea506721395571108912 (diff) | |
| download | luarocks-18842a049784cdbba66010fb30f06525e9016600.tar.gz luarocks-18842a049784cdbba66010fb30f06525e9016600.tar.bz2 luarocks-18842a049784cdbba66010fb30f06525e9016600.zip | |
upload: add --sign option
| -rw-r--r-- | spec/upload_spec.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/cmd/upload.lua | 31 |
2 files changed, 34 insertions, 3 deletions
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index 76a27ee3..947147d7 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua | |||
| @@ -40,7 +40,11 @@ describe("LuaRocks upload tests #integration", function() | |||
| 40 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) | 40 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) |
| 41 | end) | 41 | end) |
| 42 | 42 | ||
| 43 | it("LuaRocks upload rockspec with api-key and skip-pack", function() | 43 | it("#gpg rockspec with --sign", function() |
| 44 | print(run.luarocks("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123 --sign", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) | ||
| 45 | end) | ||
| 46 | |||
| 47 | it("rockspec with api-key and skip-pack", function() | ||
| 44 | assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) | 48 | assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) |
| 45 | end) | 49 | end) |
| 46 | end) | 50 | end) |
diff --git a/src/luarocks/cmd/upload.lua b/src/luarocks/cmd/upload.lua index ffcb1a0a..b052500e 100644 --- a/src/luarocks/cmd/upload.lua +++ b/src/luarocks/cmd/upload.lua | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | local upload = {} | 2 | local upload = {} |
| 3 | 3 | ||
| 4 | local signing = require("luarocks.signing") | ||
| 4 | local util = require("luarocks.util") | 5 | local util = require("luarocks.util") |
| 5 | local fetch = require("luarocks.fetch") | 6 | local fetch = require("luarocks.fetch") |
| 6 | local pack = require("luarocks.pack") | 7 | local pack = require("luarocks.pack") |
| @@ -12,14 +13,20 @@ upload.help_arguments = "[--skip-pack] [--api-key=<key>] [--force] <rockspec>" | |||
| 12 | upload.help = [[ | 13 | upload.help = [[ |
| 13 | <rockspec> Pack a source rock file (.src.rock extension), | 14 | <rockspec> Pack a source rock file (.src.rock extension), |
| 14 | upload rockspec and source rock to server. | 15 | upload rockspec and source rock to server. |
| 16 | |||
| 15 | --skip-pack Do not pack and send source rock. | 17 | --skip-pack Do not pack and send source rock. |
| 18 | |||
| 16 | --api-key=<key> Give it an API key. It will be stored for subsequent uses. | 19 | --api-key=<key> Give it an API key. It will be stored for subsequent uses. |
| 20 | |||
| 17 | --temp-key=<key> Use the given a temporary API key in this invocation only. | 21 | --temp-key=<key> Use the given a temporary API key in this invocation only. |
| 18 | It will not be stored. | 22 | It will not be stored. |
| 23 | |||
| 19 | --force Replace existing rockspec if the same revision of | 24 | --force Replace existing rockspec if the same revision of |
| 20 | a module already exists. This should be used only | 25 | a module already exists. This should be used only |
| 21 | in case of upload mistakes: when updating a rockspec, | 26 | in case of upload mistakes: when updating a rockspec, |
| 22 | increment the revision number instead. | 27 | increment the revision number instead. |
| 28 | |||
| 29 | --sign Upload a signature file alongside each file as well. | ||
| 23 | ]] | 30 | ]] |
| 24 | 31 | ||
| 25 | local function is_dev_version(version) | 32 | local function is_dev_version(version) |
| @@ -58,6 +65,17 @@ function upload.command(flags, fname) | |||
| 58 | return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload") | 65 | return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload") |
| 59 | end | 66 | end |
| 60 | 67 | ||
| 68 | local sigfname | ||
| 69 | local rock_sigfname | ||
| 70 | |||
| 71 | if flags["sign"] then | ||
| 72 | sigfname, err = signing.sign_file(fname) | ||
| 73 | if err then | ||
| 74 | return nil, "Failed signing rockspec: " .. err | ||
| 75 | end | ||
| 76 | util.printout("Signed rockspec: "..sigfname) | ||
| 77 | end | ||
| 78 | |||
| 61 | local rock_fname | 79 | local rock_fname |
| 62 | if not flags["skip-pack"] and not is_dev_version(rockspec.version) then | 80 | if not flags["skip-pack"] and not is_dev_version(rockspec.version) then |
| 63 | util.printout("Packing " .. tostring(rockspec.package)) | 81 | util.printout("Packing " .. tostring(rockspec.package)) |
| @@ -65,12 +83,20 @@ function upload.command(flags, fname) | |||
| 65 | if not rock_fname then | 83 | if not rock_fname then |
| 66 | return nil, err | 84 | return nil, err |
| 67 | end | 85 | end |
| 86 | if flags["sign"] then | ||
| 87 | rock_sigfname, err = signing.sign_file(rock_fname) | ||
| 88 | if err then | ||
| 89 | return nil, "Failed signing rock: " .. err | ||
| 90 | end | ||
| 91 | util.printout("Signed packed rock: "..rock_sigfname) | ||
| 92 | end | ||
| 68 | end | 93 | end |
| 69 | 94 | ||
| 70 | local multipart = require("luarocks.upload.multipart") | 95 | local multipart = require("luarocks.upload.multipart") |
| 71 | 96 | ||
| 72 | res, err = api:method("upload", nil, { | 97 | res, err = api:method("upload", nil, { |
| 73 | rockspec_file = multipart.new_file(fname) | 98 | rockspec_file = multipart.new_file(fname), |
| 99 | rockspec_sig = sigfname and multipart.new_file(sigfname), | ||
| 74 | }) | 100 | }) |
| 75 | if not res then return nil, err end | 101 | if not res then return nil, err end |
| 76 | 102 | ||
| @@ -86,7 +112,8 @@ function upload.command(flags, fname) | |||
| 86 | end | 112 | end |
| 87 | util.printout(("Sending " .. tostring(rock_fname) .. " ...")) | 113 | util.printout(("Sending " .. tostring(rock_fname) .. " ...")) |
| 88 | res, err = api:method("upload_rock/" .. ("%d"):format(res.version.id), nil, { | 114 | res, err = api:method("upload_rock/" .. ("%d"):format(res.version.id), nil, { |
| 89 | rock_file = multipart.new_file(rock_fname) | 115 | rock_file = multipart.new_file(rock_fname), |
| 116 | rock_sig = rock_sigfname and multipart.new_file(rock_sigfname), | ||
| 90 | }) | 117 | }) |
| 91 | if not res then return nil, err end | 118 | if not res then return nil, err end |
| 92 | end | 119 | end |
