diff options
author | Adam Kocoloski <adam@cloudant.com> | 2010-08-10 17:34:08 -0400 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2010-08-10 17:37:19 -0400 |
commit | 5e2f90537f5b54adc94c58b58512a05b058fa804 (patch) | |
tree | 6ef74855e9e53a8f273f5016dd40dc880b92e4b7 /src/fabric_db_create.erl | |
parent | 38228cdaeefd6ad2f9ec2452e05794caa850cf84 (diff) |
validate dbnames before submitting jobs
Diffstat (limited to 'src/fabric_db_create.erl')
-rw-r--r-- | src/fabric_db_create.erl | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/fabric_db_create.erl b/src/fabric_db_create.erl index 2fca0eed..d10bcc22 100644 --- a/src/fabric_db_create.erl +++ b/src/fabric_db_create.erl @@ -5,18 +5,25 @@ -include_lib("mem3/include/mem3.hrl"). -include_lib("couch/include/couch_db.hrl"). +-define(DBNAME_REGEX, "^[a-z][a-z0-9\\_\\$()\\+\\-\\/\\s.]*$"). + %% @doc Create a new database, and all its partition files across the cluster %% Options is proplist with user_ctx, n, q go(DbName, Options) -> - Shards = mem3:choose_shards(DbName, Options), - Doc = make_document(Shards), - Workers = fabric_util:submit_jobs(Shards, create_db, [Options, Doc]), - Acc0 = fabric_dict:init(Workers, nil), - case fabric_util:recv(Workers, #shard.ref, fun handle_message/3, Acc0) of - {ok, _} -> - ok; - Else -> - Else + case re:run(DbName, ?DBNAME_REGEX, [{capture,none}]) of + match -> + Shards = mem3:choose_shards(DbName, Options), + Doc = make_document(Shards), + Workers = fabric_util:submit_jobs(Shards, create_db, [Options, Doc]), + Acc0 = fabric_dict:init(Workers, nil), + case fabric_util:recv(Workers, #shard.ref, fun handle_message/3, Acc0) of + {ok, _} -> + ok; + Else -> + Else + end; + nomatch -> + {error, illegal_database_name} end. handle_message(Msg, Shard, Counters) -> |