-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/seipan/bluma/lib" | ||
) | ||
|
||
func ParseAndAttack(ctx context.Context, path string) error { | ||
oapi := lib.NewOpenAPI(path) | ||
paths, err := oapi.Parse(ctx) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse openapi: %w", err) | ||
} | ||
atks, err := ParthOpenAPItoAttacker(paths) | ||
if err != nil { | ||
return fmt.Errorf("failed to convert openapi to attacker: %w", err) | ||
} | ||
for _, atk := range atks { | ||
atk.Attack() | ||
} | ||
return nil | ||
} | ||
|
||
func ParthOpenAPItoAttacker(pathes []lib.Path) ([]lib.Attacker, error) { | ||
var res []lib.Attacker | ||
for i, path := range pathes { | ||
mtd := path.Method(i) | ||
body := mtd.Bodys() | ||
bodyjson, err := body[0].MarshalJSON() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal json: %w", err) | ||
} | ||
atk := lib.Attacker{ | ||
Path: path, | ||
MethodIndex: i, | ||
Body: bodyjson, | ||
} | ||
res = append(res, atk) | ||
} | ||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters