Skip to content

Commit

Permalink
feat: add-consumer command
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Jun 5, 2015
1 parent 96c8a23 commit d2ebdc9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
7 changes: 4 additions & 3 deletions bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ local commands = {
config = "kong.cli.config",
restart = "kong.cli.restart",
version = "kong.cli.version",
["add-api"] = "kong.cli.add_api",
["--version"] = "kong.cli.version",
migrations = "kong.cli.migrations"
migrations = "kong.cli.migrations",
["add-api"] = "kong.cli.add_api",
["add-consumer"] = "kong.cli.add_consumer"
}

local help_message = string.format([[
Usage: kong <command>
where <command> is one of:
start, restart, reload, stop, quit,
add-api, version
add-api, add-consumer, version
kong --help print this message
kong <command> --help print the help message of a command
Expand Down
3 changes: 2 additions & 1 deletion kong-0.3.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ build = {
["kong.cli.reload"] = "kong/cli/reload.lua",
["kong.cli.restart"] = "kong/cli/restart.lua",
["kong.cli.version"] = "kong/cli/version.lua",
["kong.cli.add_api"] = "kong/cli/add_api.lua",
["kong.cli.migrations"] = "kong/cli/migrations.lua",
["kong.cli.add_api"] = "kong/cli/add_api.lua",
["kong.cli.add_consumer"] = "kong/cli/add_consumer.lua",

["kong.tools.io"] = "kong/tools/io.lua",
["kong.tools.utils"] = "kong/tools/utils.lua",
Expand Down
30 changes: 30 additions & 0 deletions kong/cli/add_consumer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env lua

local printable_mt = require "kong.tools.printable"
local constants = require "kong.constants"
local cutils = require "kong.cli.utils"
local IO = require "kong.tools.io"

local args = require("lapp")(string.format([[
Usage: kong add-consumer [options]
Options:
-c,--config (default %s) path to configuration file
-n,--username (default none) username
-p,--custom-id (default none) custom id
]], constants.CLI.GLOBAL_KONG_CONF))

local config_path = cutils.get_kong_config_path(args.config)
local _, dao_factory = IO.load_configuration_and_dao(config_path)

local res, err = dao_factory.consumers:insert {
username = args.username ~= "none" and args.username or nil,
custom_id = args["custom-id"] ~= "none" and args["custom-id"] or nil
}

if err then
cutils.logger:error_exit("Cannot insert consumer: "..err)
elseif res then
setmetatable(res, printable_mt)
cutils.logger:success("Consumer added to Kong: "..res)
end
1 change: 0 additions & 1 deletion kong/cli/utils/signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ local function prepare_nginx_working_dir(args_config)
end

-- Inject anonymous reports
local KONG_SYSLOG = "kong-hf.mashape.com"
if kong_config.send_anonymous_reports then
-- If there is no internet connection, disable this feature
if socket.dns.toip(constants.SYSLOG.ADDRESS) then
Expand Down
1 change: 0 additions & 1 deletion kong/cli/utils/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ end
return {
colors = colors,
logger = logger,
properties_to_string = properties_to_string,
get_kong_infos = get_kong_infos,
get_kong_config_path = get_kong_config_path,
get_ssl_cert_and_key = get_ssl_cert_and_key,
Expand Down

0 comments on commit d2ebdc9

Please sign in to comment.