Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rizul2108 committed Dec 22, 2023
1 parent 828f99a commit 1b66b95
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 113 deletions.
4 changes: 2 additions & 2 deletions cliHelpers/infraService/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion katana-services
28 changes: 7 additions & 21 deletions lib/utils/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/utils/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
86 changes: 1 addition & 85 deletions lib/utils/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"context"
"fmt"

"io"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1b66b95

Please sign in to comment.