Skip to content

Commit

Permalink
Merge pull request #1056 from MetPX/issue1008_2
Browse files Browse the repository at this point in the history
Fix #1008 and update documentation
  • Loading branch information
petersilva authored May 21, 2024
2 parents 4dea882 + 3b3f3bb commit 4a334c9
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 14 deletions.
9 changes: 8 additions & 1 deletion docs/source/Explanation/CommandLineGuide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,19 @@ Call the corresponding function for each configuration::
2020-09-06 23:22:18,115 [INFO] sarra.moth.amqp __getSetup queue declared q_tfeed.sr_cpump.xvan_f15.50074940.98161482 (as: amqp://tfeed@localhost/)

Declares the queues and exchanges related to each configuration.
One can also invoke it with --users, so that it will declare users as well as exchanges and queues::
One can also invoke it with *\-\-users*, so that it will declare users as well as exchanges and queues::

$ sr3 --users declare
...
2020-09-06 23:28:56,211 [INFO] sarra.rabbitmq_admin add_user permission user 'ender' role source configure='^q_ender.*|^xs_ender.*' write='^q_ender.*|^xs_ender.*' read='^q_ender.*|^x[lrs]_ender.*|^x.*public$'
...

Providing a flow/flows will declare only the users that are specified in the flow(s)::

$ sr3 --users declare subscribe/dd_amis
...
declare: 2024-05-17 20:02:18,548 434920 [INFO] sarracenia.rabbitmq_admin add_user permission user 'tfeed@localhost' role feeder configure=.* write=.* read=.*
...

dump
~~~~
Expand Down
10 changes: 8 additions & 2 deletions docs/source/How2Guides/Admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ in the file .config/sarra/admin.conf ::
declare subscriber anonymous
declare source peter

Now to configure the pump execute the following::
Now to configure the pump, execute the following::

*sr3 --users declare*
sr3 --users declare

Sample run::

Expand Down Expand Up @@ -581,6 +581,12 @@ To remove users, just remove *declare source Alice* from the admin.conf file, an
again. To delete users, one can use the existing rabbitmq management interfaces directly.
The creation is automated because the read/write/configure patterns are cumbersome to do manually.

- Note: By default, all users are declared. However, flows can be specified on the command line to constrain
the declared users to only those in the given flow. For example:

- *sr3 \-\-users declare* will declare all users
- *sr3 \-\-users declare subscribe/dd_amis* will only declare users specified in *subscribe/dd_amis*


First Subscribe
~~~~~~~~~~~~~~~
Expand Down
11 changes: 9 additions & 2 deletions docs/source/Reference/sr3_options.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ declare
-------

env NAME=Value
On can also reference environment variables in configuration files,
One can also reference environment variables in configuration files,
using the *${ENV}* syntax. If Sarracenia routines needs to make use
of an environment variable, then they can be set in configuration files::

Expand Down Expand Up @@ -610,10 +610,17 @@ feeder
preference to administrator accounts to run flows.

User credentials are placed in the `credentials.conf <sr3_credentials.7.html>`_
file, and *sr3 --users declare* will update
file, and *sr3 \-\-users declare* will update
the broker to accept what is specified in that file, as long as the admin password is
already correct.

- By default, all users are declared. However, flows can be specified on the command line to constrain
the declared users to only those in the given flow. For example:

- *sr3 \-\-users declare* will declare all users
- *sr3 \-\-users declare subscribe/dd_amis* will only declare users specified in *subscribe/dd_amis*


debug
-----

Expand Down
10 changes: 8 additions & 2 deletions docs/source/fr/CommentFaire/Admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ dans le fichier .config/sarra/admin.conf ::

Maintenant, pour configurer la pompe, exécutez ce qui suit::

*sr3 --users declare*
sr3 --users declare

resultat::
Resultat::

fractal% sr3 --users declare
2020-09-06 23:28:56,211 [INFO] sarra.rabbitmq_admin add_user permission user 'ender' role source configure='^q_ender.*|^xs_ender.*' write='^q_ender.*|^xs_ender.*' read='^q_ender.*|^x[lrs]_ender.*|^x.*public$'
Expand Down Expand Up @@ -638,6 +638,12 @@ du fichier admin.conf, et d'exécuter::
encore. Pour supprimer des utilisateurs, on peut utiliser directement les interfaces de gestion rabbitmq existantes.
La création est automatisée car les modèles de lecture/écriture/configuration sont lourds à faire manuellement.

- Remarque: Par défaut, tous les utilisateurs sont déclarés. Toutefois, des flux peuvent être spécifiés sur
la ligne de commande pour limiter les utilisateurs déclarés à ceux du flux donné. Par exemple,

- *sr3 \-\-users declare* déclarera tous les utilisateurs
- *sr3 \-\-users declare subscribe/dd_amis* ne déclarera que les utilisateurs spécifiés dans *subscribe/dd_amis*


Premier abonnement
~~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 7 additions & 1 deletion docs/source/fr/Explication/GuideLigneDeCommande.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,18 @@ Appeler la fonction correspondante pour chacune des configurations::


Déclare les files d’attente et les échanges liés à chaque configuration.
On peut également l’appeler avec --users, afin qu’il déclare les utilisateurs ainsi que les échanges et les files d’attente::
On peut également l’appeler avec *\-\-users*, afin qu’il déclare les utilisateurs ainsi que les échanges et les files d’attente::

$ sr3 --users declare
2020-09-06 23:28:56,211 [INFO] sarra.rabbitmq_admin add_user permission user 'ender' role source configure='^q_ender.*|^xs_ender.*' write='^q_ender.*|^xs_ender.*' read='^q_ender.*|^x[lrs]_ender.*|^x.*public$'
...

La fourniture d'un ou de plusieurs flux ne déclarera que les utilisateurs spécifiés dans le(s) flux::

$ sr3 --users declare subscribe/dd_amis
...
declare: 2024-05-17 20:02:18,548 434920 [INFO] sarracenia.rabbitmq_admin add_user permission user 'tfeed@localhost' role feeder configure=.* write=.* read=.*
...

dump
~~~~
Expand Down
9 changes: 8 additions & 1 deletion docs/source/fr/Reference/sr3_options.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,16 @@ feeder
préférence au lieu de comptes d’administrateur pour exécuter des flux.

Les informations d’identification de l’utilisateur sont placées dans le `credentials.conf <sr3_credentials.7.html>`_
et *sr3 --users declare* mettra à jour le courtier pour accepter ce qui est spécifié dans ce fichier, tant que le
et *sr3 \-\-users declare* mettra à jour le courtier pour accepter ce qui est spécifié dans ce fichier, tant que le
mot de passe de l'administrateur est déjà correct.

- Par défaut, tous les utilisateurs sont déclarés. Toutefois, des flux peuvent être spécifiés sur
la ligne de commande pour limiter les utilisateurs déclarés à ceux du flux donné. Par exemple,

- *sr3 \-\-users declare* déclarera tous les utilisateurs
- *sr3 \-\-users declare subscribe/dd_amis* ne déclarera que les utilisateurs spécifiés dans *subscribe/dd_amis*


debug
-----

Expand Down
2 changes: 1 addition & 1 deletion sarracenia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ def __call__(self, parser, namespace, values, option_string):
def parse_args(self, isPost=False):
"""
user information:
accept a configguration, apply argParse library to augment the given configuration
accept a configuration, apply argParse library to augment the given configuration
with command line settings.
the post component has a different calling convention than others, so use that flag
Expand Down
42 changes: 38 additions & 4 deletions sarracenia/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,8 @@ def _match_patterns(self, patterns=None):
for cfg in self.configs[c]:
fcc = c + os.sep + cfg
candidates.append(fcc)


self.all_configs = candidates
logger.debug( f"candidates: {candidates}" )
new_patterns=[]
for p in patterns:
Expand Down Expand Up @@ -1319,8 +1320,34 @@ def add(self):
f.write('')

def declare(self):
'''
creates users, exchanges, and queues in that order - each one is needed to create
the subsequent one
'''

filtered_users = []

if len(self.filtered_configurations) < len(self.all_configs):

for config in self.filtered_configurations:

(c, cfg) = config.split(os.sep)

if not 'options' in self.configs[c][cfg]:
continue

if self.users:
o = self.configs[c][cfg]['options']

if hasattr(o, "broker") and o.broker:
filtered_users.append(f"{o.broker.url.username}@{o.broker.url.hostname}")
if hasattr(o, "post_broker") and o.post_broker:
filtered_users.append(f"{o.post_broker.url.username}@{o.post_broker.url.hostname}")
if hasattr(o, "report_broker") and o.report_broker:
filtered_users.append(f"{o.report_broker.url.username}@{o.report_broker.url.hostname}")

# add users (?)
if self.users: # check if users exist in the configuration (?)
for h in self.brokers:
if self.please_stop:
break
Expand All @@ -1347,14 +1374,21 @@ def declare(self):
#print( 'u_url : user:%s, pw:%s, role: %s netloc: %s, host:%s' % \
# (u_url.username, u_url.password, self.default_cfg.declared_users[u_url.username],
# u_url.netloc, u_url.hostname ))

user = f"{u_url.username}@{h}"

if filtered_users and user not in filtered_users:
logger.debug(f"not adding {user}")
continue

sarracenia.rabbitmq_admin.add_user( \
self.brokers[h]['admin'].url, \
self.default_cfg.declared_users[u_url.username],
u_url.username, u_url.password, self.options.dry_run )

# declare admin exchanges.
if hasattr(self,'default_cfg') and self.default_cfg.admin:
logger.info( f"Declaring exchnges for admin.conf using {self.default_cfg.admin} ")
logger.info( f"Declaring exchanges for admin.conf using {self.default_cfg.admin} ")
if hasattr(self.default_cfg, 'declared_exchanges'):
xdc = sarracenia.moth.Moth.pubFactory(
{
Expand All @@ -1365,7 +1399,7 @@ def declare(self):
})
xdc.putSetup()
xdc.close()

# declare exchanges first.
for f in self.filtered_configurations:
if self.please_stop:
Expand Down

0 comments on commit 4a334c9

Please sign in to comment.