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 5dddbad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
34 changes: 17 additions & 17 deletions updater/reports/Report.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,22 @@ def scriptPath(self, script):
# Executes a script but prints stderr and returns stdout only
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 stdin:
cmd = script
else:
cmd = ["bash -s", "--"]
try:
with open(script) as f:
assert(stdin == None)
stdin = f.read()
except:
stdin = " ".join(map(lambda x: '"' + x.replace('\\"', '\\\\"').replace('"', '\\"') + '"', script))
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"]
] + cmd
stdout, stderr = executeCommand(script, stdin)

print(stderr.decode("utf-8"), file = sys.stderr)
Expand All @@ -101,12 +104,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 5dddbad

Please sign in to comment.