Skip to content

Commit

Permalink
Service Resource Changes (#106)
Browse files Browse the repository at this point in the history
* Service Resource Changes
  • Loading branch information
Krunal-Thakkar authored Feb 29, 2024
1 parent 83a8183 commit 502845a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func New(

c.http.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: pool,
RootCAs: pool,
// #nosec G402
InsecureSkipVerify: opts.Insecure,
InsecureSkipVerify: opts.Insecure,
},
}
}
Expand Down
20 changes: 10 additions & 10 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ func NewGateway(host string, username, password string, insecure, useCerts bool)
username: username,
password: password,
}
if insecure {
gc.http.Transport = &http.Transport{

if insecure {
gc.http.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
// #nosec G402
InsecureSkipVerify: true,
InsecureSkipVerify: true,
},
}
}
if !insecure || useCerts {

if !insecure || useCerts {
pool, err := x509.SystemCertPool()
if err != nil {
return nil, errSysCerts
}

gc.http.Transport = &http.Transport{
gc.http.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: pool,
RootCAs: pool,
// #nosec G402
InsecureSkipVerify: insecure,
InsecureSkipVerify: insecure,
},
}
}
Expand Down Expand Up @@ -1264,7 +1264,7 @@ func writeConfig(config *CookieConfig) error {
if err != nil {
return err
}
// #nosec G306
// #nosec G306
err = ioutil.WriteFile(configFile, data, 0644)
if err != nil {
return err
Expand Down
19 changes: 14 additions & 5 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ func (gc *GatewayClient) DeployService(deploymentName, deploymentDesc, serviceTe
return nil, fmt.Errorf("Error While Parsing Response Data For Template: %s", parseError)
}

configuredNode, _ := templateData["serverCount"].(int)
configuredNode, _ := templateData["serverCount"].(float64)

configuredNodeCount := int(configuredNode)

nodes, _ := strconv.Atoi(nodes)

if nodes > 0 {
nodeDiff := nodes - configuredNode
nodeDiff := nodes - configuredNodeCount

if nodeDiff != 0 {
return nil, fmt.Errorf("Node count is not matching with Service Template")
Expand Down Expand Up @@ -260,14 +262,21 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
// Find the component with type "SERVER"
var serverComponent map[string]interface{}

componentFound := false

for _, comp := range components {
comp := comp.(map[string]interface{})
if comp["type"].(string) == "SERVER" && comp["name"].(string) == nodename {
serverComponent = comp
componentFound = true
break
}
}

if !componentFound {
return nil, fmt.Errorf("Host to clone from not found")
}

for numberOfNode := 1; numberOfNode <= nodeDiff; numberOfNode++ {

// Deep copy the component
Expand Down Expand Up @@ -385,7 +394,7 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD

deploymentPayloadJson, _ = json.Marshal(deploymentResponse)
} else if nodeDiff < 0 {
return nil, fmt.Errorf("node difference should be more than or equal 1")
return nil, fmt.Errorf("Removing node(s) is not supported")
}

req, httpError := http.NewRequest("PUT", gc.host+"/Api/V1/Deployment/"+deploymentID, bytes.NewBuffer(deploymentPayloadJson))
Expand Down Expand Up @@ -672,15 +681,15 @@ func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error)
}
}

func (gc *GatewayClient) DeleteService(serviceId string) (*types.ServiceResponse, error) {
func (gc *GatewayClient) DeleteService(serviceId, serversInInventory, serversManagedState string) (*types.ServiceResponse, error) {

var deploymentResponse types.ServiceResponse

deploymentResponse.StatusCode = 400

defer TimeSpent("DeleteService", time.Now())

req, httpError := http.NewRequest("DELETE", gc.host+"/Api/V1/Deployment/"+serviceId+"?serversInInventory=remove&resourceState=managed", nil)
req, httpError := http.NewRequest("DELETE", gc.host+"/Api/V1/Deployment/"+serviceId+"?serversInInventory="+serversInInventory+"&resourceState="+serversManagedState, nil)
if httpError != nil {
return nil, httpError
}
Expand Down

0 comments on commit 502845a

Please sign in to comment.