Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix literal secret handling in Dynalists #331

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 25 additions & 55 deletions xircuits/compiler/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ def unparse(parsed):
return f.getvalue()


def _get_value_from_literal_port(port):
if port.source.type == "string" or port.source.type == "secret":
value = port.sourceLabel
elif port.source.type == "list":
value = json.loads("[" + port.sourceLabel + "]")
elif port.source.type == "dict":
value = json.loads("{" + port.sourceLabel + "}")
elif port.source.type == "chat":
value = json.loads(port.sourceLabel)
elif port.source.type == "tuple":
if port.sourceLabel == "":
value = ()
else:
value = eval(port.sourceLabel)
if not isinstance(value, tuple):
# Handler for single entry tuple
value = (value,)
else:
value = eval(port.sourceLabel)

return value

class CodeGenerator:
def __init__(self, graph, component_python_paths):
self.graph = graph
Expand Down Expand Up @@ -163,27 +185,7 @@ def execute(self, ctx):
if port.source.id not in named_nodes:
# Literal
tpl = set_value(assignment_target, '1')
if port.source.type == "string":
value = port.sourceLabel
elif port.source.type == "list":
value = json.loads("[" + port.sourceLabel + "]")
elif port.source.type == "dict":
value = json.loads("{" + port.sourceLabel + "}")
elif port.source.type == "secret":
value = port.sourceLabel
elif port.source.type == "chat":
value = json.loads(port.sourceLabel)
elif port.source.type == "tuple":
if port.sourceLabel == "":
value = ()
else:
value = eval(port.sourceLabel)
if not isinstance(value, tuple):
# Handler for single entry tuple
value = (value,)
else:
value = eval(port.sourceLabel)
tpl.body[0].value.value = value
tpl.body[0].value.value = _get_value_from_literal_port(port)
else:
assignment_source = "%s.%s" % (
named_nodes[port.source.id],
Expand All @@ -210,23 +212,7 @@ def execute(self, ctx):

for port in ports:
if port.source.id not in named_nodes:
# Handle Literals
if port.source.type == "string":
value = port.sourceLabel
elif port.source.type == "list":
value = json.loads("[" + port.sourceLabel + "]")
elif port.source.type == "dict":
value = json.loads("{" + port.sourceLabel + "}")
elif port.source.type == "tuple":
if port.sourceLabel == "":
value = ()
else:
value = eval(port.sourceLabel)
if not isinstance(value, tuple):
# Handler for single entry tuple
value = (value,)
else:
value = eval(port.sourceLabel)
value = _get_value_from_literal_port(port)
dynaport_values.append(RefOrValue(value, False))
else:
# Handle named node references
Expand Down Expand Up @@ -257,23 +243,7 @@ def execute(self, ctx):
if port.source.id not in named_nodes:
# Literal
tpl = set_value(assignment_target, '1')
if port.source.type == "string":
value = port.sourceLabel
elif port.source.type == "list":
value = json.loads("[" + port.sourceLabel + "]")
elif port.source.type == "dict":
value = json.loads("{" + port.sourceLabel + "}")
elif port.source.type == "secret":
value = port.sourceLabel
elif port.source.type == "chat":
value = json.loads(port.sourceLabel)
elif port.source.type == "tuple":
value = eval(port.sourceLabel)
if not isinstance(value, tuple):
# handler for single entry tuple
value = (value,)
else:
value = eval(port.sourceLabel)
value = _get_value_from_literal_port(port)
tpl.body[0].value.value = value
port_type = type(value).__name__
else:
Expand Down
Loading