spark-197 - plugin.py security_key generation picks the wrong key
This commit is contained in:
1 parent
6a205d3316
commit
9bea06bd0d
2 files changed
+44
-14
No files matched your search
Vendored
+17
@@ -1,6 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"stopOnEntry": false,
|
||||
"pythonPath": "${config:python.pythonPath}",
|
||||
"program": "${file}",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"env": {},
|
||||
"envFile": "${workspaceRoot}/.env",
|
||||
"args": [ "DEBUG" ],
|
||||
"debugOptions": [
|
||||
"WaitOnAbnormalExit",
|
||||
"WaitOnNormalExit",
|
||||
"RedirectOutput"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "WSL Launch",
|
||||
"type": "cppdbg",
|
||||
|
||||
@@ -45,6 +45,7 @@ def type_name_cpp(name_with_ns):
|
||||
# Map protobuf raw types to intermediate type tree
|
||||
#
|
||||
MethodModel = namedtuple("MethodModel", "name comment server_streaming has_complex_key key_type key_field output_type_full output_type_cpp output_type input_type_full input_type_cpp input_type")
|
||||
KeyData = namedtuple("KeyData", "type field")
|
||||
def transform_method(m, keydata):
|
||||
return MethodModel(
|
||||
name=m.name,
|
||||
@@ -87,25 +88,23 @@ def transform_message(i):
|
||||
return r
|
||||
|
||||
ServiceModel = namedtuple("ServiceModel", "name comment method")
|
||||
def transform_service(service, keydata):
|
||||
KeyModel = namedtuple("KeyModel", "type field")
|
||||
DefaultKeyModel = KeyModel("int", "id")
|
||||
def transform_service(service, keymap):
|
||||
return ServiceModel(
|
||||
service.name,
|
||||
option(service.options, apioptions_pb2.service_description, ""),
|
||||
[transform_method(m, keydata) for m in service.method])
|
||||
[transform_method(m, keymap.get(m.output_type, DefaultKeyModel)) for m in service.method])
|
||||
|
||||
FileModel = namedtuple("FileModel", "name package namespace_csharp message_type service enum_type")
|
||||
KeyModel = namedtuple("KeyModel", "type field")
|
||||
def transform_file(p):
|
||||
def transform_file(p, keymap):
|
||||
message_types = [transform_message(m) for m in p.message_type]
|
||||
# Note: this keydata thing is wrong... this will find the first key in the file not the key for the service
|
||||
keydata = next((KeyModel(f.type,f.name) for m in message_types for f in m.field if f.is_key), None)
|
||||
keydata = keydata or next((KeyModel(f.type,f.name) for m in message_types for f in m.field if f.name == 'id'), KeyModel("int","id"))
|
||||
return FileModel(
|
||||
name = p.name,
|
||||
package = p.package,
|
||||
namespace_csharp = p.package,
|
||||
message_type = message_types,
|
||||
service = [transform_service(s, keydata) for s in p.service],
|
||||
service = [transform_service(s, keymap) for s in p.service],
|
||||
enum_type = [transform_enum(e) for e in p.enum_type]
|
||||
)
|
||||
|
||||
@@ -229,14 +228,28 @@ def generate_code(request, response):
|
||||
'type': lambda this,item: item.split('.')[-1:][0],
|
||||
'camel': lambda _,f: camel_case(f),
|
||||
}
|
||||
# for proto_file in request.proto_file:
|
||||
# todo: for all files on the input
|
||||
# get a list of their messages and Key fields
|
||||
# pass this as a dictionary into transform_file
|
||||
# pass
|
||||
keymap = {}
|
||||
# Generate a map of keys for all types across files
|
||||
for proto_file in request.proto_file:
|
||||
for msg in proto_file.message_type:
|
||||
# check eachfield
|
||||
found_key = False
|
||||
namekey = ".{}.{}".format(proto_file.package,msg.name)
|
||||
for field in msg.field:
|
||||
if option(field.options, apioptions_pb2.key, False):
|
||||
found_key = True
|
||||
keymap[namekey] = KeyData(to_type_model(field, msg), field.name)
|
||||
break
|
||||
# If no field was annotated as a key but there's a field named "id" use that
|
||||
if not found_key:
|
||||
for field in msg.field:
|
||||
if field.name == "id":
|
||||
keymap[namekey] = KeyData(to_type_model(field, msg), field.name)
|
||||
break
|
||||
|
||||
for proto_file in request.proto_file:
|
||||
if proto_file.name in request.file_to_generate:
|
||||
proto_file = transform_file(proto_file)
|
||||
proto_file = transform_file(proto_file, keymap)
|
||||
# Path on response.file name is interpreted differently by the c# and c++ code gen
|
||||
filename = ('strip_out_path' in params) and os.path.split(proto_file.name)[1] or proto_file.name
|
||||
source_name = os.path.splitext(filename)[0]
|
||||
|
||||
Reference in new issue
Block a user