Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
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
OpenEdx
ansible
Commits
3c4dd618
Commit
3c4dd618
authored
Oct 18, 2013
by
James Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4454 Make a temporary clean cnf file if unable to parse existing
parent
1d090b5b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
library/database/mysql_user
+30
-0
No files found.
library/database/mysql_user
View file @
3c4dd618
...
@@ -134,6 +134,7 @@ password=n<_665{vS43y
...
@@ -134,6 +134,7 @@ password=n<_665{vS43y
import
ConfigParser
import
ConfigParser
import
getpass
import
getpass
import
tempfile
try
:
try
:
import
MySQLdb
import
MySQLdb
except
ImportError
:
except
ImportError
:
...
@@ -316,6 +317,32 @@ def config_get(config, section, option):
...
@@ -316,6 +317,32 @@ def config_get(config, section, option):
return
strip_quotes
(
config
.
get
(
section
,
option
))
return
strip_quotes
(
config
.
get
(
section
,
option
))
def
_safe_cnf_load
(
config
,
path
):
data
=
{
'user'
:
''
,
'password'
:
''
}
# read in user/pass
f
=
open
(
path
,
'r'
)
for
line
in
f
.
readlines
():
line
=
line
.
strip
()
if
line
.
startswith
(
'user='
):
data
[
'user'
]
=
line
.
split
(
'='
,
1
)[
1
]
.
strip
()
if
line
.
startswith
(
'password='
)
or
line
.
startswith
(
'pass='
):
data
[
'password'
]
=
line
.
split
(
'='
,
1
)[
1
]
.
strip
()
f
.
close
()
# write out a new cnf file with only user/pass
fh
,
newpath
=
tempfile
.
mkstemp
(
prefix
=
path
+
'.'
)
f
=
open
(
newpath
,
'wb'
)
f
.
write
(
'[client]
\n
'
)
f
.
write
(
'user=
%
s
\n
'
%
data
[
'user'
])
f
.
write
(
'password=
%
s
\n
'
%
data
[
'password'
])
f
.
close
()
config
.
readfp
(
open
(
newpath
))
os
.
remove
(
newpath
)
return
config
def
load_mycnf
():
def
load_mycnf
():
config
=
ConfigParser
.
RawConfigParser
()
config
=
ConfigParser
.
RawConfigParser
()
mycnf
=
os
.
path
.
expanduser
(
'~/.my.cnf'
)
mycnf
=
os
.
path
.
expanduser
(
'~/.my.cnf'
)
...
@@ -325,6 +352,9 @@ def load_mycnf():
...
@@ -325,6 +352,9 @@ def load_mycnf():
config
.
readfp
(
open
(
mycnf
))
config
.
readfp
(
open
(
mycnf
))
except
(
IOError
):
except
(
IOError
):
return
False
return
False
except
:
config
=
_safe_cnf_load
(
config
,
mycnf
)
# We support two forms of passwords in .my.cnf, both pass= and password=,
# We support two forms of passwords in .my.cnf, both pass= and password=,
# as these are both supported by MySQL.
# as these are both supported by MySQL.
try
:
try
:
...
...
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