black format bh_owned
parent
4f634d6f9e
commit
90de636536
|
@ -60,7 +60,7 @@ class CMEModule:
|
||||||
domain = connection.domain
|
domain = connection.domain
|
||||||
|
|
||||||
host_fqdn = (connection.hostname + "." + domain).upper()
|
host_fqdn = (connection.hostname + "." + domain).upper()
|
||||||
uri = "bolt://{}:{}".format(self.neo4j_URI, self.neo4j_Port)
|
uri = f"bolt://{self.neo4j_URI}:{self.neo4j_Port}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
driver = GraphDatabase.driver(
|
driver = GraphDatabase.driver(
|
||||||
|
@ -68,27 +68,25 @@ class CMEModule:
|
||||||
)
|
)
|
||||||
except AuthError as e:
|
except AuthError as e:
|
||||||
context.log.fail(
|
context.log.fail(
|
||||||
"Provided Neo4J credentials ({}:{}) are not valid. See --options".format(
|
f"Provided Neo4J credentials ({self.neo4j_user}:{self.neo4j_pass}) are"
|
||||||
self.neo4j_user, self.neo4j_pass
|
" not valid. See --options"
|
||||||
)
|
|
||||||
)
|
)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except ServiceUnavailable as e:
|
except ServiceUnavailable as e:
|
||||||
context.log.fail(
|
context.log.fail(
|
||||||
"Neo4J does not seem to be available on {}. See --options".format(uri)
|
f"Neo4J does not seem to be available on {uri}. See --options"
|
||||||
)
|
)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
context.log.fail("Unexpected error with Neo4J")
|
context.log.fail("Unexpected error with Neo4J")
|
||||||
context.log.debug("Error : ".format(str(e)))
|
context.log.debug(f"Error {e}: ")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
with driver.session() as session:
|
with driver.session() as session:
|
||||||
with session.begin_transaction() as tx:
|
with session.begin_transaction() as tx:
|
||||||
result = tx.run(
|
result = tx.run(
|
||||||
'MATCH (c:Computer {{name:"{}"}}) SET c.owned=True RETURN c.name AS name'.format(
|
f'MATCH (c:Computer {{name:"{host_fqdn}"}}) SET c.owned=True RETURN'
|
||||||
host_fqdn
|
" c.name AS name"
|
||||||
)
|
|
||||||
)
|
)
|
||||||
record = result.single()
|
record = result.single()
|
||||||
try:
|
try:
|
||||||
|
@ -97,12 +95,11 @@ class CMEModule:
|
||||||
value = []
|
value = []
|
||||||
if len(value) > 0:
|
if len(value) > 0:
|
||||||
context.log.success(
|
context.log.success(
|
||||||
"Node {} successfully set as owned in BloodHound".format(host_fqdn)
|
f"Node {host_fqdn} successfully set as owned in BloodHound"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
context.log.fail(
|
context.log.fail(
|
||||||
"Node {} does not appear to be in Neo4J database. Have you imported correct data?".format(
|
f"Node {host_fqdn} does not appear to be in Neo4J database. Have you"
|
||||||
host_fqdn
|
" imported the correct data?"
|
||||||
)
|
|
||||||
)
|
)
|
||||||
driver.close()
|
driver.close()
|
||||||
|
|
Loading…
Reference in New Issue