-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include D-Bus sender in User-Agent http header #2329
Conversation
This PR depend on #2328 |
The http headers could look like this: {
"Content-type": "application/json",
"Accept": "application/json",
"x-subscription-manager-version": "RPM_VERSION",
"Accept-Language": "cs-cz",
"X-Correlation-ID": "70859bc7ffbd4f0b836a7c1b2946414a",
"User-Agent": "RHSM/1.0 (cmd=rhsm_service.py) subscription-manager/RPM_VERSION dbus_sender=cockpit-bridge",
"Content-Length": "0"
} |
f7ac889
to
b57a161
Compare
Singleton and parent for singletons | ||
""" | ||
_instance = None | ||
_initialized = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I realized that I do something wrong here and we will need to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it is used in decorator no_reinitialization
.
0a9bdaa
to
279ceaf
Compare
Looks like there are a few failing flake8 issues: test/test_managercli.py:1605:37: E231 missing whitespace after ',' |
test/rhsmlib_test/test_utils.py
Outdated
spoiled_child = SpoiledChild() | ||
self.assertEqual(id(spoiled_child), spoiled_child_id) | ||
|
||
def test_signleton_and_treading(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_signleton_and_treading -> test_singleton_and_threading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/rhsmlib/dbus/util.py
Outdated
elif len(args) > 0: | ||
sender = args[-1] | ||
|
||
if sender is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to ensure that the sender isn't changed for a given call, shouldn't we acquire the lock for the DbusSender singleton here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
src/rhsmlib/dbus/util.py
Outdated
try: | ||
return func(*args, **kwargs) | ||
finally: | ||
dbus_reset_sender_cmd_line() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if we acquire the lock before the function call, I'd suggest we release it here.
Admittedly this is effectively serializing all our dbus calls which may be worth more discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented this using __enter__()
and __exit__()
methods and with DBusSender as dbus_sender
statement. It is more clear solution.
6da5b37
to
d738c64
Compare
We need to fix the test issue and rebase if this is on track for inclusion. Otherwise, we should close the PR until is it on the path. |
d738c64
to
eaf02e7
Compare
* When some application call D-Bus method, then the application can be identified using sender argument of the method. This argument used to be unused. The sender ID (e.g. ':1:3003') can be used for finding of PID and this PID can be used for finding command line used for starting the application that sent the D-Bus method. This could be e.g.: 'dbus-send', 'cockpit-bridge', etc. (note: all command line options are stripped for security reason to not send username nor password). The command line of D-Bus sender is stored in singleton and then this command line is added to User-Agent http header as 'dbus_sender=cockpit-bridge' * The sender argument is saved to singleton using decorator dbus_handle_sender implemented in rhsmlib.dbus.util. When it will not be desired to store sender for some method then just don't use this decorator. * When methods of DomainSocketRegisterDBusObject are used, then it is little bit complicated, because system bus is not used there, but custom unix socket is used. Thus sender argument is not available. It is necessary to save sender, when DomainSocketRegisterDBusObject is created using com.redha.RHSM.Register.Start method * Fix one issue with initialization of CPPProvider * It will be possible to do statistics of applications using our D-Bus API * Modified some unit tests * Added implementation of singleton * Added unit tests for singleton * Create new connection for GetStatus, otherwise the dbus_sender is not set correctly and value from previous call is used * Fix issue with printing traceback to the file * Do not use wild import in rhsmlib.dbus package, because it caused circular import of DBusSender
eaf02e7
to
81c5dea
Compare
@wottop I updated the PR. |
can be identified using sender argument of the method.
This argument used to be unused. The sender ID (e.g. ':1:3003')
can be used for finding of PID and this PID can be used for
finding command line used for starting the application that
sent the D-Bus method. This could be e.g.: 'dbus-send',
'cockpit-bridge', etc. (note: all command line options are
stripped for security reason to not send username nor password).
The command line of D-Bus sender is stored in singleton and
then this command line is added to User-Agent http header
as 'dbus_sender=cockpit-bridge'
dbus_handle_sender implemented in rhsmlib.dbus.util.
When it will not be desired to store sender for some method
then just don't use this decorator.
then it is little bit complicated, because system bus
is not used there, but custom unix socket is used. Thus
sender argument is not available. It is necessary to save
sender, when DomainSocketRegisterDBusObject is created using
com.redha.RHSM.Register.Start method
our D-Bus API