ldhertert / harness-cli

Apache License 2.0
18 stars 14 forks source link

harness-cli

Version Downloads/week License Slack

Overview

This tool has been designed to simplify common automation tasks for administration of the Harness platform. The primary focus initially is on streamlining common app team onboarding tasks, such as creating applications, user groups, and bootstrapping default pipeline resources. These tasks leverage the Harness GraphQL API as well as Harness Config as Code. There are also commands for interacting with common platforms that Harness customers interact with in tandem with Harness, such as Github and Kubernetes.

Disclaimers

Installation

There are two options for installation.

1) There are standalone binaries available for linux, macos, and windows on the releases page. 2) NPM package. Note: NodeJS v12 or required.

    npm install -g @ldhertert/harness-cli

Usage

Examples of command usage can be found here

$ export HARNESS_ACCOUNT='xxxxxx'
$ export HARNESS_API_KEY='xxxxxx'
$ harness applications:list
running command...
$ harness (-v|--version|version)
$ harness --help [COMMAND]

Global options

The following options are available across all commands, but for brevity have been exclused from the individual command documentation.

OPTIONS
  --harnessAccountId=harnessAccountId  The Harness Account Id.  Can also be set via HARNESS_ACCOUNT environment
                                       variable.

  --harnessApiKey=harnessApiKey        The Harness API Key. Can also be set via HARNESS_API_KEY environment variable.

  --managerUrl=managerUrl              [default: https://app.harness.io] The Harness Manager URL.  Can also be set via
                                       HARNESS_MANAGER_URL environment variable.  If a path is included, then that path is used as the API root.  Otherwise, the default API root will be /gateway/api.

  -s, --silent                         Supress stdout logging. Can also be set via
                                       HARNESS_CLI_SILENT environment variable

  --debug                              Print debug logs to stdout. Can also be set via
                                       HARNESS_CLI_DEBUG environment variable

  --help                               Display help for a command                                      

Commands

harness application:create

Create a new Harness application

USAGE
  $ harness application:create

OPTIONS
  -n, --name=name              (required) The name of the application
  --branch=branch              The branch name to use for git sync. Defaults to "master" if sync is enabled.
  --description=description    A description of the application
  --gitConnector=gitConnector  The name or id of the git connector to use for git sync.
  --skipExisting               If true, this command will not fail if an resource with the same name already exists.
  --syncEnabled                Whether or not git sync should be enabled

ALIASES
  $ harness app:create
  $ harness apps:create
  $ harness applications:create
  $ harness application:create

See code: src/commands/application/create.ts

harness application:delete

Delete an application

USAGE
  $ harness application:delete

OPTIONS
  -n, --nameOrId=nameOrId  (required) The name or id of the application

ALIASES
  $ harness app:delete
  $ harness apps:delete
  $ harness applications:delete
  $ harness application:delete

See code: src/commands/application/delete.ts

harness application:get

Get an application

USAGE
  $ harness application:get

OPTIONS
  -n, --nameOrId=nameOrId  (required) The name or id of the application

ALIASES
  $ harness app:get
  $ harness apps:get
  $ harness applications:get
  $ harness application:get

See code: src/commands/application/get.ts

harness application:list

List Applications

USAGE
  $ harness application:list

ALIASES
  $ harness app:list
  $ harness apps:list
  $ harness applications:list
  $ harness application:list

See code: src/commands/application/list.ts

harness application:update

Update an application

USAGE
  $ harness application:update

OPTIONS
  -n, --nameOrId=nameOrId      (required) The current name or id of the application
  --branch=branch              The branch name to use for git sync
  --description=description    The new description of the application. If omitted, the value will remain unchanged.
  --gitConnector=gitConnector  The name or id of the git connector to use for git sync
  --newName=newName            The new name of the application.  If omitted, the value will remain unchanged.
  --syncEnabled                Whether or not git sync should be enabled. If omitted, the value will remain unchanged.

ALIASES
  $ harness app:update
  $ harness apps:update
  $ harness applications:update
  $ harness application:update

See code: src/commands/application/update.ts

harness autocomplete [SHELL]

display autocomplete installation instructions

USAGE
  $ harness autocomplete [SHELL]

ARGUMENTS
  SHELL  shell type

OPTIONS
  -r, --refresh-cache  Refresh cache (ignores displaying instructions)

EXAMPLES
  $ harness autocomplete
  $ harness autocomplete bash
  $ harness autocomplete zsh
  $ harness autocomplete --refresh-cache

See code: @oclif/plugin-autocomplete

harness cloud-provider:create-k8s

Create a new application

USAGE
  $ harness cloud-provider:create-k8s

OPTIONS
  -n, --name=name                                        (required) The name of the cloud provider

  --harnessPassword=harnessPassword                      The Harness password. This is currently required if you inherit
                                                         from delegate (See
                                                         https://github.com/ldhertert/harness-cli/issues/6).  Can also
                                                         be set via HARNESS_PASSWORD environment variable.

  --harnessUsername=harnessUsername                      The Harness username. This is currently required if you inherit
                                                         from delegate (See
                                                         https://github.com/ldhertert/harness-cli/issues/6).  Can also
                                                         be set via HARNESS_USERNAME environment variable.

  --inheritFromDelegate=inheritFromDelegate              If true, permissions are inherited from the delegate instead of
                                                         being explicitly provided

  --masterUrl=masterUrl                                  The Kubernetes master node URL. The easiest method to obtain
                                                         the master URL is using kubectl: kubectl cluster-info

  --serviceAccountTokenSecret=serviceAccountTokenSecret  The name or id of the secret that contains the service account
                                                         token

  --skipExisting                                         If true, this command will not fail if an resource with the
                                                         same name already exists.

  --skipValidation

ALIASES
  $ harness cloud-provider:create-k8s
  $ harness cloud-providers:create-k8s

See code: src/commands/cloud-provider/create-k8s.ts

harness cloud-provider:delete

Delete cloud provider

USAGE
  $ harness cloud-provider:delete

OPTIONS
  -n, --nameOrId=nameOrId  (required) The name or id of the cloud provider

ALIASES
  $ harness cloud-provider:delete
  $ harness cloud-providers:delete

See code: src/commands/cloud-provider/delete.ts

harness cloud-provider:get

Get cloud provider

USAGE
  $ harness cloud-provider:get

OPTIONS
  -n, --nameOrId=nameOrId  (required) The name or id of the cloud provider

ALIASES
  $ harness cloud-provider:get
  $ harness cloud-providers:get

See code: src/commands/cloud-provider/get.ts

harness config-as-code:delete

Delete a config as code file at the given path

USAGE
  $ harness config-as-code:delete

OPTIONS
  --harnessPassword=harnessPassword  [DEPRECATED] The Harness password. Can also be set via HARNESS_PASSWORD environment
                                     variable.

  --harnessUsername=harnessUsername  [DEPRECATED] The Harness username. Can also be set via HARNESS_USERNAME environment
                                     variable.

  --path=path                        (required) The file path to delete.  Glob patterns are supported.

ALIASES
  $ harness config:delete
  $ harness config-as-code:delete

See code: src/commands/config-as-code/delete.ts

harness config-as-code:get

Fetch file contents based on path

USAGE
  $ harness config-as-code:get

OPTIONS
  --harnessPassword=harnessPassword  (required) The Harness password. This is required for now until the underlying APIs
                                     suport API key auth.  Can also be set via HARNESS_PASSWORD environment variable.

  --harnessUsername=harnessUsername  (required) The Harness username. This is required for now until the underlying APIs
                                     suport API key auth.  Can also be set via HARNESS_USERNAME environment variable.

  --out=out                          A directory path on the local filesystem that will be used to write file contents
                                     to disk.

  --path=path                        (required) The file path(s) to fetch contents for. Glob patterns are supported.

  --raw                              Output raw YAML content instead of a JSON array.  This is only supported when there
                                     is a single file matching the provided path.

ALIASES
  $ harness config:get
  $ harness config-as-code:get

See code: src/commands/config-as-code/get.ts

harness config-as-code:list-files

List file tree for config-as-code

USAGE
  $ harness config-as-code:list-files

OPTIONS
  --harnessPassword=harnessPassword  [DEPRECATED] The Harness password. Can also be set via HARNESS_PASSWORD environment
                                     variable.

  --harnessUsername=harnessUsername  [DEPRECATED] The Harness username. Can also be set via HARNESS_USERNAME environment
                                     variable.

ALIASES
  $ harness config:list
  $ harness config-as-code:list-files

See code: src/commands/config-as-code/list-files.ts

harness config-as-code:upsert

Create or update a config as code file at the given path

USAGE
  $ harness config-as-code:upsert

OPTIONS
  --content=content                  The YAML content

  --harnessPassword=harnessPassword  [DEPRECATED] The Harness password. Can also be set via HARNESS_PASSWORD environment
                                     variable.

  --harnessUsername=harnessUsername  [DEPRECATED] The Harness username. Can also be set via HARNESS_USERNAME environment
                                     variable.

  --path=path                        The file path

  --source=source                    The path to a directory on the local filesystem that contains files to be upserted.
                                     Source files must contain a valid Harness config as code path structure relative to
                                     the source directory.

  --sourcePattern=sourcePattern      [default: **/*.yaml] A glob pattern to limit files to include from source directory

ALIASES
  $ harness config:upsert
  $ harness config-as-code:upsert
  $ harness config:create
  $ harness config-as-code:create
  $ harness config:update
  $ harness config-as-code:update

See code: src/commands/config-as-code/upsert.ts

harness connectors:create-docker

Create docker connector

USAGE
  $ harness connectors:create-docker

OPTIONS
  -n, --name=name                  (required) The name of the connector

  --passwordSecret=passwordSecret  The name or id of the secret that contains the password to be used for docker
                                   authentication

  --skipExisting                   If true, this command will not fail if an resource with the same name already exists.

  --url=url                        (required) [default: https://index.docker.io/v2/] The url for the docker registry

  --username=username              The username to be used for authentication

ALIASES
  $ harness connector:create-docker
  $ harness connectors:create-docker

See code: src/commands/connectors/create-docker.ts

harness connectors:create-git

Create git connector

USAGE
  $ harness connectors:create-git

OPTIONS
  -n, --name=name                  (required) The name of the connector
  --branch=branch                  [default: master] The git branch name

  --passwordSecret=passwordSecret  (required) The name or id of the secret that contains the password to be used for git
                                   authentication

  --url=url                        (required) The url for the repository

  --username=username              (required) The username to be used for git authentication

ALIASES
  $ harness connector:create-git
  $ harness connectors:create-git

See code: src/commands/connectors/create-git.ts

harness connectors:delete

Delete connector

USAGE
  $ harness connectors:delete

OPTIONS
  -n, --name=name                        The name of the connector
  --id=id                                The id of the connector
  --type=(DockerConnector|GitConnector)  (required)

ALIASES
  $ harness connector:delete
  $ harness connectors:delete

See code: src/commands/connectors/delete.ts

harness github:create-repo

Create a new GitHub Repository in an Organization

USAGE
  $ harness github:create-repo

OPTIONS
  --baseUrl=baseUrl                       [default: https://api.github.com] The Github API base url
  --description=description               A description of the application
  --org=org                               (required) The Github organization
  --repo=repo                             (required) The repository name

  --token=token                           (required) The GitHub token for authentication.  This can also be set via the
                                          environment variable GITHUB_TOKEN.

  --visibility=(private|public|internal)  [default: private] Visibility settings for the repository

See code: src/commands/github/create-repo.ts

harness github:create-webhook

Create a new webhook in a GitHub repo for a Harness git connector

USAGE
  $ harness github:create-webhook

OPTIONS
  --baseUrl=baseUrl            [default: https://api.github.com] The Github API base url
  --gitConnector=gitConnector  (required) The name or id of the Harness git connector
  --org=org                    (required) The Github organization
  --repo=repo                  (required) The repository name

  --token=token                (required) The GitHub token for authentication.  This can also be set via the environment
                               variable GITHUB_TOKEN.

See code: src/commands/github/create-webhook.ts

harness github:delete-repo

Delete a GitHub Repository in an Organization

USAGE
  $ harness github:delete-repo

OPTIONS
  --baseUrl=baseUrl  [default: https://api.github.com] The Github API base url
  --org=org          (required) The Github organization
  --repo=repo        (required) The repository name

  --token=token      (required) The GitHub token for authentication.  This can also be set via the environment variable
                     GITHUB_TOKEN.

See code: src/commands/github/delete-repo.ts

harness groups:create

Create a new user group. Note - not all functionality has been implemented yet

USAGE
  $ harness groups:create

OPTIONS
  -n, --name=name                          (required) The name of the group

  --applicationScope=applicationScope      An application id or name.  This will replace any Application Restrictions
                                           with the provided applications.  Multiple values are allowed

  --copyPermissionFrom=copyPermissionFrom  Copy permissions from an existing group.

  --permissions=permissions                JSON encoded permissions object

ALIASES
  $ harness group:create
  $ harness groups:create

See code: src/commands/groups/create.ts

harness groups:delete

Delete user group

USAGE
  $ harness groups:delete

OPTIONS
  -n, --name=name  The name of the group
  --id=id          The id of the group

ALIASES
  $ harness group:delete
  $ harness groups:delete

See code: src/commands/groups/delete.ts

harness groups:get

Get user group

USAGE
  $ harness groups:get

OPTIONS
  -n, --name=name  The name of the group
  --id=id          The id of the group

ALIASES
  $ harness group:get
  $ harness groups:get

See code: src/commands/groups/get.ts

harness groups:list

List User groups

USAGE
  $ harness groups:list

ALIASES
  $ harness group:list
  $ harness groups:list

See code: src/commands/groups/list.ts

harness help [COMMAND]

display help for harness

USAGE
  $ harness help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

harness k8s:cluster-info

Get a kubernetes service account

USAGE
  $ harness k8s:cluster-info

OPTIONS
  --kubeconfig=kubeconfig  Path to a kubeconfig file. If not specified, the following search order takes precedence:
                           KUBECONFIG environment variable, default kubectl config file (i.e. ~/.kube/config).

  --name=name              [default: harness] The name of the service account

See code: src/commands/k8s/cluster-info.ts

harness k8s:create-namespace

Create a new Kubernetes namespace

USAGE
  $ harness k8s:create-namespace

OPTIONS
  --kubeconfig=kubeconfig  Path to a kubeconfig file. If not specified, the following search order takes precedence:
                           KUBECONFIG environment variable, default kubectl config file (i.e. ~/.kube/config).

  --name=name              (required) The name of the new namespace

See code: src/commands/k8s/create-namespace.ts

harness k8s:create-role

Create a Kubernetes Role with common Harness permissions and optionally bind to a service account.

USAGE
  $ harness k8s:create-role

OPTIONS
  --kubeconfig=kubeconfig                            Path to a kubeconfig file. If not specified, the following search
                                                     order takes precedence: KUBECONFIG environment variable, default
                                                     kubectl config file (i.e. ~/.kube/config).

  --listDeploymentsInDefaultNamespace                Grants the account permissions to list deployments in the default
                                                     namespace. This is required for cloud provider validation to be
                                                     successful without skipping validation.

  --name=name                                        [default: harness] The name of the role

  --namespace=namespace                              The namespace to create the role in. If not specified, the default
                                                     namespace in your kubeconfig will be used

  --namespaceAdmin                                   Grant full permissions to a specific namespace.

  --serviceAccount=serviceAccount                    [default: harness] Specify a service account to create a role
                                                     binding for

  --serviceAccountNamespace=serviceAccountNamespace  The namespace of the service account. If not provided, the service
                                                     account for the role is used.

See code: src/commands/k8s/create-role.ts

harness k8s:create-service-account

Create a kubernetes service account

USAGE
  $ harness k8s:create-service-account

OPTIONS
  --kubeconfig=kubeconfig  Path to a kubeconfig file. If not specified, the following search order takes precedence:
                           KUBECONFIG environment variable, default kubectl config file (i.e. ~/.kube/config).

  --name=name              [default: harness] The name of the service account

  --namespace=namespace    The name of the namespace. If not specified, the default namespace in your kubeconfig will be
                           used

See code: src/commands/k8s/create-service-account.ts

harness k8s:get-service-account

Get a kubernetes service account

USAGE
  $ harness k8s:get-service-account

OPTIONS
  --kubeconfig=kubeconfig  Path to a kubeconfig file. If not specified, the following search order takes precedence:
                           KUBECONFIG environment variable, default kubectl config file (i.e. ~/.kube/config).

  --name=name              [default: harness] The name of the service account

  --namespace=namespace    The name of the namespace. If not specified, the default namespace in your kubeconfig will be
                           used

See code: src/commands/k8s/get-service-account.ts

harness secrets:create

Create a new secret

USAGE
  $ harness secrets:create

OPTIONS
  -n, --name=name
      (required) The name of the secret

  -v, --value=value
      (required) The value of the secret

  --accountScope
      Scope this secret to the account for use in delegate profiles

  --scope=scope
      [default: ALL_APPS::PROD_ENVS,ALL_APPS::NON_PROD_ENVS] 
      Restrict the use of this resource to specific Harness components.  
      The expected format is "application::environment".  
      The supported values for applications are "ALL_APPS", an application name, or an application id.  
      The supported values for environments are "PROD_ENVS", "NON_PROD_ENVS", an environment name, or an environment id.

      Examples:
      All applications, production environments: "ALL_APPS::PROD_ENVS"
      All applications, non-production environments: "ALL_APPS::NON_PROD_ENVS"
      Specific application, specific environment: "MyCoolApp::development"
      Specific application, non-production environment: "rPyC0kD_SbymffS26SC_GQ::nonprod"

  --secretManager=secretManager
      (required) The id of the secret manager to leverage

  --skipExisting
      If true, this command will not fail if an resource with the same name already exists.

  --type=(ENCRYPTED_TEXT)
      (required) [default: ENCRYPTED_TEXT]

ALIASES
  $ harness secret:create
  $ harness secrets:create

See code: src/commands/secrets/create.ts

harness secrets:delete

Delete a secret

USAGE
  $ harness secrets:delete

OPTIONS
  -n, --name=name          The name of the secret
  --id=id                  The id of the secret
  --type=(ENCRYPTED_TEXT)  (required) [default: ENCRYPTED_TEXT]

ALIASES
  $ harness secret:delete
  $ harness secrets:delete

See code: src/commands/secrets/delete.ts

harness secrets:get

Get Secret By Id or By Name

USAGE
  $ harness secrets:get

OPTIONS
  -n, --name=name          The name of the secret
  --id=id                  The id of the secret
  --type=(ENCRYPTED_TEXT)  (required) [default: ENCRYPTED_TEXT]

ALIASES
  $ harness secret:get
  $ harness secrets:get

See code: src/commands/secrets/get.ts

harness secrets:update

Update a text secret

USAGE
  $ harness secrets:update

OPTIONS
  -n, --name=name
      The name of the secret.  If you want to rename a secret, then secret ID must also be provided.

  -v, --value=value
      (required) The value of the secret

  --accountScope
      Scope this secret to the account for use in delegate profiles

  --id=id
      The id of the secret

  --scope=scope
      [default: ALL_APPS::PROD_ENVS,ALL_APPS::NON_PROD_ENVS] 
      Restrict the use of this resource to specific Harness components.  
      The expected format is 'application::environment'.  
      The supported values for applications are 'ALL_APPS', an application name, or an application id.  
      The supported values for environments are 'PROD_ENVS', 'NON_PROD_ENVS', an environment name, or an environment id.

      Examples:
      All applications, production environments: 'ALL_APPS::PROD_ENVS'
      All applications, non-production environments: 'ALL_APPS::NON_PROD_ENVS'
      Specific application, specific environment: 'MyCoolApp::development'
      Specific application, non-production environment: 'rPyC0kD_SbymffS26SC_GQ::nonprod'

ALIASES
  $ harness secret:update
  $ harness secrets:update

See code: src/commands/secrets/update.ts

harness template:exec

Apply steps defined in template manifest and send reults to target Harness account.

USAGE
  $ harness template:exec

OPTIONS
  -v, --var=var                      Set a variable specified within the template.  Format is --var "templateVar=My
                                     Value"

  --dryRun                           Executes all template steps but does not push result to destination

  --harnessPassword=harnessPassword  [DEPRECATED] The Harness password. Can also be set via HARNESS_PASSWORD environment
                                     variable.

  --harnessUsername=harnessUsername  [DEPRECATED] The Harness username. Can also be set via HARNESS_USERNAME environment
                                     variable.

  --manifest=manifest                (required) A template manifest in either YAML or JSON format.  Can be a local file
                                     or URL.

See code: src/commands/template/exec.ts

harness users:create

Create user

USAGE
  $ harness users:create

OPTIONS
  -e, --email=email  (required) The email of the user
  -n, --name=name    (required) The name of the user
  --group=group      [default: ] The name or id of a Harness group

ALIASES
  $ harness user:create
  $ harness users:create

See code: src/commands/users/create.ts

harness users:delete

Delete user by email/name/id

USAGE
  $ harness users:delete

OPTIONS
  -n, --name=name  The name of the user
  --email=email    The email of the user
  --id=id          The id of the user

ALIASES
  $ harness user:delete
  $ harness users:delete

See code: src/commands/users/delete.ts

harness users:get

Get user by email/name/id

USAGE
  $ harness users:get

OPTIONS
  -n, --name=name  The name of the user
  --email=email    The email of the user
  --id=id          The id of the user

ALIASES
  $ harness user:get
  $ harness users:get

See code: src/commands/users/get.ts

harness users:list

List users

USAGE
  $ harness users:list

ALIASES
  $ harness user:list
  $ harness users:list

See code: src/commands/users/list.ts

Development

Common tasks

Generate new command

  npx oclif command applications:create

Update autogenerated portions of the README

  npx oclif-dev readme

Build dockerfile

  docker build --rm -t harness-cli .
  docker run --rm harness-cli --version

Releasing

export GITHUB_TOKEN='xxxx'
npm run release