def add_key(self):
try:<EOL><INDENT>with open(self.args.ssh_public_key) as f:<EOL><INDENT>public_key = f.read().strip()<EOL><DEDENT><DEDENT>except:<EOL><INDENT>log.debug("<STR_LIT>".format(self.args.ssh_public_key))<EOL>return None<EOL><DEDENT>g = self.gitlab<EOL>url = g['<STR_LIT:url>'] + "<STR_LIT>"<EOL>query = {'<STR_LIT>': g['<STR_LIT>']}<EOL>keys = requests.get(url, params=query).json()<EOL>log.debug("<STR_LIT>" + public_key + "<STR_LIT>" + str(keys))<EOL>if (list(filter(lambda key: key['<STR_LIT:key>'] == public_key, keys))):<EOL><INDENT>log.debug(self.args.ssh_public_key + "<STR_LIT>")<EOL>return None<EOL><DEDENT>else:<EOL><INDENT>name = '<STR_LIT>'<EOL>log.info("<STR_LIT>" + name + "<STR_LIT>" +<EOL>self.args.ssh_public_key)<EOL>query['<STR_LIT:title>'] = name<EOL>query['<STR_LIT:key>'] = public_key<EOL>result = requests.post(url, query)<EOL>if result.status_code != requests.codes.created:<EOL><INDENT>log.warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(self.args.ssh_public_key))<EOL><DEDENT>return public_key<EOL><DEDENT>
Add ssh key to gitlab if necessary