CodeScene: Difference between revisions

From Omnia
Jump to navigation Jump to search
 
(17 intermediate revisions by the same user not shown)
Line 7: Line 7:
  https://codescene.io/docs/cli/index.html
  https://codescene.io/docs/cli/index.html


=== CLI Usage ===
=== CLI - Check ===


  cs review
Check a specific file for code health issues
  cs check [file]
 
<pre>
EXAMPLES
  $ cs check test.c                      Check the file test.c
  $ cs check master:./test.c              Check the file test.c on the master branch
  $ cs check 801b0c0f:./test.c            Check the file test.c at the given commit
  $ cs check --file-name test.c < test.c  Read file data from stdin
</pre>
 
=== CLI - Review ===
 
Score a file, and provide a review
cs review [file]
 
<pre>
EXAMPLES
  $ cs review test.c                      Check the file test.c
  $ cs review test.c --output-format json  Check test.c and output the results as json
  $ cs review master:./test.c              Check the file test.c on the master branch
  $ cs review 801b0c0f:./test.c            Check the file test.c at the given commit
  $ cs review --file-name test.c < test.c  Read file data from stdin
</pre>
 
=== CLI - Update ===
 
Command for updating the CLI:
cs update
 
=== CLI - Help ===
 
<pre>
$ cs help
USAGE
  $ cs <command> [--help | <args>]
 
COMMANDS
  delta      Perform a delta analysis in the current git repository
  review     Score a file, and provide a review
  check      Check a specific file for code health issues
  docs        CodeScene CLI documentation topics
  version    Display CLI version info
  update      Command for updating the CLI
  check-rules Find code health rule matches for input file
 
GETTING HELP
  For more information about a specific command, run `cs <command> --help`
  For more general documentation, run `cs docs`
 
Invalid arguments: ("help")
</pre>


=== CLI Configuration ===
=== CLI Configuration ===
Line 31: Line 82:
=== Windows CLI Tools Installation ===
=== Windows CLI Tools Installation ===


Powershell Installation:
  Invoke-WebRequest -Uri 'https://downloads.codescene.io/enterprise/cli/install-cs-tool.ps1' -OutFile install-cs-tool.ps1
  Invoke-WebRequest -Uri 'https://downloads.codescene.io/enterprise/cli/install-cs-tool.ps1' -OutFile install-cs-tool.ps1
  .\install-cs-tool.ps1
  .\install-cs-tool.ps1


May need to set Powershell permissions first (if you have never run Powershell scripts before):
Set-ExecutionPolicy RemoteSigned
Set access token:
  $env:CS_ACCESS_TOKEN = 'your-access-token'
  $env:CS_ACCESS_TOKEN = 'your-access-token'


Line 41: Line 97:
Run a code scene command:
Run a code scene command:
  cs review
  cs review
Installs the tool to:
%LOCALAPPDATA%\Programs\CodeScene\cs.exe
=== Linux CLI Tools Installation ===
The install script will download the binary, move it to ~/.local/bin and make it executable. If ~/.local/bin is not in the user’s PATH, it will be added.
Shell Installation:
curl https://downloads.codescene.io/enterprise/cli/install-cs-tool.sh | sh
export CS_ACCESS_TOKEN=your-access-token
If using an onpremise code scene server:
export CS_ONPREM_URL=https://codescene.example.com
Installs the tool to:
~/.local/bin/cs
$HOME/.local/bin/cs
/home/USER/.local/bin/cs


== Issues ==
== Issues ==
Line 58: Line 134:
</pre>
</pre>


If you don't want to wait for IT, you can test it out by checking out the next section, "Custom SSL Certificate"...
==== Can't Wait on IT, Test Now ====
 
If you don't want to wait for IT, you can test it out by checking out the section below, "Custom SSL Certificate"...


But first, collect the SSL Certificate chain:
Solution:
* First - cry.  Java is the worst at dealing with custom SSL keystores.  Sorry.
* Second - See the steps below under the section below, "Custom SSL Certificate"....


Use Firefox, view the SSL certificate chain, and export it out.  (Click the lock in the address bar, select Connection Secure, select More Information, View Certificate, under Miscellaneious select Download "PEM (chain)".
=== Untrusted SSL Certificate - Corporate SSL Proxy ===
 
If your company uses a SSL decryption monitoring certificate, you may run into this:
 
<pre>
PS C:\code> cs review


<img src="https://i.imgur.com/PJYEaxG.png" width="200" />
Version update check failed, proceeding.
<img src="https://i.imgur.com/sVQsqb1.png" width="100" />
License check failed (https://api.codescene.io/v2/tool-license/cli): error - javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
<img src="https://i.imgur.com/f17Cy9z.png" width="100" />
</pre>
<img src="https://i.imgur.com/x9wCVLe.png" width="200" />


Then split this chain file into several files named 1.pem, 2.pem, 3.pem, etc... depending on how many levels deep it is.
Solution:
* First - cry. Java is the worst at dealing with custom SSL keystores. Sorry.
* Second - See the steps below under the section below, "Custom SSL Certificate"....


=== Untrusted On-Premise CodeScene Server - Custom SSL Certificate ===
=== Untrusted On-Premise CodeScene Server - Custom SSL Certificate ===


Okay, so you didn't pay for an official SSL Certificate?  Sigh, Java is the worst when it comes to dealing with Custom SSL Certificates.  Sorry.  But you've made your bed, and wish to sleep in it, so buckle up, and here we go...
Okay, so you didn't pay for an official SSL Certificate ''(or you are stuck with a Corporate SSL Proxy Certificate)''?  Sigh, Java is the worst when it comes to dealing with Custom SSL Certificates.  Sorry.  But you've made your bed, and wish to sleep in it, so buckle up, and here we go...


Error:
Error:
<pre>
<pre>
PS C:\code> cs review
PS C:\code> cs review test.py


Version update check failed, proceeding.
Version update check failed, proceeding.
Line 83: Line 169:
</pre>
</pre>


First, you will need to build a custom Java Keystore, and every command, tool, and application will need to reference this custom Keystore.  It's ugly.  Very ugly.
Solution Overview:
* you will need to build a custom Java Keystore, and every command, tool, and application will need to reference this custom Keystore, and the way you reference the Keystore with each application is different.  It's ugly.  Very ugly.  Sorry.
 
==== Use Firefox to Collect the SSL Certificate Chain ====
 
First, collect the SSL Certificate chain.  This is from the perspective of the system trying to access the CodeScene server.  (This SSL chain may change if the system tries to connect via a VPN proxy, which may use a Corporate SSL proxy, so you may need a second keystore)
 
Use Firefox, view the SSL certificate chain, and export it out.  (Click the lock in the address bar, select Connection Secure, select More Information, View Certificate, under Miscellaneious select Download "PEM (chain)".
 
<img src="https://i.imgur.com/PJYEaxG.png" width="200" />
<img src="https://i.imgur.com/sVQsqb1.png" width="100" />
<img src="https://i.imgur.com/f17Cy9z.png" width="100" />
<img src="https://i.imgur.com/x9wCVLe.png" width="200" />
 
Then open this PEM text file, and split this chain file into several files named 1.pem, 2.pem, 3.pem, etc... depending on how many levels deep it is, and copy these to some place convenient like C:\code\
 
1.pem:
<pre>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</pre>
 
2.pem
<pre>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</pre>
 
etc...


==== Install OpenJDK for Keytool ====
==== Install OpenJDK for Keytool ====
Line 103: Line 219:
  ...etc...
  ...etc...


Note: If you are asked to trust the certificate, or if the certificate is already in the system keystore, agree to add it to the keystore anyway.
Note: If you are asked by keytool to trust the certificate, or if it reports the certificate is already in the system's keystore, agree to add it to the keystore anyway (default is "[no]" to type "yes").


It's not needed, as the default is a PKCS12 format, but if you want you can add the storetype:
Note: It's not needed, as the default is a PKCS12 format, but if you want you can add the storetype in the above commands:
  keytool -importcert -trustcacerts -file 1.pem -alias codescene_1 -storetype PKCS12 -keystore codescene.jks -storepass changeit
  keytool -importcert -trustcacerts -file 1.pem -alias codescene_1 -storetype PKCS12 -keystore codescene.jks -storepass changeit


==== Test CS-CLI with Keystore ====
==== Test CS-CLI with Keystore ====


To use the keystore you will need to inject it in various ways with Visual Code, CS-CLI, CS-MCP, etc.  For the CS-CLI, for example:
To use the keystore you will need to inject it in various ways with Visual Code, CS-CLI, CS-MCP, etc.  But, for the CS-CLI specifically, for example:


  # Powershell example
  # Powershell example
  $CS_ONPREM_URL = 'https://bad-codescene.example.com'
  $CS_ONPREM_URL = 'https://bad-codescene.example.com'
  $CS_ACCESS_TOKEN = 'insert-my-access-token-key-here-xxxxxxxxxxxxxxxx'
  $CS_ACCESS_TOKEN = 'insert-my-access-token-key-here-xxxxxxxxxxxxxxxx'
  cs review -Djavax.net.ssl.trustStore=C:/code/codescene.jks -Djavax.net.ssl.trustStorePassword=changeit  
  cs review -D"javax.net.ssl.trustStore=C:/code/codescene.jks" -D"javax.net.ssl.trustStorePassword=changeit"
 
Note: the java parameters use forward slashes "/" not back slashes "\" - I know this is Windows, and this may break some brains.


Note, once the license has been cached, you should be able to call the CS-CLI command again without the keystore parameters, at least until the cached license expires:
Note: once the license has been cached, you should be able to call the CS-CLI command again without the keystore parameters, at least until the cached license expires:
  cs review
  cs review


=== Untrusted SSL Certificate - Corporate SSL Proxy ===
==== License Caching ====
 
If your company uses a SSL decryption monitoring certificate, you may run into this:


<pre>
The license will be cached in:
PS C:\code> cs review
%APPDATA%\Codescene


Version update check failed, proceeding.
If you wish to force the license to be reacquired, delete this folder, and rerun the CS-CLI command
License check failed (https://api.codescene.io/v2/tool-license/cli): error - javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
</pre>
 
Solution
 
* First - cry.  Java is the worst at dealing with custom SSL keystores.  Sorry.


* Second - okay, so you still want to continue?
== keywords ==

Latest revision as of 01:10, 2 February 2026

CodeScene

https://codescene.com/

CLI Tools

https://codescene.io/docs/cli/index.html

CLI - Check

Check a specific file for code health issues

cs check [file]
EXAMPLES
  $ cs check test.c                       Check the file test.c
  $ cs check master:./test.c              Check the file test.c on the master branch
  $ cs check 801b0c0f:./test.c            Check the file test.c at the given commit
  $ cs check --file-name test.c < test.c  Read file data from stdin

CLI - Review

Score a file, and provide a review

cs review [file]
EXAMPLES
  $ cs review test.c                       Check the file test.c
  $ cs review test.c --output-format json  Check test.c and output the results as json
  $ cs review master:./test.c              Check the file test.c on the master branch
  $ cs review 801b0c0f:./test.c            Check the file test.c at the given commit
  $ cs review --file-name test.c < test.c  Read file data from stdin

CLI - Update

Command for updating the CLI:

cs update

CLI - Help

$ cs help
USAGE
  $ cs <command> [--help | <args>]

COMMANDS
  delta       Perform a delta analysis in the current git repository
  review      Score a file, and provide a review
  check       Check a specific file for code health issues
  docs        CodeScene CLI documentation topics
  version     Display CLI version info
  update      Command for updating the CLI
  check-rules Find code health rule matches for input file

GETTING HELP
  For more information about a specific command, run `cs <command> --help`
  For more general documentation, run `cs docs`

Invalid arguments: ("help")

CLI Configuration

Version update check failed, proceeding.
In order to use the full CLI tool you will need to set up your environment
with a Personal Access Token.

- codescene.io -> https://codescene.io/users/me/pat

- CodeScene Enterprise -> https://your.codescene.com/configuration/user/token

Generate a new PAT token then set your environment variables as follows:

- codescene.io -> $env:CS_ACCESS_TOKEN = '<your-PAT>'

- CodeScene Enterprise -> $env:CS_ACCESS_TOKEN = '<your-PAT>'

Windows CLI Tools Installation

Powershell Installation:

Invoke-WebRequest -Uri 'https://downloads.codescene.io/enterprise/cli/install-cs-tool.ps1' -OutFile install-cs-tool.ps1
.\install-cs-tool.ps1

May need to set Powershell permissions first (if you have never run Powershell scripts before):

Set-ExecutionPolicy RemoteSigned

Set access token:

$env:CS_ACCESS_TOKEN = 'your-access-token'

If using an onpremise code scene server:

$env:CS_ONPREM_URL = 'https://codescene.example.com'

Run a code scene command:

cs review

Installs the tool to:

%LOCALAPPDATA%\Programs\CodeScene\cs.exe

Linux CLI Tools Installation

The install script will download the binary, move it to ~/.local/bin and make it executable. If ~/.local/bin is not in the user’s PATH, it will be added.

Shell Installation:

curl https://downloads.codescene.io/enterprise/cli/install-cs-tool.sh | sh
export CS_ACCESS_TOKEN=your-access-token

If using an onpremise code scene server:

export CS_ONPREM_URL=https://codescene.example.com

Installs the tool to:

~/.local/bin/cs
$HOME/.local/bin/cs
/home/USER/.local/bin/cs

Issues

SSL Certificate Issues

Untrusted On-Premise CodeScene Server - Legitimate SSL Certificate

Okay, so you paid for an official SSL Certificate, but CodeScene is not trusting it? No worries, likey the problem is the web server is just simply not exporting out the full SSL certificate chain. Should be easily resolved. Just tell your IT team not to just export the end leaf SSL certificate, but the full SSL chain, including the intermediary certificates. This should resolve the issue

Error:

PS C:\code> cs review

Version update check failed, proceeding.
License check failed (https://good-codescene.example.com/api/v2/tool-license/cli): error - javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Can't Wait on IT, Test Now

If you don't want to wait for IT, you can test it out by checking out the section below, "Custom SSL Certificate"...

Solution:

  • First - cry. Java is the worst at dealing with custom SSL keystores. Sorry.
  • Second - See the steps below under the section below, "Custom SSL Certificate"....

Untrusted SSL Certificate - Corporate SSL Proxy

If your company uses a SSL decryption monitoring certificate, you may run into this:

PS C:\code> cs review

Version update check failed, proceeding.
License check failed (https://api.codescene.io/v2/tool-license/cli): error - javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Solution:

  • First - cry. Java is the worst at dealing with custom SSL keystores. Sorry.
  • Second - See the steps below under the section below, "Custom SSL Certificate"....

Untrusted On-Premise CodeScene Server - Custom SSL Certificate

Okay, so you didn't pay for an official SSL Certificate (or you are stuck with a Corporate SSL Proxy Certificate)? Sigh, Java is the worst when it comes to dealing with Custom SSL Certificates. Sorry. But you've made your bed, and wish to sleep in it, so buckle up, and here we go...

Error:

PS C:\code> cs review test.py

Version update check failed, proceeding.
License check failed (https://bad-codescene.example.com/api/v2/tool-license/cli): error - javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Solution Overview:

  • you will need to build a custom Java Keystore, and every command, tool, and application will need to reference this custom Keystore, and the way you reference the Keystore with each application is different. It's ugly. Very ugly. Sorry.

Use Firefox to Collect the SSL Certificate Chain

First, collect the SSL Certificate chain. This is from the perspective of the system trying to access the CodeScene server. (This SSL chain may change if the system tries to connect via a VPN proxy, which may use a Corporate SSL proxy, so you may need a second keystore)

Use Firefox, view the SSL certificate chain, and export it out. (Click the lock in the address bar, select Connection Secure, select More Information, View Certificate, under Miscellaneious select Download "PEM (chain)".

Then open this PEM text file, and split this chain file into several files named 1.pem, 2.pem, 3.pem, etc... depending on how many levels deep it is, and copy these to some place convenient like C:\code\

1.pem:

-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

2.pem

-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

etc...

Install OpenJDK for Keytool

Install the OpenJDK ( https://openjdk.org/install/ | https://jdk.java.net/ ), because screw Sun/Oracle and their schenaigans:

winget install openjdk --source winget

Gather your custom certificate file(s) and name them something like 1.pem

Build custom keystore

# Pick a place to put the keystore file, for example, c:\code\codescene.jks
mkdir c:\code
cd \code
keytool -importcert -trustcacerts -file 1.pem -alias codescene_1 -keystore codescene.jks -storepass changeit
keytool -importcert -trustcacerts -file 2.pem -alias codescene_2 -keystore codescene.jks -storepass changeit
keytool -importcert -trustcacerts -file 3.pem -alias codescene_3 -keystore codescene.jks -storepass changeit
...etc...

Note: If you are asked by keytool to trust the certificate, or if it reports the certificate is already in the system's keystore, agree to add it to the keystore anyway (default is "[no]" to type "yes").

Note: It's not needed, as the default is a PKCS12 format, but if you want you can add the storetype in the above commands:

keytool -importcert -trustcacerts -file 1.pem -alias codescene_1 -storetype PKCS12 -keystore codescene.jks -storepass changeit

Test CS-CLI with Keystore

To use the keystore you will need to inject it in various ways with Visual Code, CS-CLI, CS-MCP, etc. But, for the CS-CLI specifically, for example:

# Powershell example
$CS_ONPREM_URL = 'https://bad-codescene.example.com'
$CS_ACCESS_TOKEN = 'insert-my-access-token-key-here-xxxxxxxxxxxxxxxx'
cs review -D"javax.net.ssl.trustStore=C:/code/codescene.jks" -D"javax.net.ssl.trustStorePassword=changeit"

Note: the java parameters use forward slashes "/" not back slashes "\" - I know this is Windows, and this may break some brains.

Note: once the license has been cached, you should be able to call the CS-CLI command again without the keystore parameters, at least until the cached license expires:

cs review

License Caching

The license will be cached in:

%APPDATA%\Codescene

If you wish to force the license to be reacquired, delete this folder, and rerun the CS-CLI command

keywords