From 1b66b957a0a277a3e5c43e13bfa644b760949e9a Mon Sep 17 00:00:00 2001 From: Rizul Gupta Date: Fri, 22 Dec 2023 16:01:36 +0530 Subject: [PATCH] minor fixes --- cliHelpers/infraService/helper.go | 4 +- katana-services | 2 +- lib/utils/crypto.go | 28 +++------- lib/utils/docker.go | 4 -- lib/utils/kube.go | 86 +------------------------------ 5 files changed, 11 insertions(+), 113 deletions(-) diff --git a/cliHelpers/infraService/helper.go b/cliHelpers/infraService/helper.go index a180d85..07017aa 100644 --- a/cliHelpers/infraService/helper.go +++ b/cliHelpers/infraService/helper.go @@ -81,7 +81,7 @@ func GitSetup() error { // Create the request req, err := http.NewRequest("POST", "http://"+LoadBalancer+":3000"+"/install", &requestBody) if err != nil { - fmt.Println("", err) + fmt.Println(err) return err } @@ -92,7 +92,7 @@ func GitSetup() error { client := &http.Client{} resp, err := client.Do(req) if err != nil { - fmt.Println("", err) + fmt.Println(err) return err } diff --git a/katana-services b/katana-services index a79e56b..34fb474 160000 --- a/katana-services +++ b/katana-services @@ -1 +1 @@ -Subproject commit a79e56b2458f84a42fa51d293fa1bce036af57b5 +Subproject commit 34fb47432e1118a50ca0f6f0a99e858a115b320f diff --git a/lib/utils/crypto.go b/lib/utils/crypto.go index 6c2ea3e..dffb60e 100644 --- a/lib/utils/crypto.go +++ b/lib/utils/crypto.go @@ -36,15 +36,12 @@ func GenerateCerts(domain string, basePath string) error { return err } - cmd = "openssl rsa -in " + basePath + "/ca.key -out "+ basePath + "/ca.key -traditional" - if err := RunCommand(cmd); err != nil { - return err - } - - // using -traditional flag to get PKCS#1 [different header], otherwise 500 Internal Error - cmd = "openssl rsa -in " + basePath + "/ca.key -out " + basePath + "/ca.key -traditional" - if err := RunCommand(cmd); err != nil { - return err + if(openSSLabove3){ + // using -traditional flag to get PKCS#1 [different header], otherwise 500 Internal Error + cmd = "openssl rsa -in " + basePath + "/ca.key -out " + basePath + "/ca.key -traditional" + if err := RunCommand(cmd); err != nil { + return err + } } // using -traditional flag to get PKCS#1 [different header], otherwise 500 Internal Error @@ -60,18 +57,6 @@ func GenerateCerts(domain string, basePath string) error { return err } - // using -traditional flag to get PKCS#1 [different header], otherwise 500 Internal Error - cmd = "openssl rsa -in " + basePath + "/" + domain + ".key -out " + basePath + "/" + domain + ".key -traditional" - if err := RunCommand(cmd); err != nil { - return err - } - - // using -traditional flag to get PKCS#1 [different header], otherwise 500 Internal Error - cmd = "openssl rsa -in " + basePath + "/" + domain + ".key -out " + basePath + "/" + domain + ".key -traditional" - if err := RunCommand(cmd); err != nil { - return err - } - // Generate private key cmd = "openssl genrsa -out " + basePath + "/" + domain + ".key 4096" if err := RunCommand(cmd); err != nil { @@ -80,6 +65,7 @@ func GenerateCerts(domain string, basePath string) error { } if(openSSLabove3){ + // using -traditional flag to get PKCS#1 [different header], otherwise 500 Internal Error cmd = "openssl rsa -in " + basePath+"/"+domain + ".key -out "+ basePath +"/"+domain + ".key -traditional" if err := RunCommand(cmd); err != nil { return err diff --git a/lib/utils/docker.go b/lib/utils/docker.go index b08bb88..b4591dd 100644 --- a/lib/utils/docker.go +++ b/lib/utils/docker.go @@ -45,10 +45,6 @@ func CheckDockerfile(_DockerfilePath string) bool { return !os.IsNotExist(err) } -func CheckDockerfile(_DockerfilePath string) bool { - _, err := os.Stat(_DockerfilePath + "/Dockerfile") - return !os.IsNotExist(err) -} func BuildDockerImage(_ChallengeName string, _DockerfilePath string) error { buf := new(bytes.Buffer) if err := Tar(_DockerfilePath, buf); err != nil { diff --git a/lib/utils/kube.go b/lib/utils/kube.go index f9b2c43..e246cff 100644 --- a/lib/utils/kube.go +++ b/lib/utils/kube.go @@ -4,8 +4,6 @@ import ( "bytes" "context" "fmt" - - "io" "io/ioutil" "log" "os" @@ -261,89 +259,7 @@ func CopyIntoPod(podName string, containerName string, pathInPod string, localFi return nil } -func CopyFromPod(podName string, containerName string, pathInPod string, localFilePath string, ns ...string) error { - config, err := GetKubeConfig() - if err != nil { - return err - } - - client, err := GetKubeClient() - if err != nil { - return err - } - - namespace := "katana" - if len(ns) > 0 { - namespace = ns[0] - } - - pod, err := client.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{}) - if err != nil { - log.Printf("Error getting pod: %s\n", err) - } - - // Find the container in the pod - var container *corev1.Container - for _, c := range pod.Spec.Containers { - if c.Name == containerName { - container = &c - break - } - } - - if container == nil { - log.Printf("Container not found in pod\n") - err = fmt.Errorf("container not found in pod") - return err - } - - // Create a stream to the container - req := client.CoreV1().RESTClient().Post(). - Resource("pods"). - Name(podName). - Namespace(namespace). - SubResource("exec"). - Param("container", containerName) - - req.VersionedParams(&corev1.PodExecOptions{ - Container: containerName, - Command: []string{"cat", pathInPod}, - Stdin: false, - Stdout: true, - Stderr: true, - TTY: false, - }, scheme.ParameterCodec) - - exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL()) - if err != nil { - log.Printf("Error creating executor: %s\n", err) - return err - } - - localFile, err := os.Create(localFilePath) - if err != nil { - log.Printf("Error creating local file: %s\n", err) - return err - } - defer localFile.Close() - - // Stream the file - err = exec.Stream(remotecommand.StreamOptions{ - Stdin: nil, - Stdout: localFile, - Stderr: os.Stderr, - Tty: false, - }) - if err != nil { - log.Printf("Error streaming the file: %s\n", err) - return err - } - - log.Println("File copied successfully") - return nil -} - - func GetKatanaLoadbalancer() (string,error) { +func GetKatanaLoadbalancer() (string,error) { client, err := GetKubeClient() if err != nil { log.Fatal(err)