Skip to content

Commit

Permalink
docs: added cli text (#274)
Browse files Browse the repository at this point in the history
* added cli text
  • Loading branch information
noamd-legit authored Dec 10, 2023
1 parent 6ea81a7 commit 9ef7c2f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
13 changes: 12 additions & 1 deletion cmd/common_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Legit-Labs/legitify/internal/outputer/scheme"
"github.com/Legit-Labs/legitify/internal/outputer/scheme/converter"
"github.com/Legit-Labs/legitify/internal/screen"
"github.com/fatih/color"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -99,8 +100,18 @@ func (a *args) applyOutputOptions() (preExitHook func(), err error) {
if errlog.HadPermIssues() {
buf.WriteString(fmt.Sprintf("Some policies skipped. Check %s for more details\n", permFile.Name()))
}

lineStart := color.New(color.FgMagenta, color.Bold).Sprintf("--->")
legitify := color.New(color.FgMagenta, color.Bold).Sprintf("legitify")
legitifyMail := color.New(color.FgMagenta, color.Bold).Sprintf("[email protected]")

legitText := fmt.Sprintf("%s If you have any questions or you need assistance using %s,"+
" please don't hesitate REACHING OUT @ %s", lineStart, legitify, legitifyMail)

buf.WriteString(legitText)

if buf.Len() > 0 {
screen.Printf("\n\n%s", buf.String())
screen.Printf("\n\n%s\n", buf.String())
}
}, nil
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func Execute() {
if screen.IsTty() {
logoColored := color.New(color.FgMagenta, color.Bold).Sprintf("%s", logo)
brandColored := color.New(color.Bold).Sprintf("%s", brand)
screen.Printf("%s\nBy %s\n\n", logoColored, brandColored)
legitifyWebsite := color.New(color.FgMagenta, color.Bold).Sprintf("https://legitsecurity.com/legitify")
screen.Printf("%s\nBy %s - %s\n", logoColored, brandColored, legitifyWebsite)
screen.Printf(color.New(color.Bold).Sprintf("%s\n", GetVersionLean()))
}
err := rootCmd.Execute()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ var versionCmd = &cobra.Command{
func GetVersion() string {
return version.ReadableVersion
}

func GetVersionLean() string {
return version.ReadableVersionLean
}
2 changes: 2 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ var (
)

var ReadableVersion = fmt.Sprintf("%s version %s commit %s", Name, Version, Commit)

var ReadableVersionLean = fmt.Sprintf("Version: %s Commit %s", Version, Commit)
49 changes: 30 additions & 19 deletions scripts/gen-gh-pages-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HeaderSize(Enum):
H5 = 5
H6 = 6


def format_header(header_size: HeaderSize, text: str) -> str:
if not isinstance(header_size, HeaderSize):
raise ValueError("Invalid header size")
Expand All @@ -24,23 +25,29 @@ def format_header(header_size: HeaderSize, text: str) -> str:

return f"{'#' * header_size.value} {text}"


def scm_to_pretty_name(scm):
if scm == 'github': return 'GitHub'
return 'GitLab'
if scm == "github":
return "GitHub"
return "GitLab"


def get_docs_yaml(docs_file):
with open(docs_file) as f:
return yaml.load(f, Loader=yaml.FullLoader)


def gen_policy_markdown(policy):
policy_name = policy['policy_name']
title = policy['title']
description = policy['description']
severity = policy['severity']
remediation = policy['remediation']
threat = policy['threat']

remediation_string = "".join([f"{index+1}. {line}\n" for index, line in enumerate(remediation)])
policy_name = policy["policy_name"]
title = policy["title"]
description = policy["description"]
severity = policy["severity"]
remediation = policy["remediation"]
threat = policy["threat"]

remediation_string = "".join(
[f"{index+1}. {line}\n" for index, line in enumerate(remediation)]
)
remediation = f"""
{format_header(HeaderSize.H3, "Remediation")}
{remediation_string}
Expand All @@ -66,11 +73,12 @@ def gen_policy_markdown(policy):
{remediation}
"""


def create_policy_page(policy, output_dir, parent, grand_parent):
file_path = os.path.join(output_dir, f"{policy['policy_name']}.md")
md = gen_policy_markdown(policy)
title=policy['title']
final =f"""---
title = policy["title"]
final = f"""---
layout: default
title: {title}
parent: {parent}
Expand All @@ -79,56 +87,60 @@ def create_policy_page(policy, output_dir, parent, grand_parent):
{md}
"""
with open(file_path, 'w') as f:
with open(file_path, "w") as f:
f.write(final)


def create_ns_policies(output_dir, ns, docs_yaml, parent):
ns_dir = os.path.join(output_dir)
os.mkdir(ns_dir)
title = f"{ns.title()} Policies"

file_path = os.path.join(ns_dir, f"index.md")
file_header=f"""---
file_header = f"""---
layout: default
title: {title}
parent: {parent}
has_children: true
---
"""

with open(file_path, 'w') as f:
with open(file_path, "w") as f:
f.write(file_header)

for policy in docs_yaml[ns]:
create_policy_page(policy, ns_dir, title, parent)

return ns_dir


def create_scm_policy_docs(scm, docs_yaml, output_dir):
scm_outdir = os.path.join(output_dir, scm)
os.mkdir(scm_outdir)
file_path = os.path.join(scm_outdir, f"index.md")
title = f"{scm_to_pretty_name(scm)} Policies"
file_header=f"""---
file_header = f"""---
layout: default
title: {title}
has_children: true
---
"""

with open(file_path, 'w') as f:
with open(file_path, "w") as f:
f.write(file_header)

for ns in docs_yaml:
store_at = os.path.join(scm_outdir, ns)
create_ns_policies(store_at, ns, docs_yaml, title)


def create_policy_docs(docs_file, output_dir):
docs_yaml = get_docs_yaml(docs_file)

for scm in docs_yaml:
create_scm_policy_docs(scm, docs_yaml[scm], output_dir)


def create_monomarkdown(docs_file, output_dir):
table_of_contents = f"{format_header(HeaderSize.H1, 'Table of contents')}\n"

Expand Down Expand Up @@ -159,12 +171,11 @@ def create_monomarkdown(docs_file, output_dir):
f.write(result)



if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("docs_file", type=str, help="input file name")
parser.add_argument("output_dir", type=str, help="output directory")
parser.add_argument("--monomarkdown", action='store_true')
parser.add_argument("--monomarkdown", action="store_true")

args = parser.parse_args()

Expand Down

0 comments on commit 9ef7c2f

Please sign in to comment.