forked from ddd/req2proto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
647 lines (547 loc) · 20.9 KB
/
main.go
File metadata and controls
647 lines (547 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
package main
import (
"flag"
"fmt"
"log"
"net/url"
"os"
"regexp"
"req2proto/parser"
"strconv"
"strings"
"time"
"github.com/rs/zerolog"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/types/descriptorpb"
)
var (
logger zerolog.Logger
headerRe = regexp.MustCompile(`:\s*`)
messageRe = regexp.MustCompile(`^((?:[a-z0-9_]+\.)*[a-z0-9_]+)\.([A-Z][A-Za-z.0-9_]+)$`)
fieldDescRe = regexp.MustCompile(`Invalid value at '(.+)' \((.*)\), (?:Base64 decoding failed for )?"?x?([^"]*)"?`)
requiredFieldRe = regexp.MustCompile(`Missing required field (.+) at '([^']+)'`)
packageFDProtoMap = make(map[string]*descriptorpb.FileDescriptorProto)
packageDependencyMap = make(map[string][]string)
)
var typeMap = map[string]*descriptorpb.FieldDescriptorProto_Type{
"TYPE_STRING": descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum(),
"TYPE_BOOL": descriptorpb.FieldDescriptorProto_TYPE_BOOL.Enum(),
"TYPE_INT64": descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
"TYPE_UINT64": descriptorpb.FieldDescriptorProto_TYPE_UINT64.Enum(),
"TYPE_INT32": descriptorpb.FieldDescriptorProto_TYPE_INT32.Enum(),
"TYPE_UINT32": descriptorpb.FieldDescriptorProto_TYPE_UINT32.Enum(),
"TYPE_DOUBLE": descriptorpb.FieldDescriptorProto_TYPE_DOUBLE.Enum(),
"TYPE_FLOAT": descriptorpb.FieldDescriptorProto_TYPE_FLOAT.Enum(),
"TYPE_BYTES": descriptorpb.FieldDescriptorProto_TYPE_BYTES.Enum(),
"TYPE_FIXED64": descriptorpb.FieldDescriptorProto_TYPE_FIXED64.Enum(),
"TYPE_FIXED32": descriptorpb.FieldDescriptorProto_TYPE_FIXED32.Enum(),
"TYPE_SINT64": descriptorpb.FieldDescriptorProto_TYPE_SINT64.Enum(),
"TYPE_SINT32": descriptorpb.FieldDescriptorProto_TYPE_SINT32.Enum(),
"TYPE_SFIXED64": descriptorpb.FieldDescriptorProto_TYPE_SFIXED64.Enum(),
"TYPE_SFIXED32": descriptorpb.FieldDescriptorProto_TYPE_SFIXED32.Enum(),
}
type headerSliceFlag []string
func (h *headerSliceFlag) String() string {
return fmt.Sprint(*h)
}
func (h *headerSliceFlag) Set(value string) error {
*h = append(*h, value)
return nil
}
func cleanupDuplicateFields(fdproto *descriptorpb.FileDescriptorProto, verbose bool) {
// Create maps for top-level enum names
enumNames := make(map[string]bool)
// Populate top-level enum names first
for _, enum := range fdproto.EnumType {
enumNames[*enum.Name] = true
}
// Check and remove conflicting top-level messages
var newMessageType []*descriptorpb.DescriptorProto
for _, msgType := range fdproto.MessageType {
if enumNames[*msgType.Name] {
if verbose {
logger.Debug().Str("message", *msgType.Name).Msg("Removed top-level message as it conflicts with an enum")
}
} else {
cleanupMessageType(msgType, verbose)
newMessageType = append(newMessageType, msgType)
}
}
fdproto.MessageType = newMessageType
}
func cleanupMessageType(msgType *descriptorpb.DescriptorProto, verbose bool) {
// Create a map of enum names
enumNames := make(map[string]bool)
// Populate enum names first
for _, enum := range msgType.EnumType {
enumNames[*enum.Name] = true
}
// Check and remove conflicting nested types
var newNestedType []*descriptorpb.DescriptorProto
for _, nestedType := range msgType.NestedType {
if enumNames[*nestedType.Name] {
if verbose {
logger.Debug().Str("message", *nestedType.Name).Msg("Removed nested message as it conflicts with an enum")
}
} else {
newNestedType = append(newNestedType, nestedType)
}
}
msgType.NestedType = newNestedType
// Recursively clean up nested message types
for _, nestedType := range msgType.NestedType {
cleanupMessageType(nestedType, verbose)
}
}
func getOrCreateMessageDescriptor(fileDesc *descriptorpb.FileDescriptorProto, messageName string) (*descriptorpb.DescriptorProto, *descriptorpb.EnumDescriptorProto, error) {
parts := strings.Split(messageName, ".")
var currentMessage *descriptorpb.DescriptorProto
var currentMessages *[]*descriptorpb.DescriptorProto = &fileDesc.MessageType
var currentEnums *[]*descriptorpb.EnumDescriptorProto = &fileDesc.EnumType
for i, part := range parts {
if i == len(parts)-1 {
// Check if the last part is an enum
if enum := findEnum(currentEnums, part); enum != nil {
return nil, enum, nil
}
}
currentMessage = findOrCreateMessage(currentMessages, part)
if i < len(parts)-1 {
// If we're not at the last part, we need to go deeper
currentMessages = ¤tMessage.NestedType
currentEnums = ¤tMessage.EnumType
}
}
return currentMessage, nil, nil
}
func findOrCreateMessage(messages *[]*descriptorpb.DescriptorProto, name string) *descriptorpb.DescriptorProto {
for _, msg := range *messages {
if msg.GetName() == name {
return msg
}
}
// If the message doesn't exist, create it
newMessage := &descriptorpb.DescriptorProto{
Name: proto.String(name),
}
*messages = append(*messages, newMessage)
return newMessage
}
func findEnum(enums *[]*descriptorpb.EnumDescriptorProto, name string) *descriptorpb.EnumDescriptorProto {
for _, enum := range *enums {
if enum.GetName() == name {
return enum
}
}
return nil
}
type MsgChData struct {
Package string
Message string
Index []int
DescProto *descriptorpb.DescriptorProto
ParentDescProto *descriptorpb.DescriptorProto
RequiredFieldsToLabel []string
}
func monitorAndCloseChannel(msgCh chan MsgChData) {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
timer := time.NewTimer(10 * time.Second)
defer timer.Stop()
for {
select {
case <-ticker.C:
if len(msgCh) > 0 {
timer.Reset(10 * time.Second)
}
case <-timer.C:
close(msgCh)
return
}
}
}
// This function recieves fdProto and index of messages to probe further fields in
func probeNestedMessageWorker(msgCh chan MsgChData, method string, url string, headers map[string]string, maxDepth int, verbose bool) {
for msgChData := range msgCh {
// probe for int violations
payload := genPayload(msgChData.Index, "int")
intViolations, err := probeAPI(method, url, headers, payload)
if err != nil {
logger.Fatal().Err(err).Msg("error when probing api")
}
// probe for str violations
payload = genPayload(msgChData.Index, "str")
violations, err := probeAPI(method, url, headers, payload)
if err != nil {
logger.Fatal().Err(err).Msg("error when probing api")
}
// add all violations together
violations = append(violations, intViolations...)
// TODO: add mutex locks everywhere when iterating and appending
alreadyPresentFields := make(map[int]struct{})
for _, field := range msgChData.DescProto.Field {
alreadyPresentFields[int(*field.Number)] = struct{}{}
}
// first, we have to loop through violations and find if there's any required field errors. requiredFieldMap is a map of full field name of message and array of required fields
requiredFieldMap := make(map[string][]string, 300)
for _, i := range violations {
if strings.HasPrefix(i.Description, "Missing required field") {
x := requiredFieldRe.FindStringSubmatch(i.Description)
requiredFields, ok := requiredFieldMap[i.Field]
if !ok {
requiredFieldMap[i.Field] = []string{x[1]}
} else {
requiredFieldMap[i.Field] = append(requiredFields, x[1])
}
}
}
addedFields := make(map[string]struct{}, 100)
for _, i := range violations {
// enum
if i.Description == "Invalid value (), Unexpected list for single non-message field." || i.Description == "Invalid value (), List is not message or group type." {
// if enum, we find parent, then set it's field Type and TypeName. after that, we append an entry to EnumType.
x := strings.Split(msgChData.Message, ".")
lastIndex := msgChData.Index[len(msgChData.Index)-1]
for _, i := range msgChData.ParentDescProto.Field {
if int(*i.Number) == lastIndex {
if verbose {
logger.Debug().Str("field_name", *i.Name).Str("package", msgChData.Package).Str("message", msgChData.Message).Msg("updated type to enum")
}
i.Type = descriptorpb.FieldDescriptorProto_TYPE_ENUM.Enum()
newTypeName := "." + msgChData.Package + "." + msgChData.Message
i.TypeName = &newTypeName
}
}
// If the parent is the FileDescriptorProto
if len(x) == 1 {
actualParentDesc := packageFDProtoMap[msgChData.Package]
exists := false
for _, i := range actualParentDesc.EnumType {
if *i.Name == msgChData.Message {
exists = true
break
}
}
if !exists {
actualParentDesc.EnumType = append(actualParentDesc.EnumType, &descriptorpb.EnumDescriptorProto{
Name: proto.String(msgChData.Message),
Value: []*descriptorpb.EnumValueDescriptorProto{
{Name: proto.String(convertToUnknownType(msgChData.Message)), Number: proto.Int32(0)},
},
})
}
} else {
actualParentDesc, _, err := getOrCreateMessageDescriptor(packageFDProtoMap[msgChData.Package], strings.Join(x[:len(x)-1], "."))
if err != nil {
panic(err)
}
exists := false
for _, i := range actualParentDesc.EnumType {
if *i.Name == x[len(x)-1] {
exists = true
break
}
}
if !exists {
actualParentDesc.EnumType = append(actualParentDesc.EnumType, &descriptorpb.EnumDescriptorProto{
Name: proto.String(x[len(x)-1]),
Value: []*descriptorpb.EnumValueDescriptorProto{
{Name: proto.String(convertToUnknownType(x[len(x)-1])), Number: proto.Int32(0)},
},
})
}
}
break
}
// required field, we settled this before, so we can skip
if strings.HasPrefix(i.Description, "Missing required field") {
continue
}
z := strings.Split(i.Field, ".")
fieldName := z[len(z)-1]
matches := fieldDescRe.FindStringSubmatch(i.Description)
if len(matches) < 3 {
logger.Error().Str("description", i.Description).Str("message", msgChData.Message).Msg("unable to parse violation error description")
continue
}
number, _ := strconv.Atoi(matches[3])
// repeated
if strings.HasSuffix(fieldName, "]") {
// if repeated, we find parent, and then set this as repeated flag
x := strings.Split(msgChData.Message, ".")
// find the message's field, and set the label to repeated
for _, i := range msgChData.ParentDescProto.Field {
if *i.Name == x[len(x)-1] {
i.Label = descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum()
}
}
if verbose {
logger.Debug().Str("field_name", fieldName).Str("parent_message", *msgChData.ParentDescProto.Name).Str("package", msgChData.Package).Str("index", fmt.Sprint(msgChData.Index)).Msg("set field as repeated")
}
// after that, we append 0 to index and send back to msgCh, then break out of the violations loop
if maxDepth < 0 || !(len(msgChData.Index) == maxDepth) {
msgCh <- MsgChData{Package: msgChData.Package, Message: msgChData.Message, DescProto: msgChData.DescProto, ParentDescProto: msgChData.DescProto, Index: append(msgChData.Index, 1)}
}
break
}
// field is not a message
if strings.HasPrefix(matches[2], "TYPE_") {
_, ok := alreadyPresentFields[number]
if !ok {
label := descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum()
for _, requiredField := range msgChData.RequiredFieldsToLabel {
if requiredField == fieldName {
label = descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum()
packageFDProtoMap[msgChData.Package].Syntax = proto.String("proto2")
}
}
addedFields[fieldName] = struct{}{}
msgChData.DescProto.Field = append(msgChData.DescProto.Field, &descriptorpb.FieldDescriptorProto{
Name: proto.String(fieldName),
Number: proto.Int32(int32(number)),
Label: label,
Type: typeMap[matches[2]],
JsonName: proto.String(fieldName),
})
alreadyPresentFields[number] = struct{}{}
}
} else {
_, ok := alreadyPresentFields[number]
if !ok {
z := strings.Split(matches[2], ".")
nestedMessageName := z[len(z)-1]
// getting the package and message name from the googleapi type
//fmt.Println(matches[2])
x := messageRe.FindStringSubmatch(strings.Split(matches[2], "type.googleapis.com/")[1])
var packageName, fullMessageName string
if x != nil {
packageName = x[1]
fullMessageName = x[2]
} else {
// if we can't find a package name, we just put it under google
packageName = "google"
fullMessageName = strings.Split(matches[2], "type.googleapis.com/")[1]
nestedMessageName = fullMessageName
}
var descProto *descriptorpb.DescriptorProto
fdproto, ok := packageFDProtoMap[packageName]
if !ok {
// we can't find a fdproto for that package, so we make a new one
packageFDProtoMap[packageName] = &descriptorpb.FileDescriptorProto{
Name: proto.String(strings.Replace(packageName, ".", "/", -1) + "/message.proto"),
Syntax: proto.String("proto3"),
Package: proto.String(packageName),
MessageType: []*descriptorpb.DescriptorProto{
{
Name: proto.String(nestedMessageName),
},
},
}
fdproto = packageFDProtoMap[packageName]
descProto = fdproto.MessageType[0]
} else {
// the fdproto for that package exists, so we find if the message exists in there, if it doesn't, create it
var enum *descriptorpb.EnumDescriptorProto
descProto, enum, err = getOrCreateMessageDescriptor(fdproto, fullMessageName)
if err != nil {
panic(err)
}
// skip, as there's already an enum with this name
if enum != nil {
continue
}
}
// adding dependency of package if it's on another file
if packageName != msgChData.Package {
dependencyFileName := strings.Replace(packageName, ".", "/", -1) + "/message.proto"
alreadyAdded := false
for _, i := range packageDependencyMap[msgChData.Package] {
if i == dependencyFileName {
alreadyAdded = true
break
}
}
if !alreadyAdded {
packageDependencyMap[msgChData.Package] = append(packageDependencyMap[msgChData.Package], dependencyFileName)
}
}
// if we found google.protobuf.Any, we don't need to probe it
if matches[2] == "type.googleapis.com/google.protobuf.Any" {
exists := false
for _, i := range packageFDProtoMap["google.protobuf"].MessageType {
if *i.Name == "Any" && i.Field != nil && *i.Field[0].Name == "type_url" {
exists = true
break
}
}
if !exists {
for _, i := range packageFDProtoMap["google.protobuf"].MessageType {
if *i.Name == "Any" {
i.Field = append(i.Field, []*descriptorpb.FieldDescriptorProto{
{
Name: proto.String("type_url"),
Number: proto.Int32(1),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum().Enum(),
JsonName: proto.String("type_url"),
},
{
// this is a guess as to what the internal name is, no clue honestly.
Name: proto.String("data"),
Number: proto.Int32(2),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
Type: descriptorpb.FieldDescriptorProto_TYPE_BYTES.Enum(),
JsonName: proto.String("data"),
},
}...)
}
}
}
} else {
// send the descProto to msgCh so that it will be probed next
if maxDepth < 0 || !(len(msgChData.Index) == maxDepth) {
newIndex := append(msgChData.Index, number)
requiredFields := requiredFieldMap[i.Field]
msgCh <- MsgChData{Package: packageName, Message: fullMessageName, DescProto: descProto, ParentDescProto: msgChData.DescProto, Index: newIndex, RequiredFieldsToLabel: requiredFields}
}
}
label := descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum()
for _, requiredField := range msgChData.RequiredFieldsToLabel {
if requiredField == fieldName {
label = descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum()
packageFDProtoMap[packageName].Syntax = proto.String("proto2")
}
}
addedFields[fieldName] = struct{}{}
msgChData.DescProto.Field = append(msgChData.DescProto.Field, &descriptorpb.FieldDescriptorProto{
Name: proto.String(fieldName),
Number: proto.Int32(int32(number)),
Label: label,
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
TypeName: proto.String("." + strings.Split(matches[2], "type.googleapis.com/")[1]),
JsonName: proto.String(fieldName),
})
alreadyPresentFields[number] = struct{}{}
}
}
}
}
}
func modifyAltParameter(inputURL string) string {
// Parse the URL
parsedURL, err := url.Parse(inputURL)
if err != nil {
panic(err)
}
// Get the query parameters
values := parsedURL.Query()
// Check if alt parameter exists
altValue := values.Get("alt")
if altValue == "" {
// If alt doesn't exist, add alt=json
values.Set("alt", "json")
} else if altValue != "json" {
// If alt exists but isn't json, replace it with json
values.Set("alt", "json")
}
// Set the new query string
parsedURL.RawQuery = values.Encode()
return parsedURL.String()
}
func main() {
// Define flags
method := flag.String("X", "POST", "HTTP method (GET or POST)")
url := flag.String("u", "", "URL to send the request to")
maxDepth := flag.Int("d", -1, "Maximum depth to probe (unlimited: -1)")
outputDir := flag.String("o", "output", "Directory for .proto files to be output (can be full or relative path)")
verbose := flag.Bool("v", false, "Verbose mode")
reqMessageName := flag.String("p", "google.example.Request", "Full type name for request, usually similar to gRPC name (ex. google.internal.people.v2.minimal.ListRankedTargetsRequest)")
// Use a custom flag for headers
var headers headerSliceFlag
flag.Var(&headers, "H", "Headers in format 'Key: Value' (can be used multiple times)")
flag.Parse()
logFile, _ := os.OpenFile("latest.log", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
defer logFile.Close()
consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout}
multi := zerolog.MultiLevelWriter(consoleWriter, logFile)
logger = zerolog.New(multi).With().Timestamp().Logger()
if *url == "" {
panic("no url supplied!")
}
*url = modifyAltParameter(*url)
headersMap := make(map[string]string, 20)
for _, i := range headers {
j := headerRe.Split(i, 2)
headersMap[j[0]] = j[1]
}
payload := genPayload(nil, "str")
s1, _, err := testAPI(*method, *url, headersMap, payload)
if err != nil {
logger.Fatal().Err(err)
}
payload = genPayload(nil, "int")
s2, r2, err := testAPI(*method, *url, headersMap, payload)
if err != nil {
logger.Fatal().Err(err)
}
if s1 != 400 && s2 != 400 {
logger.Fatal().Int("status", s2).Str("resp", string(r2)).Msg("unknown status code")
}
msgCh := make(chan MsgChData, 1000)
x := messageRe.FindStringSubmatch(*reqMessageName)
packageName := x[1]
messageName := x[2]
packageFDProtoMap[packageName] = &descriptorpb.FileDescriptorProto{
Name: proto.String(strings.Replace(packageName, ".", "/", -1) + "/message.proto"),
Syntax: proto.String("proto3"),
Package: proto.String(packageName),
MessageType: []*descriptorpb.DescriptorProto{
{
Name: proto.String(messageName),
Field: []*descriptorpb.FieldDescriptorProto{},
NestedType: []*descriptorpb.DescriptorProto{},
},
},
}
fdproto := packageFDProtoMap[packageName]
descProto := fdproto.MessageType[0]
// ParentDescProto is nil for initial
msgCh <- MsgChData{Package: packageName, Message: messageName, Index: []int{}, DescProto: descProto}
go monitorAndCloseChannel(msgCh)
probeNestedMessageWorker(msgCh, *method, *url, headersMap, *maxDepth, *verbose)
for p, fdproto := range packageFDProtoMap {
fdproto.Dependency = append(fdproto.Dependency, packageDependencyMap[p]...)
}
fileDescSet := &descriptorpb.FileDescriptorSet{}
processFileDescriptors(packageFDProtoMap)
for _, i := range packageFDProtoMap {
cleanupDuplicateFields(i, *verbose)
if *verbose {
text := prototext.Format(i)
logger.Debug().Msg(text)
}
fileDescSet.File = append(fileDescSet.File, i)
}
fileOptions := protodesc.FileOptions{AllowUnresolvable: true}
files := &protoregistry.Files{}
for _, fdProto := range fileDescSet.File {
descriptor, err := fileOptions.New(fdProto, files)
if err != nil {
log.Printf("Error creating FileDescriptor for %s: %v\n", *fdProto.Name, err)
continue
}
if err := files.RegisterFile(descriptor); err != nil {
log.Printf("Error registering file %s: %v\n", *fdProto.Name, err)
continue
}
fileContent := parser.GenerateProtoFile(descriptor)
fileName := *outputDir + "/" + *fdProto.Name
writeFile([]byte(fileContent), fileName)
if *verbose {
logger.Debug().Str("file", fileName).Msg("proto file generated successfully")
}
}
}