Skip to content

Commit

Permalink
[Enhancement] Add provision to skip TLS validation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-opsverse authored Feb 8, 2024
1 parent 4cd501b commit ffb8061
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@ name: Integration Test

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Import Secrets
id: secrets
uses: hashicorp/[email protected]
with:
url: ${{ secrets.VAULT_ADDR }}
method: github
githubToken: ${{ secrets.GT_VAULT_AUTH_TOKEN }}
secrets: |
argocd/data/token admin | ARGOCD_TOKEN ;
- name: Self test
id: selftest
uses: ./
with:
address: ${{ secrets.ARGOCD_ADDR }}
token: ${{ steps.secrets.outputs.ARGOCD_TOKEN }}
address: ${{ secrets.ARGOCD_SERVER }}
token: ${{ secrets.ARGOCD_TOKEN }}
action: sync
appName: argocd-apps
appName: ${{ secrets.ARGOCD_APP_NAME }}
image: latest

disableTlsVerification: "false"
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ jobs:
token: ${{ secrets.ARGOCD_TOKEN }}
action: sync
appName: "my-example-app"
disableTlsVerification: "false" # Default is false. Only enable this if ArgoCD doesn't have TLS / has self signed certificate / you see any sort of x509 errors
```
### Inputs
| Input | Description |
|-----------|----------------------------------------|
| `address` | ArgoCD server address. |
| `token` | ArgoCD Token. |
| `action` | ArgoCD Action i.e. sync. |
| `appName` | Application name to execute action on. |
| Input | Description |
|--------------------------|----------------------------------------|
| `address` | ArgoCD server address. |
| `token` | ArgoCD Token. |
| `action` | ArgoCD Action i.e. sync. |
| `appName` | Application name to execute action on. |
| `disableTlsVerification` | Skip TLS validation. |

## Examples

Expand All @@ -57,4 +59,5 @@ jobs:
token: ${{ secrets.ARGOCD_TOKEN }}
action: sync
appName: "my-example-app"
disableTlsVerification: "false" # Default is false. Only enable this if ArgoCD doesn't have TLS / has self signed certificate / you see any sort of x509 errors
```
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ inputs:
image:
description: "Image tag for the binary"
required: false
default: "latest"
default: "latest"
disableTlsVerification:
description: "Disable TLS Verification"
required: true
default: "false"

runs:
using: "composite"
steps:
- name: Run argocd-actions CLI from the image for GH image registry
run: |
docker run --rm -i ghcr.io/omegion/argocd-actions:${{ inputs.image }} \
docker run --rm -i registry.devopsnow.io/public/argocd-sync-action:${{ inputs.image }} \
${{ inputs.action }} \
--application=${{ inputs.appName }} \
--token=${{ inputs.token }} \
--address=${{ inputs.address }} \
--disableTlsVerification=${{disableTlsVerification}} \
--logLevel=debug
shell: sh
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ func Root() *cobra.Command {
log.Fatalf("Lethal damage: %s\n\n", err)
}

cmd.PersistentFlags().String("disableTlsVerification", "", "Disable TLS verification")

if err := cmd.MarkPersistentFlagRequired("disableTlsVerification"); err != nil {
log.Fatalf("Lethal damage: %s\n\n", err)
}

return cmd
}
9 changes: 7 additions & 2 deletions cmd/sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"strconv"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand All @@ -17,10 +19,13 @@ func Sync() *cobra.Command {
address, _ := cmd.Flags().GetString("address")
token, _ := cmd.Flags().GetString("token")
application, _ := cmd.Flags().GetString("application")
disableTlsVerification, _ := cmd.Flags().GetString("disableTlsVerification")
disableTlsVerificationBool, _ := strconv.ParseBool(disableTlsVerification)

api := argocd.NewAPI(&argocd.APIOptions{
Address: address,
Token: token,
Address: address,
Token: token,
DisableTlsVerification: disableTlsVerificationBool,
})

controller := ctrl.NewController(api)
Expand Down
13 changes: 10 additions & 3 deletions internal/argocd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package argocd
import (
"context"
"io"
"log"

argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
applicationpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
argoio "github.com/argoproj/argo-cd/v2/util/io"
)

//nolint:lll // go generate is ugly.
// Interface is an interface for API.
//
//nolint:lll // go generate is ugly.
type Interface interface {
Sync(appName string) error
}
Expand All @@ -23,8 +25,9 @@ type API struct {

// APIOptions is options for API.
type APIOptions struct {
Address string
Token string
Address string
Token string
DisableTlsVerification bool
}

// NewAPI creates new API.
Expand All @@ -33,9 +36,13 @@ func NewAPI(options *APIOptions) API {
ServerAddr: options.Address,
AuthToken: options.Token,
GRPCWeb: true,
Insecure: options.DisableTlsVerification,
}

connection, client := argocdclient.NewClientOrDie(&clientOptions).NewApplicationClientOrDie()
if options.DisableTlsVerification {
log.Println("Skip TLS Validation option is enabled")
}

return API{client: client, connection: connection}
}
Expand Down

0 comments on commit ffb8061

Please sign in to comment.