From d0ae4f1c1a6f6af7eb4d33983def78a26e02346d Mon Sep 17 00:00:00 2001 From: DRAGON Date: Sat, 22 Jul 2023 13:26:40 +0530 Subject: [PATCH 1/3] fix: yamlhandler error handling Signed-off-by: DRAGON --- core/pkg/fixhandler/yamlhandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/pkg/fixhandler/yamlhandler.go b/core/pkg/fixhandler/yamlhandler.go index 45e64f7f..5b5048d2 100644 --- a/core/pkg/fixhandler/yamlhandler.go +++ b/core/pkg/fixhandler/yamlhandler.go @@ -23,8 +23,6 @@ func decodeDocumentRoots(yamlAsString string) ([]yaml.Node, error) { var node yaml.Node err := dec.Decode(&node) - nodes = append(nodes, node) - if errors.Is(err, io.EOF) { break } @@ -32,6 +30,8 @@ func decodeDocumentRoots(yamlAsString string) ([]yaml.Node, error) { return nil, fmt.Errorf("Cannot Decode File as YAML") } + + nodes = append(nodes, node) } return nodes, nil From d8e913fb9f7b7053ba6dbe0d0b11f234bb8e63a8 Mon Sep 17 00:00:00 2001 From: DRAGON Date: Thu, 13 Jul 2023 01:26:21 +0530 Subject: [PATCH 2/3] feat: add build.ps1 Signed-off-by: DRAGON --- build.ps1 | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 build.ps1 diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 00000000..75fc2c88 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,77 @@ +# Defining input params +param ( + [string]$mode = "error" +) + +# Function to install MSYS +function Install { + Write-Host "Starting install..." -ForegroundColor Cyan + + # Check to see if already installed + if (Test-Path "C:\MSYS64\") { + Write-Host "MSYS2 already installed" -ForegroundColor Green + } else { + # Create a temp directory + New-Item -Path "$PSScriptRoot\temp_install" -ItemType Directory > $null + + # Download MSYS + Write-Host "Downloading MSYS2..." -ForegroundColor Cyan + $bitsJobObj = Start-BitsTransfer "https://github.com/msys2/msys2-installer/releases/download/2022-06-03/msys2-x86_64-20220603.exe" -Destination "$PSScriptRoot\temp_install\msys2-x86_64-20220603.exe" + switch ($bitsJobObj.JobState) { + "Transferred" { + Complete-BitsTransfer -BitsJob $bitsJobObj + break + } + "Error" { + throw "Error downloading" + } + } + Write-Host "MSYS2 download complete" -ForegroundColor Green + + # Install MSYS + Write-Host "Installing MSYS2..." -ForegroundColor Cyan + Start-Process -Filepath "$PSScriptRoot\temp_install\msys2-x86_64-20220603.exe" -ArgumentList @("install", "--root", "C:\MSYS64", "--confirm-command") -Wait -NoNewWindow + Write-Host "MSYS2 install complete" -ForegroundColor Green + + # Set PATH + $env:Path = "C:\MSYS64\mingw64\bin;C:\MSYS64\usr\bin;" + $env:Path + + # Install MSYS packages + Write-Host "Installing MSYS2 packages..." -ForegroundColor Cyan + Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "make") -Wait -NoNewWindow + Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "mingw-w64-x86_64-cmake") -Wait -NoNewWindow + Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "mingw-w64-x86_64-gcc") -Wait -NoNewWindow + Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "mingw-w64-x86_64-pkg-config") -Wait -NoNewWindow + Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "msys2-w32api-runtime") -Wait -NoNewWindow + Write-Host "MSYS2 packages install complete" -ForegroundColor Green + + # Remove temp directory + Remove-Item "$PSScriptRoot\temp_install" -Recurse + } + Write-Host "Install complete" -ForegroundColor Green +} + +# Function to build libgit2 +function Build { + Write-Host "Starting build..." -ForegroundColor Cyan + + # Set PATH + $env:Path = "C:\MSYS64\mingw64\bin;C:\MSYS64\usr\bin;" + $env:Path + + # Build + Start-Process -Filepath "make" -ArgumentList @("libgit2") -Wait -NoNewWindow + + Write-Host "Build complete" -ForegroundColor Green +} + +# Check user call mode +if ($mode -eq "all") { + Install + Build +} elseif ($mode -eq "install") { + Install +} elseif ($mode -eq "build") { + Build +} else { + Write-Host "Error: -mode should be one of (all|install|build)" -ForegroundColor Red +} \ No newline at end of file From c4e5611c7f0bc925355aa66e02f4791a4ce36d44 Mon Sep 17 00:00:00 2001 From: rcohencyberarmor <84019060+rcohencyberarmor@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:37:44 +0300 Subject: [PATCH 3/3] add print in the cli to which version the kubescape was update (#1295) * add print in the cli to which version the kubescape was update Signed-off-by: rcohencyberarmor * update will suggest to our user to update by following kubescape installation guide Signed-off-by: rcohencyberarmor --------- Signed-off-by: rcohencyberarmor Co-authored-by: rcohencyberarmor --- cmd/update/update.go | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index 38b205c5..fe373a0d 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -6,14 +6,16 @@ package update import ( "fmt" - "os/exec" - "runtime" logger "github.com/kubescape/go-logger" "github.com/kubescape/kubescape/v2/core/cautils" "github.com/spf13/cobra" ) +const ( + installationLink string = "https://github.com/kubescape/kubescape/blob/master/docs/installation.md" +) + var updateCmdExamples = fmt.Sprintf(` # Update to the latest kubescape release %[1]s update @@ -31,33 +33,7 @@ func GetUpdateCmd() *cobra.Command { //your version == latest version logger.L().Info(("You are in the latest version")) } else { - - const OSTYPE string = runtime.GOOS - var ShellToUse string - switch OSTYPE { - - case "windows": - cautils.StartSpinner() - //run the installation command for windows - ShellToUse = "powershell" - _, err := exec.Command(ShellToUse, "-c", "iwr -useb https://raw.githubusercontent.com/kubescape/kubescape/master/install.ps1 | iex").Output() - - if err != nil { - logger.L().Fatal(err.Error()) - } - cautils.StopSpinner() - - default: - ShellToUse = "bash" - cautils.StartSpinner() - //run the installation command for linux and macOS - _, err := exec.Command(ShellToUse, "-c", "curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash").Output() - if err != nil { - logger.L().Fatal(err.Error()) - } - - cautils.StopSpinner() - } + fmt.Printf("please refer to our installation docs in the following link: %s", installationLink) } return nil },