aidevops 2.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/.agent/AGENTS.md +614 -0
  2. package/.agent/accounts.md +65 -0
  3. package/.agent/aidevops/add-new-mcp-to-aidevops.md +456 -0
  4. package/.agent/aidevops/api-integrations.md +335 -0
  5. package/.agent/aidevops/architecture.md +510 -0
  6. package/.agent/aidevops/configs.md +274 -0
  7. package/.agent/aidevops/docs.md +244 -0
  8. package/.agent/aidevops/extension.md +311 -0
  9. package/.agent/aidevops/mcp-integrations.md +340 -0
  10. package/.agent/aidevops/mcp-troubleshooting.md +162 -0
  11. package/.agent/aidevops/memory-patterns.md +172 -0
  12. package/.agent/aidevops/providers.md +217 -0
  13. package/.agent/aidevops/recommendations.md +321 -0
  14. package/.agent/aidevops/requirements.md +301 -0
  15. package/.agent/aidevops/resources.md +214 -0
  16. package/.agent/aidevops/security-requirements.md +174 -0
  17. package/.agent/aidevops/security.md +350 -0
  18. package/.agent/aidevops/service-links.md +400 -0
  19. package/.agent/aidevops/services.md +357 -0
  20. package/.agent/aidevops/setup.md +153 -0
  21. package/.agent/aidevops/troubleshooting.md +389 -0
  22. package/.agent/aidevops.md +124 -0
  23. package/.agent/build-plus.md +244 -0
  24. package/.agent/content/guidelines.md +109 -0
  25. package/.agent/content.md +87 -0
  26. package/.agent/health.md +59 -0
  27. package/.agent/legal.md +59 -0
  28. package/.agent/loop-state/full-loop.local.md +16 -0
  29. package/.agent/loop-state/ralph-loop.local.md +10 -0
  30. package/.agent/marketing.md +440 -0
  31. package/.agent/memory/README.md +260 -0
  32. package/.agent/onboarding.md +796 -0
  33. package/.agent/plan-plus.md +245 -0
  34. package/.agent/research.md +100 -0
  35. package/.agent/sales.md +333 -0
  36. package/.agent/scripts/101domains-helper.sh +701 -0
  37. package/.agent/scripts/add-missing-returns.sh +140 -0
  38. package/.agent/scripts/agent-browser-helper.sh +311 -0
  39. package/.agent/scripts/agno-setup.sh +712 -0
  40. package/.agent/scripts/ahrefs-mcp-wrapper.js +168 -0
  41. package/.agent/scripts/aidevops-update-check.sh +71 -0
  42. package/.agent/scripts/ampcode-cli.sh +522 -0
  43. package/.agent/scripts/auto-version-bump.sh +156 -0
  44. package/.agent/scripts/autogen-helper.sh +512 -0
  45. package/.agent/scripts/beads-sync-helper.sh +596 -0
  46. package/.agent/scripts/closte-helper.sh +5 -0
  47. package/.agent/scripts/cloudron-helper.sh +321 -0
  48. package/.agent/scripts/codacy-cli-chunked.sh +581 -0
  49. package/.agent/scripts/codacy-cli.sh +442 -0
  50. package/.agent/scripts/code-audit-helper.sh +5 -0
  51. package/.agent/scripts/coderabbit-cli.sh +417 -0
  52. package/.agent/scripts/coderabbit-pro-analysis.sh +238 -0
  53. package/.agent/scripts/commands/code-simplifier.md +86 -0
  54. package/.agent/scripts/commands/full-loop.md +246 -0
  55. package/.agent/scripts/commands/postflight-loop.md +103 -0
  56. package/.agent/scripts/commands/recall.md +182 -0
  57. package/.agent/scripts/commands/remember.md +132 -0
  58. package/.agent/scripts/commands/save-todo.md +175 -0
  59. package/.agent/scripts/commands/session-review.md +154 -0
  60. package/.agent/scripts/comprehensive-quality-fix.sh +106 -0
  61. package/.agent/scripts/context-builder-helper.sh +522 -0
  62. package/.agent/scripts/coolify-cli-helper.sh +674 -0
  63. package/.agent/scripts/coolify-helper.sh +380 -0
  64. package/.agent/scripts/crawl4ai-examples.sh +401 -0
  65. package/.agent/scripts/crawl4ai-helper.sh +1078 -0
  66. package/.agent/scripts/crewai-helper.sh +681 -0
  67. package/.agent/scripts/dev-browser-helper.sh +513 -0
  68. package/.agent/scripts/dns-helper.sh +396 -0
  69. package/.agent/scripts/domain-research-helper.sh +917 -0
  70. package/.agent/scripts/dspy-helper.sh +285 -0
  71. package/.agent/scripts/dspyground-helper.sh +291 -0
  72. package/.agent/scripts/eeat-score-helper.sh +1242 -0
  73. package/.agent/scripts/efficient-return-fix.sh +92 -0
  74. package/.agent/scripts/extract-opencode-prompts.sh +128 -0
  75. package/.agent/scripts/find-missing-returns.sh +113 -0
  76. package/.agent/scripts/fix-auth-headers.sh +104 -0
  77. package/.agent/scripts/fix-common-strings.sh +254 -0
  78. package/.agent/scripts/fix-content-type.sh +100 -0
  79. package/.agent/scripts/fix-error-messages.sh +130 -0
  80. package/.agent/scripts/fix-misplaced-returns.sh +74 -0
  81. package/.agent/scripts/fix-remaining-literals.sh +152 -0
  82. package/.agent/scripts/fix-return-statements.sh +41 -0
  83. package/.agent/scripts/fix-s131-default-cases.sh +249 -0
  84. package/.agent/scripts/fix-sc2155-simple.sh +102 -0
  85. package/.agent/scripts/fix-shellcheck-critical.sh +187 -0
  86. package/.agent/scripts/fix-string-literals.sh +273 -0
  87. package/.agent/scripts/full-loop-helper.sh +773 -0
  88. package/.agent/scripts/generate-opencode-agents.sh +497 -0
  89. package/.agent/scripts/generate-opencode-commands.sh +1629 -0
  90. package/.agent/scripts/generate-skills.sh +366 -0
  91. package/.agent/scripts/git-platforms-helper.sh +640 -0
  92. package/.agent/scripts/gitea-cli-helper.sh +743 -0
  93. package/.agent/scripts/github-cli-helper.sh +702 -0
  94. package/.agent/scripts/gitlab-cli-helper.sh +682 -0
  95. package/.agent/scripts/gsc-add-user-helper.sh +325 -0
  96. package/.agent/scripts/gsc-sitemap-helper.sh +678 -0
  97. package/.agent/scripts/hetzner-helper.sh +485 -0
  98. package/.agent/scripts/hostinger-helper.sh +229 -0
  99. package/.agent/scripts/keyword-research-helper.sh +1815 -0
  100. package/.agent/scripts/langflow-helper.sh +544 -0
  101. package/.agent/scripts/linkedin-automation.py +241 -0
  102. package/.agent/scripts/linter-manager.sh +599 -0
  103. package/.agent/scripts/linters-local.sh +434 -0
  104. package/.agent/scripts/list-keys-helper.sh +488 -0
  105. package/.agent/scripts/local-browser-automation.py +339 -0
  106. package/.agent/scripts/localhost-helper.sh +744 -0
  107. package/.agent/scripts/loop-common.sh +806 -0
  108. package/.agent/scripts/mainwp-helper.sh +728 -0
  109. package/.agent/scripts/markdown-formatter.sh +338 -0
  110. package/.agent/scripts/markdown-lint-fix.sh +311 -0
  111. package/.agent/scripts/mass-fix-returns.sh +58 -0
  112. package/.agent/scripts/mcp-diagnose.sh +167 -0
  113. package/.agent/scripts/mcp-inspector-helper.sh +449 -0
  114. package/.agent/scripts/memory-helper.sh +650 -0
  115. package/.agent/scripts/monitor-code-review.sh +255 -0
  116. package/.agent/scripts/onboarding-helper.sh +706 -0
  117. package/.agent/scripts/opencode-github-setup-helper.sh +797 -0
  118. package/.agent/scripts/opencode-test-helper.sh +213 -0
  119. package/.agent/scripts/pagespeed-helper.sh +464 -0
  120. package/.agent/scripts/pandoc-helper.sh +362 -0
  121. package/.agent/scripts/postflight-check.sh +555 -0
  122. package/.agent/scripts/pre-commit-hook.sh +259 -0
  123. package/.agent/scripts/pre-edit-check.sh +169 -0
  124. package/.agent/scripts/qlty-cli.sh +356 -0
  125. package/.agent/scripts/quality-cli-manager.sh +525 -0
  126. package/.agent/scripts/quality-feedback-helper.sh +462 -0
  127. package/.agent/scripts/quality-fix.sh +263 -0
  128. package/.agent/scripts/quality-loop-helper.sh +1108 -0
  129. package/.agent/scripts/ralph-loop-helper.sh +836 -0
  130. package/.agent/scripts/ralph-upstream-check.sh +341 -0
  131. package/.agent/scripts/secretlint-helper.sh +847 -0
  132. package/.agent/scripts/servers-helper.sh +241 -0
  133. package/.agent/scripts/ses-helper.sh +619 -0
  134. package/.agent/scripts/session-review-helper.sh +404 -0
  135. package/.agent/scripts/setup-linters-wizard.sh +379 -0
  136. package/.agent/scripts/setup-local-api-keys.sh +330 -0
  137. package/.agent/scripts/setup-mcp-integrations.sh +472 -0
  138. package/.agent/scripts/shared-constants.sh +246 -0
  139. package/.agent/scripts/site-crawler-helper.sh +1487 -0
  140. package/.agent/scripts/snyk-helper.sh +940 -0
  141. package/.agent/scripts/sonarcloud-autofix.sh +193 -0
  142. package/.agent/scripts/sonarcloud-cli.sh +191 -0
  143. package/.agent/scripts/sonarscanner-cli.sh +455 -0
  144. package/.agent/scripts/spaceship-helper.sh +747 -0
  145. package/.agent/scripts/stagehand-helper.sh +321 -0
  146. package/.agent/scripts/stagehand-python-helper.sh +321 -0
  147. package/.agent/scripts/stagehand-python-setup.sh +441 -0
  148. package/.agent/scripts/stagehand-setup.sh +439 -0
  149. package/.agent/scripts/system-cleanup.sh +340 -0
  150. package/.agent/scripts/terminal-title-helper.sh +388 -0
  151. package/.agent/scripts/terminal-title-setup.sh +549 -0
  152. package/.agent/scripts/test-stagehand-both-integration.sh +317 -0
  153. package/.agent/scripts/test-stagehand-integration.sh +309 -0
  154. package/.agent/scripts/test-stagehand-python-integration.sh +341 -0
  155. package/.agent/scripts/todo-ready.sh +263 -0
  156. package/.agent/scripts/tool-version-check.sh +362 -0
  157. package/.agent/scripts/toon-helper.sh +469 -0
  158. package/.agent/scripts/twilio-helper.sh +917 -0
  159. package/.agent/scripts/updown-helper.sh +279 -0
  160. package/.agent/scripts/validate-mcp-integrations.sh +250 -0
  161. package/.agent/scripts/validate-version-consistency.sh +131 -0
  162. package/.agent/scripts/vaultwarden-helper.sh +597 -0
  163. package/.agent/scripts/vercel-cli-helper.sh +816 -0
  164. package/.agent/scripts/verify-mirrors.sh +169 -0
  165. package/.agent/scripts/version-manager.sh +831 -0
  166. package/.agent/scripts/webhosting-helper.sh +471 -0
  167. package/.agent/scripts/webhosting-verify.sh +238 -0
  168. package/.agent/scripts/wordpress-mcp-helper.sh +508 -0
  169. package/.agent/scripts/worktree-helper.sh +595 -0
  170. package/.agent/scripts/worktree-sessions.sh +577 -0
  171. package/.agent/seo/dataforseo.md +215 -0
  172. package/.agent/seo/domain-research.md +532 -0
  173. package/.agent/seo/eeat-score.md +659 -0
  174. package/.agent/seo/google-search-console.md +366 -0
  175. package/.agent/seo/gsc-sitemaps.md +282 -0
  176. package/.agent/seo/keyword-research.md +521 -0
  177. package/.agent/seo/serper.md +278 -0
  178. package/.agent/seo/site-crawler.md +387 -0
  179. package/.agent/seo.md +236 -0
  180. package/.agent/services/accounting/quickfile.md +159 -0
  181. package/.agent/services/communications/telfon.md +470 -0
  182. package/.agent/services/communications/twilio.md +569 -0
  183. package/.agent/services/crm/fluentcrm.md +449 -0
  184. package/.agent/services/email/ses.md +399 -0
  185. package/.agent/services/hosting/101domains.md +378 -0
  186. package/.agent/services/hosting/closte.md +177 -0
  187. package/.agent/services/hosting/cloudflare.md +251 -0
  188. package/.agent/services/hosting/cloudron.md +478 -0
  189. package/.agent/services/hosting/dns-providers.md +335 -0
  190. package/.agent/services/hosting/domain-purchasing.md +344 -0
  191. package/.agent/services/hosting/hetzner.md +327 -0
  192. package/.agent/services/hosting/hostinger.md +287 -0
  193. package/.agent/services/hosting/localhost.md +419 -0
  194. package/.agent/services/hosting/spaceship.md +353 -0
  195. package/.agent/services/hosting/webhosting.md +330 -0
  196. package/.agent/social-media.md +69 -0
  197. package/.agent/templates/plans-template.md +114 -0
  198. package/.agent/templates/prd-template.md +129 -0
  199. package/.agent/templates/tasks-template.md +108 -0
  200. package/.agent/templates/todo-template.md +89 -0
  201. package/.agent/tools/ai-assistants/agno.md +471 -0
  202. package/.agent/tools/ai-assistants/capsolver.md +326 -0
  203. package/.agent/tools/ai-assistants/configuration.md +221 -0
  204. package/.agent/tools/ai-assistants/overview.md +209 -0
  205. package/.agent/tools/ai-assistants/status.md +171 -0
  206. package/.agent/tools/ai-assistants/windsurf.md +193 -0
  207. package/.agent/tools/ai-orchestration/autogen.md +406 -0
  208. package/.agent/tools/ai-orchestration/crewai.md +445 -0
  209. package/.agent/tools/ai-orchestration/langflow.md +405 -0
  210. package/.agent/tools/ai-orchestration/openprose.md +487 -0
  211. package/.agent/tools/ai-orchestration/overview.md +362 -0
  212. package/.agent/tools/ai-orchestration/packaging.md +647 -0
  213. package/.agent/tools/browser/agent-browser.md +464 -0
  214. package/.agent/tools/browser/browser-automation.md +400 -0
  215. package/.agent/tools/browser/chrome-devtools.md +282 -0
  216. package/.agent/tools/browser/crawl4ai-integration.md +422 -0
  217. package/.agent/tools/browser/crawl4ai-resources.md +277 -0
  218. package/.agent/tools/browser/crawl4ai-usage.md +416 -0
  219. package/.agent/tools/browser/crawl4ai.md +585 -0
  220. package/.agent/tools/browser/dev-browser.md +341 -0
  221. package/.agent/tools/browser/pagespeed.md +260 -0
  222. package/.agent/tools/browser/playwright.md +266 -0
  223. package/.agent/tools/browser/playwriter.md +310 -0
  224. package/.agent/tools/browser/stagehand-examples.md +456 -0
  225. package/.agent/tools/browser/stagehand-python.md +483 -0
  226. package/.agent/tools/browser/stagehand.md +421 -0
  227. package/.agent/tools/build-agent/agent-review.md +224 -0
  228. package/.agent/tools/build-agent/build-agent.md +784 -0
  229. package/.agent/tools/build-mcp/aidevops-plugin.md +476 -0
  230. package/.agent/tools/build-mcp/api-wrapper.md +445 -0
  231. package/.agent/tools/build-mcp/build-mcp.md +240 -0
  232. package/.agent/tools/build-mcp/deployment.md +401 -0
  233. package/.agent/tools/build-mcp/server-patterns.md +632 -0
  234. package/.agent/tools/build-mcp/transports.md +366 -0
  235. package/.agent/tools/code-review/auditing.md +383 -0
  236. package/.agent/tools/code-review/automation.md +219 -0
  237. package/.agent/tools/code-review/best-practices.md +203 -0
  238. package/.agent/tools/code-review/codacy.md +151 -0
  239. package/.agent/tools/code-review/code-simplifier.md +174 -0
  240. package/.agent/tools/code-review/code-standards.md +309 -0
  241. package/.agent/tools/code-review/coderabbit.md +101 -0
  242. package/.agent/tools/code-review/management.md +155 -0
  243. package/.agent/tools/code-review/qlty.md +248 -0
  244. package/.agent/tools/code-review/secretlint.md +565 -0
  245. package/.agent/tools/code-review/setup.md +250 -0
  246. package/.agent/tools/code-review/snyk.md +563 -0
  247. package/.agent/tools/code-review/tools.md +230 -0
  248. package/.agent/tools/content/summarize.md +353 -0
  249. package/.agent/tools/context/augment-context-engine.md +468 -0
  250. package/.agent/tools/context/context-builder-agent.md +76 -0
  251. package/.agent/tools/context/context-builder.md +375 -0
  252. package/.agent/tools/context/context7.md +371 -0
  253. package/.agent/tools/context/dspy.md +302 -0
  254. package/.agent/tools/context/dspyground.md +374 -0
  255. package/.agent/tools/context/llm-tldr.md +219 -0
  256. package/.agent/tools/context/osgrep.md +488 -0
  257. package/.agent/tools/context/prompt-optimization.md +338 -0
  258. package/.agent/tools/context/toon.md +292 -0
  259. package/.agent/tools/conversion/pandoc.md +304 -0
  260. package/.agent/tools/credentials/api-key-management.md +154 -0
  261. package/.agent/tools/credentials/api-key-setup.md +224 -0
  262. package/.agent/tools/credentials/environment-variables.md +180 -0
  263. package/.agent/tools/credentials/vaultwarden.md +382 -0
  264. package/.agent/tools/data-extraction/outscraper.md +974 -0
  265. package/.agent/tools/deployment/coolify-cli.md +388 -0
  266. package/.agent/tools/deployment/coolify-setup.md +353 -0
  267. package/.agent/tools/deployment/coolify.md +345 -0
  268. package/.agent/tools/deployment/vercel.md +390 -0
  269. package/.agent/tools/git/authentication.md +132 -0
  270. package/.agent/tools/git/gitea-cli.md +193 -0
  271. package/.agent/tools/git/github-actions.md +207 -0
  272. package/.agent/tools/git/github-cli.md +223 -0
  273. package/.agent/tools/git/gitlab-cli.md +190 -0
  274. package/.agent/tools/git/opencode-github-security.md +350 -0
  275. package/.agent/tools/git/opencode-github.md +328 -0
  276. package/.agent/tools/git/opencode-gitlab.md +252 -0
  277. package/.agent/tools/git/security.md +196 -0
  278. package/.agent/tools/git.md +207 -0
  279. package/.agent/tools/opencode/oh-my-opencode.md +375 -0
  280. package/.agent/tools/opencode/opencode-anthropic-auth.md +446 -0
  281. package/.agent/tools/opencode/opencode.md +651 -0
  282. package/.agent/tools/social-media/bird.md +437 -0
  283. package/.agent/tools/task-management/beads.md +336 -0
  284. package/.agent/tools/terminal/terminal-title.md +251 -0
  285. package/.agent/tools/ui/shadcn.md +196 -0
  286. package/.agent/tools/ui/ui-skills.md +115 -0
  287. package/.agent/tools/wordpress/localwp.md +311 -0
  288. package/.agent/tools/wordpress/mainwp.md +391 -0
  289. package/.agent/tools/wordpress/scf.md +527 -0
  290. package/.agent/tools/wordpress/wp-admin.md +729 -0
  291. package/.agent/tools/wordpress/wp-dev.md +940 -0
  292. package/.agent/tools/wordpress/wp-preferred.md +398 -0
  293. package/.agent/tools/wordpress.md +95 -0
  294. package/.agent/workflows/branch/bugfix.md +63 -0
  295. package/.agent/workflows/branch/chore.md +95 -0
  296. package/.agent/workflows/branch/experiment.md +115 -0
  297. package/.agent/workflows/branch/feature.md +59 -0
  298. package/.agent/workflows/branch/hotfix.md +98 -0
  299. package/.agent/workflows/branch/refactor.md +92 -0
  300. package/.agent/workflows/branch/release.md +96 -0
  301. package/.agent/workflows/branch.md +347 -0
  302. package/.agent/workflows/bug-fixing.md +267 -0
  303. package/.agent/workflows/changelog.md +129 -0
  304. package/.agent/workflows/code-audit-remote.md +279 -0
  305. package/.agent/workflows/conversation-starter.md +69 -0
  306. package/.agent/workflows/error-feedback.md +578 -0
  307. package/.agent/workflows/feature-development.md +355 -0
  308. package/.agent/workflows/git-workflow.md +702 -0
  309. package/.agent/workflows/multi-repo-workspace.md +268 -0
  310. package/.agent/workflows/plans.md +709 -0
  311. package/.agent/workflows/postflight.md +604 -0
  312. package/.agent/workflows/pr.md +571 -0
  313. package/.agent/workflows/preflight.md +278 -0
  314. package/.agent/workflows/ralph-loop.md +773 -0
  315. package/.agent/workflows/release.md +498 -0
  316. package/.agent/workflows/session-manager.md +254 -0
  317. package/.agent/workflows/session-review.md +311 -0
  318. package/.agent/workflows/sql-migrations.md +631 -0
  319. package/.agent/workflows/version-bump.md +283 -0
  320. package/.agent/workflows/wiki-update.md +333 -0
  321. package/.agent/workflows/worktree.md +477 -0
  322. package/LICENSE +21 -0
  323. package/README.md +1446 -0
  324. package/VERSION +1 -0
  325. package/aidevops.sh +1746 -0
  326. package/bin/aidevops +21 -0
  327. package/package.json +75 -0
  328. package/scripts/npm-postinstall.js +60 -0
  329. package/setup.sh +2366 -0
