Skip to content

Commit

Permalink
fix executeGHEConsole() / ReportOrgOwners for Hubble service
Browse files Browse the repository at this point in the history
The executeGHEConsole() function (and consequently the ReportOrgOwners)
was broken if Hubble is configures as service that runs on the GitHub
Enterprise appliance. Fix it.
  • Loading branch information
Lars Schneider committed Nov 20, 2017
1 parent c66ec18 commit 1442407
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
43 changes: 25 additions & 18 deletions updater/reports/Report.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,32 @@ def scriptPath(self, script):
script
)

# Executes a script but prints stderr and returns stdout only
# Executes a script but prints stderr and returns stdout only.
# A script is either a path to a file or a list of strings with bash
# commands.
# In case of a remote run (IOW: scripts run via SSH), the script is
# executed by passing its content via stdin to `bash -s --`. This
# method only works if the script has no stdin not set already.
def executeScript(self, script, stdin = None):
if self.configuration["remoteRun"]["enabled"]:
try:
with open(script) as f:
assert(stdin == None)
stdin = f.read()
command = ["bash -s", "--"]
except:
command = script
if not stdin:
try:
# If the script is a file, then read its content as-is into stdin
with open(script) as f:
stdin = f.read()
except:
# If the script is a list of strings, then escape the content and set it to stdin
stdin = " ".join(map(lambda x: '"' + x.replace('\\"', '\\\\"').replace('"', '\\"') + '"', script))
script = ["bash -s", "--"]

# Execute the script via SSH
script = [
"ssh",
"-i", self.configuration["remoteRun"]["sshKey"],
"-p", "122",
"admin@" + self.configuration["remoteRun"]["gheHost"],
] + command
"ssh",
"-i", self.configuration["remoteRun"]["sshKey"],
"-p", "122",
"admin@" + self.configuration["remoteRun"]["gheHost"]
] + script

stdout, stderr = executeCommand(script, stdin)

print(stderr.decode("utf-8"), file = sys.stderr)
Expand All @@ -101,12 +111,9 @@ def executeScript(self, script, stdin = None):
return stdout

def executeGHEConsole(self, rubyCode):
escapedRubyCode = rubyCode.replace('\\t', '\\\\t') \
.replace('\\n', '\\\\n') \
.replace('"', '\\"')
escapedRubyCode = rubyCode.replace('\\t', '\\\\t').replace('\\n', '\\\\n')
return self.executeScript(
["bash -s", "--"],
"github-env bin/runner -e production \"'" + escapedRubyCode + "'\""
["github-env", "bin/runner", "-e", "production", "'" + escapedRubyCode + "'"]
)

# Executes a database query, given as a string
Expand Down
4 changes: 2 additions & 2 deletions updater/reports/ReportOrgOwners.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def updateData(self):
self.executeGHEConsole('''
puts "organization\towner(s)\n"
User.where(:type => "Organization")
.where("''' + self.andExcludedEntities("login", "").replace('"', '\\\\"') + '''")
.where("''' + self.andExcludedEntities("login", "").replace('"', '\\"') + '''")
.order("login")
.each do |org|
owners = org.admins.where(:disabled => false, :gh_role => nil)
.where("''' + self.andExcludedUsers("login", "").replace('"', '\\\\"') + '''")
.where("''' + self.andExcludedUsers("login", "").replace('"', '\\"') + '''")
.order("login")
.join(",")
puts "#{org.login}\t#{owners}\n"
Expand Down

0 comments on commit 1442407

Please sign in to comment.