Explorar o código

fix(emqx_authn): fix create api

EMQ-YangM %!s(int64=4) %!d(string=hai) anos
pai
achega
580901b678

+ 2 - 0
apps/emqx_authn/include/emqx_authn.hrl

@@ -35,3 +35,5 @@
 -define(CONF_NS_BINARY, ?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME_BINARY).
 
 -endif.
+
+-define(RESOURCE_GROUP, <<"emqx_authn">>).

+ 2 - 3
apps/emqx_authn/src/emqx_authn_utils.erl

@@ -17,6 +17,7 @@
 -module(emqx_authn_utils).
 
 -include_lib("emqx/include/emqx_placeholder.hrl").
+-include_lib("emqx_authn.hrl").
 
 -export([ check_password_from_selected_map/3
         , parse_deep/1
@@ -32,8 +33,6 @@
         , make_resource_id/1
         ]).
 
--define(RESOURCE_GROUP, <<"emqx_authn">>).
-
 -define(AUTHN_PLACEHOLDERS, [?PH_USERNAME,
                              ?PH_CLIENTID,
                              ?PH_PASSWORD,
@@ -120,7 +119,7 @@ cleanup_resources() ->
 
 make_resource_id(Name) ->
     NameBin = bin(Name),
-    emqx_resource:generate_id(?RESOURCE_GROUP, NameBin).
+    emqx_resource:generate_id(NameBin).
 
 %%------------------------------------------------------------------------------
 %% Internal functions

+ 1 - 0
apps/emqx_authn/src/simple_authn/emqx_authn_http.erl

@@ -134,6 +134,7 @@ create(#{method := Method,
               request_timeout           => RequestTimeout,
               resource_id => ResourceId},
     case emqx_resource:create_local(ResourceId,
+                                    ?RESOURCE_GROUP,
                                     emqx_connector_http,
                                     Config#{base_url => maps:remove(query, URIMap),
                                             pool_type => random}) of

+ 1 - 1
apps/emqx_authn/src/simple_authn/emqx_authn_mongodb.erl

@@ -112,7 +112,7 @@ create(#{selector := Selector} = Config) ->
     NState = State#{
                selector_template => SelectorTemplate,
                resource_id => ResourceId},
-    case emqx_resource:create_local(ResourceId, emqx_connector_mongo, Config) of
+    case emqx_resource:create_local(ResourceId, ?RESOURCE_GROUP, emqx_connector_mongo, Config) of
         {ok, already_created} ->
             {ok, NState};
         {ok, _} ->

+ 1 - 1
apps/emqx_authn/src/simple_authn/emqx_authn_mysql.erl

@@ -82,7 +82,7 @@ create(#{password_hash_algorithm := Algorithm,
               placeholders => PlaceHolders,
               query_timeout => QueryTimeout,
               resource_id => ResourceId},
-    case emqx_resource:create_local(ResourceId, emqx_connector_mysql, Config) of
+    case emqx_resource:create_local(ResourceId, ?RESOURCE_GROUP, emqx_connector_mysql, Config) of
         {ok, already_created} ->
             {ok, State};
         {ok, _} ->

+ 1 - 1
apps/emqx_authn/src/simple_authn/emqx_authn_pgsql.erl

@@ -79,7 +79,7 @@ create(#{query := Query0,
     State = #{placeholders => PlaceHolders,
               password_hash_algorithm => Algorithm,
               resource_id => ResourceId},
-    case emqx_resource:create_local(ResourceId, emqx_connector_pgsql, Config#{named_queries => #{ResourceId => Query}}) of
+    case emqx_resource:create_local(ResourceId, ?RESOURCE_GROUP, emqx_connector_pgsql, Config#{named_queries => #{ResourceId => Query}}) of
         {ok, already_created} ->
             {ok, State};
         {ok, _} ->

+ 1 - 1
apps/emqx_authn/src/simple_authn/emqx_authn_redis.erl

@@ -91,7 +91,7 @@ create(#{cmd := Cmd,
         NState = State#{
                    cmd => NCmd,
                    resource_id => ResourceId},
-        case emqx_resource:create_local(ResourceId, emqx_connector_redis, Config) of
+        case emqx_resource:create_local(ResourceId, ?RESOURCE_GROUP, emqx_connector_redis, Config) of
             {ok, already_created} ->
                 {ok, NState};
             {ok, _} ->