@@ -0,0 +1,940 @@
1
+ #!/bin/bash
2
+ # shellcheck disable=SC2034,SC2155,SC2317,SC2329,SC2016,SC2181,SC1091,SC2154,SC2015,SC2086,SC2129,SC2030,SC2031,SC2119,SC2120,SC2001,SC2162,SC2088,SC2089,SC2090,SC2029,SC2006,SC2153
3
+
4
+ # Snyk Security Helper Script
5
+ # Comprehensive security scanning using Snyk CLI
6
+ # Managed by AI DevOps Framework
7
+ #
8
+ # Usage: ./snyk-helper.sh [command] [options]
9
+ # Commands:
10
+ # test - Run dependency vulnerability scan (SCA)
11
+ # code - Run source code security scan (SAST)
12
+ # container - Scan container images for vulnerabilities
13
+ # iac - Scan Infrastructure as Code files
14
+ # monitor - Create project snapshot for continuous monitoring
15
+ # sbom - Generate Software Bill of Materials
16
+ # auth - Authenticate with Snyk
17
+ # status - Check authentication and installation status
18
+ # accounts - List configured organizations
19
+ # install - Install Snyk CLI
20
+ # help - Show this help message
21
+ #
22
+ # Author: AI DevOps Framework
23
+ # Version: 1.0.0
24
+ # License: MIT
25
+
26
+ # Set strict mode
27
+ set -euo pipefail
28
+
29
+ # ------------------------------------------------------------------------------
30
+ # CONFIGURATION & CONSTANTS
31
+ # ------------------------------------------------------------------------------
32
+
33
+ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
34
+ readonly SCRIPT_DIR="$script_dir"
35
+
36
+ repo_root="$(dirname "$SCRIPT_DIR")"
37
+ readonly REPO_ROOT="$repo_root"
38
+ readonly CONFIG_FILE="$REPO_ROOT/configs/snyk-config.json"
39
+
40
+ # Colors
41
+ readonly BLUE='\033[0;34m'
42
+ readonly GREEN='\033[0;32m'
43
+ readonly YELLOW='\033[1;33m'
44
+ readonly RED='\033[0;31m'
45
+ readonly PURPLE='\033[0;35m'
46
+ readonly NC='\033[0m'
47
+
48
+ # Common constants
49
+ readonly ERROR_UNKNOWN_COMMAND="Unknown command:"
50
+ # Error Messages
51
+ readonly ERROR_SNYK_NOT_INSTALLED="Snyk CLI is required but not installed"
52
+ readonly ERROR_NOT_AUTHENTICATED="Snyk CLI is not authenticated. Run 'snyk auth' or set SNYK_TOKEN"
53
+ readonly ERROR_CONFIG_MISSING="Configuration file not found"
54
+ readonly ERROR_ORG_NOT_FOUND="Organization not found in configuration"
55
+ readonly ERROR_SCAN_FAILED="Snyk scan failed"
56
+ readonly ERROR_ARGS_MISSING="Missing required arguments"
57
+ readonly ERROR_TARGET_REQUIRED="Target path or image is required"
58
+ readonly ERROR_FILE_NOT_FOUND="File or directory not found"
59
+
60
+ # Success Messages
61
+ readonly SUCCESS_SCAN_COMPLETE="Scan completed successfully"
62
+ readonly SUCCESS_MONITOR_CREATED="Project snapshot created for monitoring"
63
+ readonly SUCCESS_AUTH_COMPLETE="Authentication successful"
64
+ readonly SUCCESS_INSTALL_COMPLETE="Snyk CLI installed successfully"
65
+
66
+ # API Configuration (exported for external use)
67
+ export SNYK_API_BASE="https://api.snyk.io"
68
+
69
+ # ------------------------------------------------------------------------------
70
+ # UTILITY FUNCTIONS
71
+ # ------------------------------------------------------------------------------
72
+
73
+ print_info() {
74
+ local msg="$1"
75
+ echo -e "${BLUE}[INFO]${NC} $msg"
76
+ return 0
77
+ }
78
+
79
+ print_success() {
80
+ local msg="$1"
81
+ echo -e "${GREEN}[SUCCESS]${NC} $msg"
82
+ return 0
83
+ }
84
+
85
+ print_warning() {
86
+ local msg="$1"
87
+ echo -e "${YELLOW}[WARNING]${NC} $msg"
88
+ return 0
89
+ }
90
+
91
+ print_error() {
92
+ local msg="$1"
93
+ echo -e "${RED}[ERROR]${NC} $msg" >&2
94
+ return 0
95
+ }
96
+
97
+ print_header() {
98
+ local msg="$1"
99
+ echo -e "${PURPLE}🔒 $msg${NC}"
100
+ return 0
101
+ }
102
+
103
+ # ------------------------------------------------------------------------------
104
+ # DEPENDENCY CHECKING
105
+ # ------------------------------------------------------------------------------
106
+
107
+ check_snyk_installed() {
108
+ if ! command -v snyk &> /dev/null; then
109
+ return 1
110
+ fi
111
+ return 0
112
+ }
113
+
114
+ check_snyk_authenticated() {
115
+ # Check if SNYK_TOKEN is set or if already authenticated
116
+ if [[ -n "${SNYK_TOKEN:-}" ]]; then
117
+ return 0
118
+ fi
119
+
120
+ # Check if authenticated via snyk auth
121
+ if snyk auth check &> /dev/null 2>&1; then
122
+ return 0
123
+ fi
124
+
125
+ # Try a simple API call to verify authentication
126
+ if snyk config get api &> /dev/null 2>&1; then
127
+ return 0
128
+ fi
129
+
130
+ return 1
131
+ }
132
+
133
+ check_dependencies() {
134
+ if ! check_snyk_installed; then
135
+ print_error "$ERROR_SNYK_NOT_INSTALLED"
136
+ print_info "Install Snyk CLI:"
137
+ print_info " macOS: brew tap snyk/tap && brew install snyk-cli"
138
+ print_info " npm: npm install -g snyk"
139
+ print_info " Binary: curl --compressed https://downloads.snyk.io/cli/stable/snyk-macos -o snyk && chmod +x snyk"
140
+ return 1
141
+ fi
142
+ return 0
143
+ }
144
+
145
+ # ------------------------------------------------------------------------------
146
+ # CONFIGURATION LOADING
147
+ # ------------------------------------------------------------------------------
148
+
149
+ load_config() {
150
+ if [[ ! -f "$CONFIG_FILE" ]]; then
151
+ return 1
152
+ fi
153
+ return 0
154
+ }
155
+
156
+ get_org_config() {
157
+ local org_name="$1"
158
+
159
+ if [[ -z "$org_name" ]]; then
160
+ print_error "$ERROR_ARGS_MISSING"
161
+ return 1
162
+ fi
163
+
164
+ if ! load_config; then
165
+ print_warning "$ERROR_CONFIG_MISSING - using defaults"
166
+ echo "{}"
167
+ return 0
168
+ fi
169
+
170
+ local config
171
+ if ! config=$(jq -r ".organizations.\"$org_name\"" "$CONFIG_FILE" 2>/dev/null); then
172
+ print_warning "Failed to read configuration for $org_name"
173
+ echo "{}"
174
+ return 0
175
+ fi
176
+
177
+ if [[ "$config" == "null" ]]; then
178
+ print_warning "$ERROR_ORG_NOT_FOUND: $org_name"
179
+ echo "{}"
180
+ return 0
181
+ fi
182
+
183
+ echo "$config"
184
+ return 0
185
+ }
186
+
187
+ get_default_options() {
188
+ if ! load_config; then
189
+ echo ""
190
+ return 0
191
+ fi
192
+
193
+ local severity_threshold
194
+ severity_threshold=$(jq -r '.defaults.severity_threshold // "high"' "$CONFIG_FILE" 2>/dev/null)
195
+
196
+ echo "--severity-threshold=$severity_threshold"
197
+ return 0
198
+ }
199
+
200
+ # ------------------------------------------------------------------------------
201
+ # INSTALLATION
202
+ # ------------------------------------------------------------------------------
203
+
204
+ install_snyk() {
205
+ print_header "Installing Snyk CLI"
206
+
207
+ local os_type
208
+ os_type=$(uname -s | tr '[:upper:]' '[:lower:]')
209
+
210
+ case "$os_type" in
211
+ "darwin")
212
+ print_info "Detected macOS - installing via Homebrew..."
213
+ if command -v brew &> /dev/null; then
214
+ brew tap snyk/tap 2>/dev/null || true
215
+ if brew install snyk-cli; then
216
+ print_success "$SUCCESS_INSTALL_COMPLETE"
217
+ return 0
218
+ fi
219
+ fi
220
+ print_warning "Homebrew installation failed, trying npm..."
221
+ # NOSONAR - merged nested if: check npm exists AND try install
222
+ if command -v npm &> /dev/null && npm install -g snyk; then
223
+ print_success "$SUCCESS_INSTALL_COMPLETE"
224
+ return 0
225
+ fi
226
+ print_info "Downloading binary directly..."
227
+ curl --compressed https://downloads.snyk.io/cli/stable/snyk-macos -o /usr/local/bin/snyk
228
+ chmod +x /usr/local/bin/snyk
229
+ ;;
230
+ "linux")
231
+ print_info "Detected Linux - installing via npm or binary..."
232
+ # NOSONAR - npm scripts required for CLI binary installation
233
+ if command -v npm &> /dev/null && npm install -g snyk; then
234
+ print_success "$SUCCESS_INSTALL_COMPLETE"
235
+ return 0
236
+ fi
237
+ print_info "Downloading binary directly..."
238
+ curl --compressed https://downloads.snyk.io/cli/stable/snyk-linux -o /usr/local/bin/snyk
239
+ chmod +x /usr/local/bin/snyk
240
+ ;;
241
+ *)
242
+ print_error "Unsupported OS: $os_type"
243
+ print_info "Please install manually: https://docs.snyk.io/snyk-cli/install-the-snyk-cli"
244
+ return 1
245
+ ;;
246
+ esac
247
+
248
+ if check_snyk_installed; then
249
+ print_success "$SUCCESS_INSTALL_COMPLETE"
250
+ snyk --version
251
+ return 0
252
+ else
253
+ print_error "Installation failed"
254
+ return 1
255
+ fi
256
+ return 0
257
+ }
258
+
259
+ # ------------------------------------------------------------------------------
260
+ # AUTHENTICATION
261
+ # ------------------------------------------------------------------------------
262
+
263
+ authenticate() {
264
+ local token="${1:-}"
265
+
266
+ print_header "Authenticating with Snyk"
267
+
268
+ if [[ -n "$token" ]]; then
269
+ print_info "Setting API token from argument..."
270
+ export SNYK_TOKEN="$token"
271
+ if snyk config set api="$token"; then
272
+ print_success "$SUCCESS_AUTH_COMPLETE"
273
+ return 0
274
+ fi
275
+ fi
276
+
277
+ # Check if SNYK_TOKEN environment variable is set
278
+ if [[ -n "${SNYK_TOKEN:-}" ]]; then
279
+ print_info "Using SNYK_TOKEN environment variable..."
280
+ if snyk config set api="$SNYK_TOKEN"; then
281
+ print_success "$SUCCESS_AUTH_COMPLETE"
282
+ return 0
283
+ fi
284
+ fi
285
+
286
+ # Interactive OAuth authentication
287
+ print_info "Starting OAuth authentication flow..."
288
+ print_info "A browser window will open for authentication."
289
+
290
+ if snyk auth; then
291
+ print_success "$SUCCESS_AUTH_COMPLETE"
292
+ return 0
293
+ else
294
+ print_error "Authentication failed"
295
+ print_info "Get your API token from: https://app.snyk.io/account"
296
+ return 1
297
+ fi
298
+ return 0
299
+ }
300
+
301
+ # ------------------------------------------------------------------------------
302
+ # STATUS & INFORMATION
303
+ # ------------------------------------------------------------------------------
304
+
305
+ show_status() {
306
+ print_header "Snyk CLI Status"
307
+
308
+ echo ""
309
+ echo "Installation:"
310
+ if check_snyk_installed; then
311
+ local version
312
+ version=$(snyk --version 2>/dev/null || echo "unknown")
313
+ echo " ✅ Snyk CLI installed: $version"
314
+ else
315
+ echo " ❌ Snyk CLI not installed"
316
+ return 1
317
+ fi
318
+
319
+ echo ""
320
+ echo "Authentication:"
321
+ if check_snyk_authenticated; then
322
+ echo " ✅ Authenticated with Snyk"
323
+ # Try to get organization info
324
+ if [[ -n "${SNYK_TOKEN:-}" ]]; then
325
+ echo " 📋 Using SNYK_TOKEN environment variable"
326
+ fi
327
+ local configured_api
328
+ configured_api=$(snyk config get api 2>/dev/null || echo "")
329
+ if [[ -n "$configured_api" && "$configured_api" != "null" ]]; then
330
+ echo " 📋 API token configured"
331
+ fi
332
+ else
333
+ echo " ❌ Not authenticated"
334
+ echo " 💡 Run 'snyk auth' or set SNYK_TOKEN environment variable"
335
+ fi
336
+
337
+ echo ""
338
+ echo "Configuration:"
339
+ if [[ -f "$CONFIG_FILE" ]]; then
340
+ echo " ✅ Configuration file found: $CONFIG_FILE"
341
+ local orgs
342
+ orgs=$(jq -r '.organizations | keys | join(", ")' "$CONFIG_FILE" 2>/dev/null || echo "none")
343
+ echo " 📋 Configured organizations: $orgs"
344
+ else
345
+ echo " ⚠️ No configuration file found"
346
+ echo " 💡 Create: cp configs/snyk-config.json.txt configs/snyk-config.json"
347
+ fi
348
+
349
+ echo ""
350
+ echo "Scan Capabilities:"
351
+ echo " 🔍 Open Source (SCA): snyk test"
352
+ echo " 🔍 Code (SAST): snyk code test"
353
+ echo " 🐳 Container: snyk container test"
354
+ echo " 📄 IaC: snyk iac test"
355
+ echo " 🤖 MCP Server: snyk mcp"
356
+
357
+ return 0
358
+ }
359
+
360
+ list_accounts() {
361
+ print_header "Configured Snyk Organizations"
362
+
363
+ if [[ -f "$CONFIG_FILE" ]]; then
364
+ echo ""
365
+ jq -r '.organizations | to_entries[] | " \(.key): \(.value.org_id // "no org_id")"' "$CONFIG_FILE" 2>/dev/null || print_warning "No organizations configured"
366
+ else
367
+ print_warning "$ERROR_CONFIG_MISSING"
368
+ print_info "Create configuration: cp configs/snyk-config.json.txt configs/snyk-config.json"
369
+ fi
370
+ return 0
371
+ }
372
+
373
+ # ------------------------------------------------------------------------------
374
+ # VULNERABILITY SCANNING
375
+ # ------------------------------------------------------------------------------
376
+
377
+ scan_dependencies() {
378
+ local target="${1:-.}"
379
+ local org_name="${2:-}"
380
+ local extra_args="${3:-}"
381
+
382
+ print_header "Running Dependency Vulnerability Scan (SCA)"
383
+
384
+ if ! check_snyk_authenticated; then
385
+ print_error "$ERROR_NOT_AUTHENTICATED"
386
+ return 1
387
+ fi
388
+
389
+ local snyk_args=()
390
+
391
+ # Add organization if specified
392
+ if [[ -n "$org_name" ]]; then
393
+ local config
394
+ config=$(get_org_config "$org_name")
395
+ local org_id
396
+ org_id=$(echo "$config" | jq -r '.org_id // ""')
397
+ if [[ -n "$org_id" && "$org_id" != "null" ]]; then
398
+ snyk_args+=("--org=$org_id")
399
+ fi
400
+ fi
401
+
402
+ # Add default options
403
+ local defaults
404
+ defaults=$(get_default_options)
405
+ if [[ -n "$defaults" ]]; then
406
+ # shellcheck disable=SC2206
407
+ snyk_args+=($defaults)
408
+ fi
409
+
410
+ # Add extra arguments
411
+ if [[ -n "$extra_args" ]]; then
412
+ # shellcheck disable=SC2206
413
+ snyk_args+=($extra_args)
414
+ fi
415
+
416
+ print_info "Scanning: $target"
417
+ print_info "Options: ${snyk_args[*]:-none}"
418
+
419
+ if [[ "$target" != "." ]] && [[ ! -e "$target" ]]; then
420
+ print_error "$ERROR_FILE_NOT_FOUND: $target"
421
+ return 1
422
+ fi
423
+
424
+ local exit_code=0
425
+ if snyk test "$target" "${snyk_args[@]}" 2>&1; then
426
+ print_success "$SUCCESS_SCAN_COMPLETE - No vulnerabilities found"
427
+ else
428
+ exit_code=$?
429
+ if [[ $exit_code -eq 1 ]]; then
430
+ print_warning "Vulnerabilities found - review results above"
431
+ else
432
+ print_error "$ERROR_SCAN_FAILED (exit code: $exit_code)"
433
+ fi
434
+ fi
435
+
436
+ return $exit_code
437
+ }
438
+
439
+ scan_code() {
440
+ local target="${1:-.}"
441
+ local org_name="${2:-}"
442
+ local extra_args="${3:-}"
443
+
444
+ print_header "Running Source Code Security Scan (SAST)"
445
+
446
+ if ! check_snyk_authenticated; then
447
+ print_error "$ERROR_NOT_AUTHENTICATED"
448
+ return 1
449
+ fi
450
+
451
+ local snyk_args=()
452
+
453
+ # Add organization if specified
454
+ if [[ -n "$org_name" ]]; then
455
+ local config
456
+ config=$(get_org_config "$org_name")
457
+ local org_id
458
+ org_id=$(echo "$config" | jq -r '.org_id // ""')
459
+ if [[ -n "$org_id" && "$org_id" != "null" ]]; then
460
+ snyk_args+=("--org=$org_id")
461
+ fi
462
+ fi
463
+
464
+ # Add extra arguments
465
+ if [[ -n "$extra_args" ]]; then
466
+ # shellcheck disable=SC2206
467
+ snyk_args+=($extra_args)
468
+ fi
469
+
470
+ print_info "Scanning: $target"
471
+ print_info "Options: ${snyk_args[*]:-none}"
472
+
473
+ if [[ "$target" != "." ]] && [[ ! -e "$target" ]]; then
474
+ print_error "$ERROR_FILE_NOT_FOUND: $target"
475
+ return 1
476
+ fi
477
+
478
+ local exit_code=0
479
+ if snyk code test "$target" "${snyk_args[@]}" 2>&1; then
480
+ print_success "$SUCCESS_SCAN_COMPLETE - No code vulnerabilities found"
481
+ else
482
+ exit_code=$?
483
+ if [[ $exit_code -eq 1 ]]; then
484
+ print_warning "Code vulnerabilities found - review results above"
485
+ else
486
+ print_error "$ERROR_SCAN_FAILED (exit code: $exit_code)"
487
+ fi
488
+ fi
489
+
490
+ return $exit_code
491
+ }
492
+
493
+ scan_container() {
494
+ local image="$1"
495
+ local org_name="${2:-}"
496
+ local extra_args="${3:-}"
497
+
498
+ if [[ -z "$image" ]]; then
499
+ print_error "$ERROR_TARGET_REQUIRED"
500
+ print_info "Usage: snyk-helper.sh container <image:tag> [org] [options]"
501
+ return 1
502
+ fi
503
+
504
+ print_header "Running Container Security Scan"
505
+
506
+ if ! check_snyk_authenticated; then
507
+ print_error "$ERROR_NOT_AUTHENTICATED"
508
+ return 1
509
+ fi
510
+
511
+ local snyk_args=()
512
+
513
+ # Add organization if specified
514
+ if [[ -n "$org_name" ]]; then
515
+ local config
516
+ config=$(get_org_config "$org_name")
517
+ local org_id
518
+ org_id=$(echo "$config" | jq -r '.org_id // ""')
519
+ if [[ -n "$org_id" && "$org_id" != "null" ]]; then
520
+ snyk_args+=("--org=$org_id")
521
+ fi
522
+ fi
523
+
524
+ # Add default severity threshold
525
+ local defaults
526
+ defaults=$(get_default_options)
527
+ if [[ -n "$defaults" ]]; then
528
+ # shellcheck disable=SC2206
529
+ snyk_args+=($defaults)
530
+ fi
531
+
532
+ # Add extra arguments
533
+ if [[ -n "$extra_args" ]]; then
534
+ # shellcheck disable=SC2206
535
+ snyk_args+=($extra_args)
536
+ fi
537
+
538
+ print_info "Scanning image: $image"
539
+ print_info "Options: ${snyk_args[*]:-none}"
540
+
541
+ local exit_code=0
542
+ if snyk container test "$image" "${snyk_args[@]}" 2>&1; then
543
+ print_success "$SUCCESS_SCAN_COMPLETE - No container vulnerabilities found"
544
+ else
545
+ exit_code=$?
546
+ if [[ $exit_code -eq 1 ]]; then
547
+ print_warning "Container vulnerabilities found - review results above"
548
+ else
549
+ print_error "$ERROR_SCAN_FAILED (exit code: $exit_code)"
550
+ fi
551
+ fi
552
+
553
+ return $exit_code
554
+ }
555
+
556
+ scan_iac() {
557
+ local target="${1:-.}"
558
+ local org_name="${2:-}"
559
+ local extra_args="${3:-}"
560
+
561
+ print_header "Running Infrastructure as Code Scan"
562
+
563
+ if ! check_snyk_authenticated; then
564
+ print_error "$ERROR_NOT_AUTHENTICATED"
565
+ return 1
566
+ fi
567
+
568
+ local snyk_args=()
569
+
570
+ # Add organization if specified
571
+ if [[ -n "$org_name" ]]; then
572
+ local config
573
+ config=$(get_org_config "$org_name")
574
+ local org_id
575
+ org_id=$(echo "$config" | jq -r '.org_id // ""')
576
+ if [[ -n "$org_id" && "$org_id" != "null" ]]; then
577
+ snyk_args+=("--org=$org_id")
578
+ fi
579
+ fi
580
+
581
+ # Add default severity threshold
582
+ local defaults
583
+ defaults=$(get_default_options)
584
+ if [[ -n "$defaults" ]]; then
585
+ # shellcheck disable=SC2206
586
+ snyk_args+=($defaults)
587
+ fi
588
+
589
+ # Add extra arguments
590
+ if [[ -n "$extra_args" ]]; then
591
+ # shellcheck disable=SC2206
592
+ snyk_args+=($extra_args)
593
+ fi
594
+
595
+ print_info "Scanning: $target"
596
+ print_info "Options: ${snyk_args[*]:-none}"
597
+
598
+ if [[ "$target" != "." ]] && [[ ! -e "$target" ]]; then
599
+ print_error "$ERROR_FILE_NOT_FOUND: $target"
600
+ return 1
601
+ fi
602
+
603
+ local exit_code=0
604
+ if snyk iac test "$target" "${snyk_args[@]}" 2>&1; then
605
+ print_success "$SUCCESS_SCAN_COMPLETE - No IaC misconfigurations found"
606
+ else
607
+ exit_code=$?
608
+ if [[ $exit_code -eq 1 ]]; then
609
+ print_warning "IaC misconfigurations found - review results above"
610
+ else
611
+ print_error "$ERROR_SCAN_FAILED (exit code: $exit_code)"
612
+ fi
613
+ fi
614
+
615
+ return $exit_code
616
+ }
617
+
618
+ # ------------------------------------------------------------------------------
619
+ # MONITORING
620
+ # ------------------------------------------------------------------------------
621
+
622
+ create_monitor() {
623
+ local target="${1:-.}"
624
+ local org_name="${2:-}"
625
+ local project_name="${3:-}"
626
+ local extra_args="${4:-}"
627
+
628
+ print_header "Creating Project Snapshot for Monitoring"
629
+
630
+ if ! check_snyk_authenticated; then
631
+ print_error "$ERROR_NOT_AUTHENTICATED"
632
+ return 1
633
+ fi
634
+
635
+ local snyk_args=()
636
+
637
+ # Add organization if specified
638
+ if [[ -n "$org_name" ]]; then
639
+ local config
640
+ config=$(get_org_config "$org_name")
641
+ local org_id
642
+ org_id=$(echo "$config" | jq -r '.org_id // ""')
643
+ if [[ -n "$org_id" && "$org_id" != "null" ]]; then
644
+ snyk_args+=("--org=$org_id")
645
+ fi
646
+ fi
647
+
648
+ # Add project name if specified
649
+ if [[ -n "$project_name" ]]; then
650
+ snyk_args+=("--project-name=$project_name")
651
+ fi
652
+
653
+ # Add extra arguments
654
+ if [[ -n "$extra_args" ]]; then
655
+ # shellcheck disable=SC2206
656
+ snyk_args+=($extra_args)
657
+ fi
658
+
659
+ print_info "Creating snapshot for: $target"
660
+ print_info "Options: ${snyk_args[*]:-none}"
661
+
662
+ if snyk monitor "$target" "${snyk_args[@]}" 2>&1; then
663
+ print_success "$SUCCESS_MONITOR_CREATED"
664
+ print_info "View results at: https://app.snyk.io"
665
+ return 0
666
+ else
667
+ print_error "Failed to create monitoring snapshot"
668
+ return 1
669
+ fi
670
+ return 0
671
+ }
672
+
673
+ # ------------------------------------------------------------------------------
674
+ # SBOM GENERATION
675
+ # ------------------------------------------------------------------------------
676
+
677
+ generate_sbom() {
678
+ local target="${1:-.}"
679
+ local format="${2:-cyclonedx1.4+json}"
680
+ local output="${3:-}"
681
+
682
+ print_header "Generating Software Bill of Materials (SBOM)"
683
+
684
+ if ! check_snyk_authenticated; then
685
+ print_error "$ERROR_NOT_AUTHENTICATED"
686
+ return 1
687
+ fi
688
+
689
+ local snyk_args=("--format=$format")
690
+
691
+ if [[ -n "$output" ]]; then
692
+ snyk_args+=("--file=$output")
693
+ fi
694
+
695
+ print_info "Generating SBOM for: $target"
696
+ print_info "Format: $format"
697
+
698
+ if [[ "$target" != "." ]] && [[ ! -e "$target" ]]; then
699
+ print_error "$ERROR_FILE_NOT_FOUND: $target"
700
+ return 1
701
+ fi
702
+
703
+ if snyk sbom "$target" "${snyk_args[@]}" 2>&1; then
704
+ print_success "SBOM generated successfully"
705
+ if [[ -n "$output" ]]; then
706
+ print_info "Output saved to: $output"
707
+ fi
708
+ return 0
709
+ else
710
+ print_error "Failed to generate SBOM"
711
+ return 1
712
+ fi
713
+ return 0
714
+ }
715
+
716
+ # ------------------------------------------------------------------------------
717
+ # FULL SECURITY SCAN
718
+ # ------------------------------------------------------------------------------
719
+
720
+ full_scan() {
721
+ local target="${1:-.}"
722
+ local org_name="${2:-}"
723
+
724
+ print_header "Running Full Security Scan"
725
+ print_info "This will run SCA, Code, and IaC scans"
726
+
727
+ local has_issues=false
728
+
729
+ echo ""
730
+ echo "═══════════════════════════════════════════════════════════════"
731
+ echo "1. Dependency Scan (SCA)"
732
+ echo "═══════════════════════════════════════════════════════════════"
733
+ if ! scan_dependencies "$target" "$org_name"; then
734
+ has_issues=true
735
+ fi
736
+
737
+ echo ""
738
+ echo "═══════════════════════════════════════════════════════════════"
739
+ echo "2. Source Code Scan (SAST)"
740
+ echo "═══════════════════════════════════════════════════════════════"
741
+ if ! scan_code "$target" "$org_name"; then
742
+ has_issues=true
743
+ fi
744
+
745
+ echo ""
746
+ echo "═══════════════════════════════════════════════════════════════"
747
+ echo "3. Infrastructure as Code Scan"
748
+ echo "═══════════════════════════════════════════════════════════════"
749
+ if ! scan_iac "$target" "$org_name"; then
750
+ has_issues=true
751
+ fi
752
+
753
+ echo ""
754
+ echo "═══════════════════════════════════════════════════════════════"
755
+ echo "SCAN SUMMARY"
756
+ echo "═══════════════════════════════════════════════════════════════"
757
+
758
+ if $has_issues; then
759
+ print_warning "Security issues were found - review results above"
760
+ return 1
761
+ else
762
+ print_success "All scans completed - no security issues found"
763
+ return 0
764
+ fi
765
+ return 0
766
+ }
767
+
768
+ # ------------------------------------------------------------------------------
769
+ # MCP SERVER
770
+ # ------------------------------------------------------------------------------
771
+
772
+ start_mcp_server() {
773
+ print_header "Starting Snyk MCP Server"
774
+
775
+ if ! check_snyk_installed; then
776
+ print_error "$ERROR_SNYK_NOT_INSTALLED"
777
+ return 1
778
+ fi
779
+
780
+ if ! check_snyk_authenticated; then
781
+ print_warning "Not authenticated - some features may not work"
782
+ fi
783
+
784
+ print_info "Starting MCP server..."
785
+ print_info "Available tools: snyk_sca_scan, snyk_code_scan, snyk_iac_scan, snyk_container_scan, snyk_sbom_scan"
786
+
787
+ # The Snyk MCP server runs as: snyk mcp
788
+ exec snyk mcp
789
+ return 0
790
+ }
791
+
792
+ # ------------------------------------------------------------------------------
793
+ # HELP
794
+ # ------------------------------------------------------------------------------
795
+
796
+ show_help() {
797
+ cat << 'EOF'
798
+ Snyk Security Helper Script
799
+ Usage: ./snyk-helper.sh [command] [options]
800
+
801
+ SECURITY SCANNING:
802
+ test [path] [org] [opts] - Scan dependencies for vulnerabilities (SCA)
803
+ code [path] [org] [opts] - Scan source code for vulnerabilities (SAST)
804
+ container <image> [org] [opts] - Scan container images
805
+ iac [path] [org] [opts] - Scan Infrastructure as Code
806
+ full [path] [org] - Run all scans (SCA + SAST + IaC)
807
+
808
+ MONITORING & REPORTING:
809
+ monitor [path] [org] [name] - Create project snapshot for monitoring
810
+ sbom [path] [format] [output] - Generate Software Bill of Materials
811
+
812
+ AUTHENTICATION & STATUS:
813
+ auth [token] - Authenticate with Snyk
814
+ status - Check installation and auth status
815
+ accounts - List configured organizations
816
+
817
+ INSTALLATION:
818
+ install - Install Snyk CLI
819
+
820
+ MCP INTEGRATION:
821
+ mcp - Start Snyk MCP server for AI assistants
822
+
823
+ GENERAL:
824
+ help - Show this help message
825
+
826
+ EXAMPLES:
827
+ ./snyk-helper.sh test # Scan current directory
828
+ ./snyk-helper.sh test ./my-project my-org # Scan with organization
829
+ ./snyk-helper.sh code . --json # Code scan with JSON output
830
+ ./snyk-helper.sh container nginx:latest # Scan container image
831
+ ./snyk-helper.sh iac ./terraform/ # Scan Terraform files
832
+ ./snyk-helper.sh full . # Run all security scans
833
+ ./snyk-helper.sh monitor . my-org my-project # Create monitoring snapshot
834
+ ./snyk-helper.sh sbom . cyclonedx1.4+json sbom.json
835
+
836
+ SCAN TYPES:
837
+ SCA (test) - Open source dependency vulnerabilities
838
+ SAST (code) - Source code security issues
839
+ Container - Container image vulnerabilities + base image recommendations
840
+ IaC - Infrastructure as Code misconfigurations
841
+
842
+ SEVERITY LEVELS:
843
+ --severity-threshold=low|medium|high|critical
844
+
845
+ OUTPUT FORMATS:
846
+ --json - JSON output for parsing
847
+ --sarif - SARIF format for CI/CD integration
848
+ --html - HTML report
849
+
850
+ ENVIRONMENT VARIABLES:
851
+ SNYK_TOKEN - API token for authentication
852
+ SNYK_ORG - Default organization ID
853
+ SNYK_API - Custom API URL (for regional/self-hosted)
854
+
855
+ CONFIGURATION:
856
+ File: configs/snyk-config.json
857
+ Template: cp configs/snyk-config.json.txt configs/snyk-config.json
858
+
859
+ For more information:
860
+ - Documentation: https://docs.snyk.io/snyk-cli
861
+ - API Token: https://app.snyk.io/account
862
+ - Status Page: https://status.snyk.io/
863
+ EOF
864
+ return 0
865
+ }
866
+
867
+ # ------------------------------------------------------------------------------
868
+ # MAIN COMMAND HANDLER
869
+ # ------------------------------------------------------------------------------
870
+
871
+ main() {
872
+ local command="${1:-help}"
873
+ shift || true
874
+
875
+ # Commands that don't require snyk to be installed
876
+ case "$command" in
877
+ "install")
878
+ install_snyk
879
+ return $?
880
+ ;;
881
+ "help"|"-h"|"--help")
882
+ show_help
883
+ return 0
884
+ ;;
885
+ *)
886
+ # Other commands handled below after dependency check
887
+ ;;
888
+ esac
889
+
890
+ # Check dependencies for other commands
891
+ if ! check_dependencies; then
892
+ return 1
893
+ fi
894
+
895
+ case "$command" in
896
+ "test"|"sca"|"dependencies")
897
+ scan_dependencies "$@"
898
+ ;;
899
+ "code"|"sast")
900
+ scan_code "$@"
901
+ ;;
902
+ "container"|"docker"|"image")
903
+ scan_container "$@"
904
+ ;;
905
+ "iac"|"infrastructure")
906
+ scan_iac "$@"
907
+ ;;
908
+ "full"|"all")
909
+ full_scan "$@"
910
+ ;;
911
+ "monitor")
912
+ create_monitor "$@"
913
+ ;;
914
+ "sbom")
915
+ generate_sbom "$@"
916
+ ;;
917
+ "auth"|"login")
918
+ authenticate "$@"
919
+ ;;
920
+ "status")
921
+ show_status
922
+ ;;
923
+ "accounts"|"orgs"|"organizations")
924
+ list_accounts
925
+ ;;
926
+ "mcp")
927
+ start_mcp_server
928
+ ;;
929
+ *)
930
+ print_error "$ERROR_UNKNOWN_COMMAND $command"
931
+ print_info "Use './snyk-helper.sh help' for usage information"
932
+ return 1
933
+ ;;
934
+ esac
935
+
936
+ return $?
937
+ }
938
+
939
+ # Execute main function
940
+ main "$@"