Ejemplo n.º 1
0
 def sendAccessNotification(self,
                            mysqlClusters,
                            mysqlUserAtHost,
                            mysqlPass,
                            defaultCluster,
                            toList=None):
     mysqlUser, mysqlHost = (x.strip("'")
                             for x in mysqlUserAtHost.split('@'))
     receipients = toList
     if receipients is None:
         emailDomain = self._email.split('@')[1]
         receipients = [mysqlUser + '@' + emailDomain]
     subject = "MySQL Access Notification"
     templateArgDict = {
         'mysqlUser': mysqlUser,
         'mysqlHost': mysqlHost,
         'mysqlClusters': ",".join(mysqlClusters),
         'defaultCluster': defaultCluster,
         'email': self._email
     }
     message = util.renderTemplate("password_change_access.tmpl",
                                   templateArgDict)
     logger.info(
         "Sent Access Notification to [%s] for %s on %s with password %s",
         ", ".join(receipients), mysqlUser, ",".join(mysqlClusters),
         mysqlPass)
     self.sendMail(receipients, subject, message)
Ejemplo n.º 2
0
 def sendChangePasswordInvite(self,
                              mysqlClusters,
                              mysqlUserAtHost,
                              mysqlPass,
                              toList=None):
     attachPayloads = {}
     mysqlUser, mysqlHost = (x.strip("'")
                             for x in mysqlUserAtHost.split('@'))
     passwordChangeScript = self.getPasswordChangeScript(
         mysqlClusters, mysqlUser, mysqlHost, mysqlPass)
     rawHasteBinUrl = self.getHasteBinUrl(passwordChangeScript)
     if rawHasteBinUrl is not None:
         passwordChangeInst = "curl -fsSL " + rawHasteBinUrl + " | python"
     else:
         attachPayloads['password_change_invite.py'] = passwordChangeScript
         passwordChangeInst = "Download the password_change_invite.py script\nRun python password_change_invite.py from a command prompt\nFollow the on screen instructions"
     receipients = toList
     if receipients is None:
         emailDomain = self._email.split('@')[1]
         receipients = [mysqlUser + '@' + emailDomain]
     subject = "MySQL Password Change Invite"
     templateArgDict = {
         'mysqlUser': mysqlUser,
         'mysqlHost': mysqlHost,
         'mysqlPass': mysqlPass,
         'email': self._email,
         'passwordChangeInst': passwordChangeInst
     }
     message = util.renderTemplate("password_change_invite.tmpl",
                                   templateArgDict)
     logger.info(
         "Sent ChangePassInvite to [%s] for %s on %s with password %s",
         receipients, mysqlUser, mysqlClusters, mysqlPass)
     self.sendMail(receipients, subject, message, attachPayloads)
Ejemplo n.º 3
0
def init_config(nonInteractive):
    configFile = os.path.join(os.getcwd(), 'auto_grant.yaml')
    if os.path.exists(configFile):
        raise Exception(
            "could not generate auto_grant.yaml file already exists")
    else:
        if nonInteractive:
            mysqlUser = "******"
            mysqlPass = "******"
            gmailUser = "******"
            gmailPass = "******"
        else:
            mysqlUser = util.askQuestion("Please enter your mysql user",
                                         "grant_user")
            mysqlPass = util.askPassword("Please enter your mysql password",
                                         "grant_pass")
            gmailUser = util.askQuestion("Please enter your gmail user")
            gmailPass = util.askPassword("Please enter your gmail password")
        templateArgDict = {
            'mysqlUser': mysqlUser,
            'mysqlPass': mysqlPass,
            'gmailUser': gmailUser,
            'gmailPass': gmailPass
        }
        payload = util.renderTemplate("auto_grant.yaml.tmpl", templateArgDict)
        with open(configFile, 'w') as f:
            f.write(payload)
Ejemplo n.º 4
0
    def test_getEmailTemplate(self):
        self.maxDiff = None
        templateContents = """
Hello {{ u }},

You are now the proud owner of your very own MySQL user:
'******'@'{{ h }}'
The first thing you should do is change your password.
This can be done easily but first setting an by running the following commands:
First set an environment variable with your password
$ export NMP="INSERT_YOUR_FAVORITE_PASSWORD_HERE"
Then you can just copy paste these lines to set your password:
{% for cl in c %}
# after being connected to {{ h }}:
$ mysql -h {{ cl }} -u '{{ u }}' -p{{ p }} -e "SET PASSWORD = PASSWORD($NMP)"
{% endfor %}
Please feel free to reply to this email with any questions you may have.

Happy Querying,
Bob T. Builder <{{ e }}>
http://i.imgur.com/IaqNsAd.jpg"""
        templateArgDict = {
            'u': "user",
            'h': "fromHost",
            'p': "password",
            'e': "*****@*****.**",
            'c': set(["cluster1", "cluster2"])
        }
        renderedTemplate = util.renderTemplate(templateContents,
                                               templateArgDict)
        expectedRenderedTemplate = u"""
Hello user,

You are now the proud owner of your very own MySQL user:
'******'@'fromHost'
The first thing you should do is change your password.
This can be done easily but first setting an by running the following commands:
First set an environment variable with your password
$ export NMP="INSERT_YOUR_FAVORITE_PASSWORD_HERE"
Then you can just copy paste these lines to set your password:

# after being connected to fromHost:
$ mysql -h cluster2 -u 'user' -ppassword -e "SET PASSWORD = PASSWORD($NMP)"

# after being connected to fromHost:
$ mysql -h cluster1 -u 'user' -ppassword -e "SET PASSWORD = PASSWORD($NMP)"

Please feel free to reply to this email with any questions you may have.

Happy Querying,
Bob T. Builder <*****@*****.**>
http://i.imgur.com/IaqNsAd.jpg"""
        self.assertEquals(expectedRenderedTemplate, renderedTemplate)
Ejemplo n.º 5
0
 def getPasswordChangeScript(self,
                             mysqlClusters,
                             mysqlUser,
                             mysqlHost,
                             mysqlPass,
                             raw=True):
     templateArgDict = {
         'mysqlUser': mysqlUser,
         'mysqlHost': mysqlHost,
         'mysqlPass': mysqlPass,
         'mysqlClusters': mysqlClusters
     }
     payload = util.renderTemplate("password_change.py.tmpl",
                                   templateArgDict)
     return payload