Skip to content

Commit

Permalink
(CI-7107) allow insecure / client cert flags
Browse files Browse the repository at this point in the history
  • Loading branch information
TP Honey committed Apr 28, 2023
1 parent 12cfd6f commit 0ee8e4a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 13 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {
"PLUGIN_URL": "http://localhost:8080",
"PLUGIN_USERNAME": "admin",
"PLUGIN_PASSWORD": "admin",
// "PLUGIN_INSECURE": "true",
// "PLUGIN_PEM_FILE_CONTENTS": "asdasdasdasdasd",
// "PLUGIN_PEM_FILE_PATH": "/tmp/bla.pem",
}
}
]
}
64 changes: 51 additions & 13 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
Expand All @@ -22,18 +23,21 @@ type Args struct {
Level string `envconfig:"PLUGIN_LOG_LEVEL"`

// TODO replace or remove
Username string `envconfig:"PLUGIN_USERNAME"`
Password string `envconfig:"PLUGIN_PASSWORD"`
APIKey string `envconfig:"PLUGIN_API_KEY"`
AccessToken string `envconfig:"PLUGIN_ACCESS_TOKEN"`
URL string `envconfig:"PLUGIN_URL"`
Source string `envconfig:"PLUGIN_SOURCE"`
Target string `envconfig:"PLUGIN_TARGET"`
Retries int `envconfig:"PLUGIN_RETRIES"`
Flat string `envconfig:"PLUGIN_FLAT"`
Spec string `envconfig:"PLUGIN_SPEC"`
Threads int `envconfig:"PLUGIN_THREADS"`
SpecVars string `envconfig:"PLUGIN_SPEC_VARS"`
Username string `envconfig:"PLUGIN_USERNAME"`
Password string `envconfig:"PLUGIN_PASSWORD"`
APIKey string `envconfig:"PLUGIN_API_KEY"`
AccessToken string `envconfig:"PLUGIN_ACCESS_TOKEN"`
URL string `envconfig:"PLUGIN_URL"`
Source string `envconfig:"PLUGIN_SOURCE"`
Target string `envconfig:"PLUGIN_TARGET"`
Retries int `envconfig:"PLUGIN_RETRIES"`
Flat string `envconfig:"PLUGIN_FLAT"`
Spec string `envconfig:"PLUGIN_SPEC"`
Threads int `envconfig:"PLUGIN_THREADS"`
SpecVars string `envconfig:"PLUGIN_SPEC_VARS"`
Insecure string `envconfig:"PLUGIN_INSECURE"`
PEMFileContents string `envconfig:"PLUGIN_PEM_FILE_CONTENTS"`
PEMFilePath string `envconfig:"PLUGIN_PEM_FILE_PATH"`
}

// Exec executes the plugin.
Expand Down Expand Up @@ -67,7 +71,41 @@ func Exec(ctx context.Context, args Args) error {
if args.Threads > 0 {
cmdArgs = append(cmdArgs, fmt.Sprintf("--threads=%d", args.Threads))
}

// Set insecure flag
insecure := parseBoolOrDefault(false, args.Insecure)
if insecure {
cmdArgs = append(cmdArgs, "--insecure-tls")
}
// create pem file
if args.PEMFileContents != "" && !insecure {
var path string
// figure out path to write pem file
if args.PEMFilePath == "" {
if runtime.GOOS == "windows" {
path = "C:/users/ContainerAdministrator/.jfrog/security/certs/cert.pem"
} else {
path = "/root/.jfrog/security/certs/cert.pem"
}
} else {
path = args.PEMFilePath
}
fmt.Printf("Creating pem file at %q\n", path)
// write pen contents to path
if _, err := os.Stat(path); os.IsNotExist(err) {
// remove filename from path
dir := filepath.Dir(path)
pemFolderErr := os.MkdirAll(dir, 0700)
if pemFolderErr != nil {
return fmt.Errorf("error creating pem folder: %s", pemFolderErr)
}
// write pem contents
pemWriteErr := os.WriteFile(path, []byte(args.PEMFileContents), 0600)
if pemWriteErr != nil {
return fmt.Errorf("error writing pem file: %s", pemWriteErr)
}
fmt.Printf("Successfully created pem file at %q\n", path)
}
}
// Take in spec file or use source/target arguments
if args.Spec != "" {
cmdArgs = append(cmdArgs, fmt.Sprintf("--spec=%s", args.Spec))
Expand Down

0 comments on commit 0ee8e4a

Please sign in to comment.