Download and Initialization
Download, install, and authenticate with the Opscompass CLI.
The Opscompass Command Line Interface (CLI) allows you to interact with Opscompass directly from your shell. The CLI is distributed through NPM and supports both browser-based and device-code authentication flows.
Download the Opscompass CLI from NPM
Install the CLI package from NPM:npm install -g @opscompass/opscompass-cli
NPM package:
https://www.npmjs.com/package/@Opscompass/Opscompass-cli
The Opscompass Command Line Interface (the CLI) lets you interact with Opscompass directly from your shell.
Optional: Configure Firewall Access
The Opscompass CLI requires access to several Opscompass endpoints. If your environment restricts outbound connections, only the required URLs need to be allowed.
For a complete list of endpoints, see the Firewall Rules for CLI API Endpoint URLs article.
Login
Login supports the two basic "native app" authentication flows:
- Authorization Code with PKCE, the "no-secret" authorization code flow, for clients with interactive browsers
- Device authorization flow, for clients without interactive browsers
Authorization Code with PKCE
This is the recommended authentication method when the machine running the CLI has access to an interactive web browser. Most Windows and macOS users will use this flow.
Start authentication:
opscompass login
When this command runs, the CLI:
- Creates short-lived security values.
- Starts a local HTTP listener on port 8400.
- Opens your default browser.
- Directs you to the Opscompass sign-in experience.
Log in using the same credentials you use when logging into the Opscompass web experience. If you haven't authorized the CLI before, after you log in and provide your MFA token, you'll be asked to authorize the CLI application.
Once you've logged in and authorized the CLI, the browser will redirect you to the local HTTP server hosted by the CLI. The CLI will take the authorization code and redeem it with the short-lived secrets to get the Opscompass access token. If it's successful, the browser shows a "Logging in..." page. If anything fails, you'll see "Problems logging in" page. It stops listening for HTTP traffic at this point.
Device Authorization
Use Device Authorization when:
Opscompass login --use-device-code
The CLI displays a URL and authorization code. The authentication process works as follows:
- The CLI requests a device code.
- You open the supplied URL and enter the displayed code.
- You authenticate and authorize the device.
- The CLI polls for completion.
- The CLI receives an access token and confirms login.
If authorization is not completed before the device code expires, the login attempt fails.
Access Token Usage
After authentication, the CLI includes the access token in all API requests until the token expires. The CLI also receives a refresh token that is used to obtain new access tokens automatically.
Refresh tokens expire if they are not used regularly. In some cases, Opscompass may require users to authenticate again even during normal use.
For additional information, see the article on CLI authentication and token expiration.
Re-Authenticating
You can authenticate with
Opscompass login
or
Opscompass login --use-device-code
Successful authentication replaces the currently stored credentials. Failed authentication attempts do not remove existing credentials.