LoginSignup
0
0

Snyk(スニーク)って、Salesforceでも使えるの?(後編)

Last updated at Posted at 2023-12-20

前回は、以下のようなエラーになって力尽きてしまいました。さて、ちょっとだけ気を取り直して... そのそも使い方を間違えているような気がしていますが...

Could not detect supported target files in C:\Users\user\Desktop\snyk.
Please see our documentation for supported languages and target files: https://snyk.co/udVgQ and make sure you are in the right directory.

コードのスキャンだから、コマンドが違うのかな?
新たなエラーです。検索してみると

ここにリンクあるので、ヘルプを読むのですが全く何のことか理解できませんね。
英語は分からないのでグーグル翻訳ですが、理解できん。何のことだろう?こうなるといつも遊んでいるSalesforceの方がずっと分かりやすいです。やはり使い方を間違えているようですね。

./snyk code test

Snyk Code is not supported for org: enable in Settings > Snyk Code

やはりマニュアルを読まないといけませんね。

CLIを使用したスキャン

CLIを使用してスキャンを開始する前に、インストール、認証、およぼ開発手順を実行していることを確認してください。

  • 「snyk CLIのインストールまたは更新」ページの指示に従い、ニーズに適切なインストール方法を選択してください。
  • CLIをインストールした後、「認証」ページの指示に従ってマシンを認証する必要があります。
  • CLIで実行してインストールをテストできます。 snyk --help

そういえば、snyk --helpはやってないので、意味があるかはわかりませんがやっておこう

CLI help
  Snyk CLI scans and monitors your projects for security vulnerabilities and license issues.

  For more information visit the Snyk website https://snyk.io

  For details see the CLI documentation https://docs.snyk.io/features/snyk-cli

How to get started
  1. Authenticate by running snyk auth.
  2. Test your local project with snyk test.
  3. Get alerted for new vulnerabilities with snyk monitor.

Available commands
  To learn more about each Snyk CLI command, use the --help option, for example, snyk auth --help.

  Note: The help on the docs site is the same as the --help in the CLI.

  snyk auth
    Authenticate Snyk CLI with a Snyk account.

  snyk test
  Test a project for open-source vulnerabilities and license issues.

    Note: Use snyk test --unmanaged to scan all files for known open-source dependencies (C/C++
    only).

  snyk monitor
    Snapshot and continuously monitor a project for open-source vulnerabilities and license issues.

  snyk container
    These commands test and continuously monitor container images for vulnerabilities and generate anSBOM for a container image.

  snyk iac
    These commands find and report security issues in Infrastructure as Code files; detect, track,
    and alert on infrastructure drift and unmanaged resources; and create a .driftigore file.

  snyk code
    The snyk code test command finds security issues using Static Code Analysis.

  snyk sbom
    Produce an SBOM for a local software project in an ecosystem supported by Snyk.

  snyk log4shell
    Find Log4Shell vulnerability.

  snyk config
    Manage Snyk CLI configuration.

  snyk policy
    Display the .snyk policy for a package.
    
  snyk ignore
    Modify the .snyk policy to ignore stated issues.

Debug
  Use -d option to output the debug logs.

Configure the Snyk CLI
  You can use environment variables to configure the Snyk CLI and also set variables to configure the
  Snyk CLI to connect with the Snyk API. See Configure the Snyk CLI
  https://docs.snyk.io/features/snyk-cli/configure-the-snyk-cli
  • CLIのセットアップが完了したら、スキャンを開始できます。詳細については、「CLIの概要」を参照してください。

スキャンを開始する

CLIを使用してプロジェクトをスキャンする場合、さまざまなコマンドとオプションを使用できます。その中には、Snyk Open Source、snyk Code、Snyk Container、またはSnyk lacにのみ適用されるものや、方法に関係なくスキャンに適用されるものもあります。Snyk CLIコマンドとオプションの完全なリストについては、「CLIコマンドとオプションの概要」を参照してください。

Snyk コード用の Snyk CLI

  • Snyk コードオプション Snyk Org設定で有効化。

Webで設定するのかな?

WEBに戻るとそういえば...

ディレクトリーが必要?

image.png

image.png

有効化したら、ちょっとエラーメッセージが変わりました

We found 0 supported files
Please see our documentation for Snyk Code language and framework support
https://docs.snyk.io/products/snyk-code/snyk-code-language-and-framework-support

.dccacheという{}が入ったテキストファイルが作成されています。何だろう。

ソースを実行ファイルと同じフォルダーにコピーし直します。

Apexのソースファイルを探せない?

We found 0 supported files
Please see our documentation for Snyk Code language and framework support
https://docs.snyk.io/products/snyk-code/snyk-code-language-and-framework-support

We found 0 supported filesで検索すると同じようなエラーの質問があります。
package.jsonが必要らしいけど... 開発者コンソールからダウンロードしたApexにはないよなぁ...

仕方ないのでpackage.jsonのひな型を眺めていたら...

よくよく考えたらApexの拡張子ってclsじゃない? 昨日はSalesforceの画面見ながら作ったので画面にあったapxcを拡張しにしたような... 何か違和感があったんですがね。

"prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",

開発者コンソールのタブを見たら .apxcになっているんだよ。これって拡張子でないのかな?

image.png

ということで、Apexの拡張子を変更します。

./snyk code test --org=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Testing C:\Users\user\Desktop\snyk ...


✔ Test completed

Organization:      xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Test type:         Static code analysis
Project path:      C:\Users\user\Desktop\snyk

Summary:

✔ Awesome! No issues were found.

おお、テストしていますね。結果は問題なしかな?

とりあえず、Apexのコードをスキャンできました。

スキャンするまでの環境をつくるのが面倒かもしれませんが、手動で配置してもコードをチェックできそうです。
PosotmanでSalesforceのTooling APIを呼び出せばApexClassはダウンロードできそうなので、Postman CLIを使えばもう少しは自動化できるかもしれません。

いやぁ、1つのApex Classをスキャンするまでにかなり時間がかかりましたね。


サポートしている拡張子が書いてありました。

Code analysis
Interfile is currently not supported. The data flow is monitored within a single file, not between multiple files.
.trigger and .cls files are supported.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0