forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade test (LTS): utility functions to support ent users (hashicorp…
…#20186) * upgrade test (LTS): utility functions to support ent users * go mod tidy * add comment
- Loading branch information
Showing
6 changed files
with
103 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package topoutil | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
// RequestRegisterService registers a service at the given node address | ||
// using consul http request. | ||
// | ||
// The service definition must be a JSON string. | ||
func RequestRegisterService(clusterHttpCli *http.Client, nodeAddress string, serviceDefinition string, token string) error { | ||
var js json.RawMessage | ||
if err := json.Unmarshal([]byte(serviceDefinition), &js); err != nil { | ||
return fmt.Errorf("failed to unmarshal service definition: %s", err) | ||
} | ||
|
||
u, err := url.Parse(nodeAddress) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse node address: %s", err) | ||
} | ||
u.Path = "/v1/agent/service/register" | ||
|
||
req, err := http.NewRequest(http.MethodPut, u.String(), bytes.NewBuffer(js)) | ||
if err != nil { | ||
return fmt.Errorf("failed to create request: %s", err) | ||
} | ||
|
||
if token != "" { | ||
req.Header.Set("X-Consul-Token", token) | ||
} | ||
|
||
resp, err := clusterHttpCli.Do(req) | ||
if err != nil { | ||
return fmt.Errorf("failed to send request: %s", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return fmt.Errorf("failed to register service: %s", resp.Status) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters