Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: plug NodeSecure runtime configuration #3

Merged
merged 42 commits into from
Mar 26, 2022

Conversation

antoine-coulon
Copy link
Member

@antoine-coulon antoine-coulon commented Mar 14, 2022

Linked to #2

This PR aims to integrate the @nodesecure/rc lib which would be another way to provide a runtime configuration in addition to the API and CLI options.

More generally it also introduces a way to manage different types of configuration in a transparent way for the @nodesecure/ci runner by providing standardization mechanisms towards a Nsci Configuration.

Consequently here are few semantic choices that can be discussed:

  • Nsci configuration becomes the standard interface for a valid configuration in order to run the pipeline
  • External configuration becomes the standard format for every external configuration (API, CLI, .nodesecurerc). Each configuration has to implement an adapter than converts the input format of the configuration to the external configuration format.
  • Once CLI, API or .nodesecurerc configuration is adapted to the External configuration, the External configuration can be standardized and validated to the Nsci format.

Take for example:

  • cli configuration
export type CliConfig = {
  directory: string;
  strategy: Nsci.InputStrategy;
  vulnerabilities: Nsci.Severity;
  warnings: Nsci.Warnings;
  reporters: string | Nsci.ReporterTarget[];
};
  • .nodesecurerc configuration, described differently
export interface RC {
  version: string;
   i18n?: i18n.languages;
   strategy?: vuln.Strategy.Kind;
   ci?: {
     reporters?: ("console" | "html")[];
     vulnerabilities?: {
        severity?: "medium" | "high" | "critical" | "all";
     };
     warnings?: CiWarnings | Record<jsxray.kindWithValue | "unsafe-import", CiWarnings>;
   };
}

These two different configurations can be defined by the user upstream the pipeline runner but we want to abstract this
complexity for the runner which should consume a standard format agnostic of configuration changes.

For that, I propose to describe a target standard format for each of these configurations such as:

export type ExternalRuntimeConfiguration = {
  directory: string;
  strategy: Nsci.InputStrategy;
  vulnerabilities: Nsci.Severity;
  warnings: Nsci.Warnings;
  reporters: string | Nsci.ReporterTarget[];
};

Each of the config could then be converted to this format above by implementing a common adapter:

export type ExternalConfigAdapter<T> = {
  adaptToExternalConfig: (config: T) => ExternalRuntimeConfiguration;
};

Once the config is adapted to the ExternalRuntimeConfiguration, its an easy work to sanitize/validate/complete the Nsci standard configuration (check src/config/external/standardize.ts)

@antoine-coulon antoine-coulon force-pushed the plug-runtime-configuration branch from 47a7f58 to a100757 Compare March 14, 2022 18:26
@antoine-coulon antoine-coulon force-pushed the plug-runtime-configuration branch 7 times, most recently from fcdcf9f to 2b6c240 Compare March 17, 2022 16:59
@antoine-coulon antoine-coulon force-pushed the plug-runtime-configuration branch 2 times, most recently from 73bc823 to 031159a Compare March 22, 2022 23:40
Copy link
Member

@tony-go tony-go left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@antoine-coulon antoine-coulon force-pushed the plug-runtime-configuration branch 4 times, most recently from 189a326 to bafb80b Compare March 23, 2022 23:16
@antoine-coulon antoine-coulon force-pushed the plug-runtime-configuration branch from bafb80b to a67133a Compare March 24, 2022 19:10
@fraxken fraxken merged commit 7b038e2 into main Mar 26, 2022
@fraxken fraxken deleted the plug-runtime-configuration branch June 2, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants