Sanitize Document Content

Action ID: cnoe:utils:sanitize
NPM Package:

@cnoe-io/plugin-scaffolder-actions

Description

Sanitizes the provided document to ensure it is free of harmful content.

Input Schema

PropertyTypeDescriptionRequired
documentstringThe document to be sanitized

Output Schema

No output schema defined for this action.

Usage Examples

Sanitize user provided README content before templating

Use this to validate freeform README text from template parameters before it is rendered into files. Place it early in the workflow alongside a fetch:template step.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme/templates/service
      targetPath: .
      values:
        name: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}
        readme: ${{ parameters.readme }}

  - id: sanitize-readme
    action: cnoe:utils:sanitize
    input:
      document: |-
        # ${{ parameters.name }}

        ${{ parameters.readme }}

        ---
        Owner: ${{ parameters.owner }}
        Description: ${{ parameters.description }}

Sanitize a Kubernetes manifest string provided by users

Use this to validate a Kubernetes Deployment manifest that will be written by the template. Run it before rendering files with fetch:template.

Copy
steps:
  - id: fetch-skeleton
    action: fetch:template
    input:
      url: https://github.com/acme/templates/kubernetes-service
      targetPath: .
      values:
        serviceName: ${{ parameters.name }}
        image: ${{ parameters.image }}
        replicas: ${{ parameters.replicas }}

  - id: sanitize-k8s-manifest
    action: cnoe:utils:sanitize
    input:
      document: |-
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: ${{ parameters.name }}
          labels:
            app.kubernetes.io/name: ${{ parameters.name }}
        spec:
          replicas: ${{ parameters.replicas }}
          selector:
            matchLabels:
              app.kubernetes.io/name: ${{ parameters.name }}
          template:
            metadata:
              labels:
                app.kubernetes.io/name: ${{ parameters.name }}
            spec:
              containers:
                - name: app
                  image: ${{ parameters.image }}
                  ports:
                    - containerPort: 8080
                  env:
                    - name: FEATURE_FLAG
                      value: ${{ parameters.featureFlag }}