-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from daanbreur/vaf-configfile-base
WIP: Config parser
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 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,24 @@ | ||
import json | ||
import os | ||
import strutils | ||
|
||
import initVafConfig | ||
import parseVafConfig | ||
|
||
import VafConfigStructure | ||
|
||
var homeDir: string = os.getHomeDir() | ||
|
||
proc importVafConfig*(): VafConfigStructure = | ||
var configExists: bool = fileExists(homedir & "/.vaf.json") | ||
var configContents = readFile(homedir & "/.vaf.json") | ||
var jsonData: JsonNode | ||
|
||
|
||
if configExists: | ||
jsonData = parseJson(configContents) | ||
# else: | ||
# jsonData = initVafConfig() | ||
|
||
return parseVafConfig(jsonData) | ||
|
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,36 @@ | ||
import json | ||
import os | ||
import strutils | ||
|
||
import VafWordlist | ||
import VafConfigStructure | ||
|
||
proc parseWordlist(data: JsonNode): VafWordlist = | ||
var wordlistObject: VafWordlist = VafWordlist() | ||
|
||
if data{"Id"} != nil: | ||
wordlistObject.Id = data{"Id"}.getInt() | ||
|
||
if data{"Path"} != nil: | ||
wordlistObject.Path = data{"Path"}.getStr() | ||
|
||
return wordlistObject | ||
|
||
proc parseVafConfig*(data: JsonNode): VafConfigStructure = | ||
var configObject: VafConfigStructure = VafConfigStructure() | ||
|
||
echo data | ||
|
||
if data{"DefaultWordlist"} == nil: | ||
configObject.DefaultWordlist = -1 | ||
else: | ||
configObject.DefaultWordlist = data{"DefaultWordlist"}.getInt() | ||
|
||
if data{"Wordlists"} != nil: | ||
for wordlist in data{"Wordlists"}: | ||
configObject.Wordlists.add( parseWordlist( wordlist )) | ||
|
||
|
||
echo configObject | ||
|
||
return configObject |