Test Proxy connection works
This commit is contained in:
parent
d39c183714
commit
0da207fd88
@ -29,6 +29,16 @@ func AWSMoveInstance(config state.Config) (state.Config) {
|
|||||||
|
|
||||||
fmt.Println("MTD move service:\t", uuid.UUID.String(uuid.UUID(serviceUUID)))
|
fmt.Println("MTD move service:\t", uuid.UUID.String(uuid.UUID(serviceUUID)))
|
||||||
|
|
||||||
|
// Test Proxy Connection
|
||||||
|
t := time.Now()
|
||||||
|
s := pcsdk.NewCommandStatus()
|
||||||
|
err := s.Execute(netip.AddrPortFrom(instance.EntryIP, config.MTD.ManagementPort))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error executing test command: %s\n", err)
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
fmt.Printf("Proxy Tested. (took %s)\n", time.Since(t).Round(100*time.Millisecond).String())
|
||||||
|
return config
|
||||||
region, instanceID := DecodeCloudID(instance.CloudID)
|
region, instanceID := DecodeCloudID(instance.CloudID)
|
||||||
awsConfig := NewConfig(region, config.AWS.CredentialsPath)
|
awsConfig := NewConfig(region, config.AWS.CredentialsPath)
|
||||||
svc := ec2.NewFromConfig(awsConfig)
|
svc := ec2.NewFromConfig(awsConfig)
|
||||||
@ -44,7 +54,7 @@ func AWSMoveInstance(config state.Config) (state.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Create image
|
//Create image
|
||||||
t := time.Now()
|
t = time.Now()
|
||||||
imageName, err := createImage(svc, instanceID)
|
imageName, err := createImage(svc, instanceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error creating image:\t", err)
|
fmt.Println("Error creating image:\t", err)
|
||||||
|
@ -39,23 +39,18 @@ func (c ProxyCommandStatus) Execute(url netip.AddrPort) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
|
requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
|
||||||
fmt.Println(requestURL)
|
|
||||||
bodyReader := bytes.NewReader(data)
|
bodyReader := bytes.NewReader(data)
|
||||||
|
|
||||||
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
|
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(res)
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
fmt.Println(string(body))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != 202 {
|
if res.StatusCode != 200 {
|
||||||
return errors.New(fmt.Sprintf("error processing command: (%d) %s\n", res.StatusCode, body))
|
return errors.New(fmt.Sprintf("error processing command: (%d) %s\n", res.StatusCode, body))
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
@ -90,18 +85,13 @@ func (c ProxyCommandCreate) Execute(url netip.AddrPort) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
|
requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
|
||||||
fmt.Println(requestURL)
|
|
||||||
bodyReader := bytes.NewReader(data)
|
bodyReader := bytes.NewReader(data)
|
||||||
|
|
||||||
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
|
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(res)
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
fmt.Println(string(body))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
||||||
}
|
}
|
||||||
@ -146,11 +136,7 @@ func (c ProxyCommandModify) Execute(url netip.AddrPort) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(res)
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
fmt.Println(string(body))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
||||||
}
|
}
|
||||||
@ -193,11 +179,7 @@ func (c ProxyCommandDelete) Execute(url netip.AddrPort) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
return errors.New(fmt.Sprintf("error making http request: %s\n", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(res)
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
fmt.Println(string(body))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
return errors.New(fmt.Sprintf("error reading response: %s\n", err))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user