forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kazoo 5582 master - add a migrations API and add a migration to disab…
…le notify and move to teletype (2600hz#3912) * KAZOO-5582: add migrations api, add notify_to_teletype migration * formatting and docs * actual docs * make some api's * dialyze the things * changes per code review * :( * add account name and user name to the migration tracking * formatting again, switch types
- Loading branch information
Showing
6 changed files
with
472 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
### Migrations | ||
|
||
#### About Migrations | ||
|
||
The migrations API allows you to perform various account based migrations on an account, or an account and its sub-accounts. | ||
|
||
#### List | ||
|
||
Lists all available migrations. | ||
|
||
> GET /v2/accounts/{ACCOUNT_ID}/migrations | ||
```shell | ||
curl -v -X GET \ | ||
-H "X-Auth-Token: {AUTH_TOKEN}" \ | ||
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations | ||
``` | ||
|
||
#### Summary | ||
|
||
Provides a summary of a migration, including information on if it was performed and by whom and when. | ||
|
||
> GET /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
```shell | ||
curl -v -X GET \ | ||
-H "X-Auth-Token: {AUTH_TOKEN}" \ | ||
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
``` | ||
|
||
#### Perform Migration | ||
|
||
Allows you to perform a migration, with the following potential parameters: | ||
|
||
Name|Values|Description | ||
----|------|----------- | ||
perform_migration|now|Performs the migration now (now is the only currently supported option) | ||
include_descendants|true / false (default: false)|If true the migration is performed on the account and sub-accounts | ||
include_resellers|true / false (default: false)|If true the migration is performed on reseller sub-accounts | ||
|
||
> POST /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
```shell | ||
curl -v -X POST \ | ||
-H "X-Auth-Token: {AUTH_TOKEN}" \ | ||
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
### Migrations | ||
|
||
#### About Migrations | ||
|
||
#### Schema | ||
|
||
|
||
|
||
#### Fetch | ||
|
||
> GET /v2/accounts/{ACCOUNT_ID}/migrations | ||
```shell | ||
curl -v -X GET \ | ||
-H "X-Auth-Token: {AUTH_TOKEN}" \ | ||
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations | ||
``` | ||
|
||
#### Fetch | ||
|
||
> GET /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
```shell | ||
curl -v -X GET \ | ||
-H "X-Auth-Token: {AUTH_TOKEN}" \ | ||
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
``` | ||
|
||
#### Change | ||
|
||
> POST /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
```shell | ||
curl -v -X POST \ | ||
-H "X-Auth-Token: {AUTH_TOKEN}" \ | ||
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
applications/crossbar/src/modules/cb_migration_disable_notify.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @copyright (C) 2011-2017, 2600Hz INC | ||
%%% @doc | ||
%%% Crawl accounts and disable notify settings so that we use Teletype instead | ||
%%% | ||
%%% @end | ||
%%% @contributors | ||
%%% Mark Magnusson | ||
%%%------------------------------------------------------------------- | ||
-module(cb_migration_disable_notify). | ||
|
||
-export([perform_migration/2]). | ||
|
||
-include("crossbar.hrl"). | ||
|
||
-spec perform_migration(binary(), cb_context:context()) -> cb_context:context(). | ||
perform_migration(Account, Context) -> | ||
lager:info("migrating account ~p from notify to teletype...", [Account]), | ||
|
||
AccountDb = kz_util:format_account_id(Account, 'encoded'), | ||
|
||
{'ok', BaseDoc} = kz_datamgr:open_cache_doc(AccountDb, Account), | ||
NewDoc = lists:foldl(fun(X, A) -> X(A) end, BaseDoc, [ | ||
fun remove_vm_to_email/1 | ||
,fun remove_fax_to_email/1 | ||
]), | ||
|
||
kz_datamgr:ensure_saved(AccountDb, NewDoc), | ||
cb_context:set_resp_status(Context, 'success'). | ||
|
||
-spec remove_vm_to_email(kz_json:object()) -> kz_json:object(). | ||
remove_vm_to_email(Doc) -> | ||
kz_json:delete_key([<<"notifications">>, <<"voicemail_to_email">>], Doc). | ||
|
||
-spec remove_fax_to_email(kz_json:object()) -> kz_json:object(). | ||
remove_fax_to_email(Doc) -> | ||
kz_json:delete_key([<<"notifications">>, <<"fax_to_email">>], Doc). |
Oops, something went wrong.