Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
21a4520b
Commit
21a4520b
authored
Jan 06, 2014
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove output of management command options and args from tracking logs.
parent
1aefe2f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
56 deletions
+3
-56
common/djangoapps/track/management/tests/test_tracked_command.py
+1
-19
common/djangoapps/track/management/tracked_command.py
+2
-37
No files found.
common/djangoapps/track/management/tests/test_tracked_command.py
View file @
21a4520b
...
...
@@ -4,7 +4,7 @@ from django.test import TestCase
from
eventtracking
import
tracker
as
eventtracker
from
track.command
import
TrackedCommand
from
track.
management.tracked_
command
import
TrackedCommand
class
DummyCommand
(
TrackedCommand
):
...
...
@@ -27,21 +27,3 @@ class CommandsTestBase(TestCase):
kwargs
=
{
'key1'
:
'default'
,
'key2'
:
True
}
json_out
=
self
.
_run_dummy_command
(
*
args
,
**
kwargs
)
self
.
assertEquals
(
json_out
[
'command'
],
'unknown'
)
self
.
assertEquals
(
json_out
[
'command_args'
],
args
)
self
.
assertEquals
(
json_out
[
'command_options'
],
kwargs
)
def
test_password_in_command
(
self
):
args
=
[]
kwargs
=
{
'password'
:
'default'
}
json_out
=
self
.
_run_dummy_command
(
*
args
,
**
kwargs
)
self
.
assertEquals
(
json_out
[
'command'
],
'unknown'
)
self
.
assertEquals
(
json_out
[
'command_args'
],
args
)
self
.
assertEquals
(
json_out
[
'command_options'
],
{
'password'
:
'********'
})
def
test_removed_args_in_command
(
self
):
args
=
[]
kwargs
=
{
'settings'
:
'dummy'
,
'pythonpath'
:
'whee'
}
json_out
=
self
.
_run_dummy_command
(
*
args
,
**
kwargs
)
self
.
assertEquals
(
json_out
[
'command'
],
'unknown'
)
self
.
assertEquals
(
json_out
[
'command_args'
],
args
)
self
.
assertEquals
(
json_out
[
'command_options'
],
{})
common/djangoapps/track/management/tracked_command.py
View file @
21a4520b
...
...
@@ -9,19 +9,11 @@ class TrackedCommand(BaseCommand):
"""
Provides management command calling info to tracking context.
Information provided to context includes th
ree values
:
Information provided to context includes th
e following value
:
'command': the program name and the subcommand used to run a management command.
'command_args': the argument list passed to the command.
'command_options': the option dict passed to the command. This includes options
that were not explicitly specified, and receive default values.
Special treatment are provided for several options, including obfuscation and filtering.
The values for the following options are filtered entirely:
'settings', 'pythonpath', 'verbosity', 'traceback', 'stdout', 'stderr'.
The values for the following options are replaced with eight asterisks:
'password'.
In future, other values (such as args and options) could be added as needed.
An example tracking log entry resulting from running the 'create_user' management command:
...
...
@@ -33,17 +25,7 @@ class TrackedCommand(BaseCommand):
"context": {
"course_id": "edX/Open_DemoX/edx_demo_course",
"org_id": "edX",
"command_options": {
"username": null,
"name": null,
"course": "edX/Open_DemoX/edx_demo_course",
"mode": "verified",
"password": "********",
"email": "rando9c@example.com",
"staff": false
},
"command": "./manage.py create_user",
"command_args": []
},
"time": "2014-01-06T15:59:49.599522+00:00",
"ip": "",
...
...
@@ -69,25 +51,8 @@ class TrackedCommand(BaseCommand):
def
execute
(
self
,
*
args
,
**
options
):
"""Wraps base execute() to add command line to tracking context."""
# Make a copy of options, and obfuscate or filter particular values.
options_dict
=
dict
(
options
)
# Stuff to obfuscate:
censored_opts
=
[
'password'
]
for
opt
in
censored_opts
:
if
opt
in
options_dict
:
options_dict
[
opt
]
=
'*'
*
8
# Stuff to filter:
removed_opts
=
[
'settings'
,
'pythonpath'
,
'verbosity'
,
'traceback'
,
'stdout'
,
'stderr'
]
for
opt
in
removed_opts
:
if
opt
in
options_dict
:
del
options_dict
[
opt
]
context
=
{
'command'
:
self
.
prog_name
,
'command_args'
:
args
,
'command_options'
:
options_dict
,
}
COMMAND_CONTEXT_NAME
=
'edx.mgmt.command'
with
tracker
.
get_tracker
()
.
context
(
COMMAND_CONTEXT_NAME
,
context
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment