mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Clean up code and make the state/http behavior more consistent
This commit is contained in:
parent
ce4d9fb3c2
commit
6cdea5af5d
@ -115,14 +115,15 @@ func (c *HTTPClient) Lock(info *state.LockInfo) (string, error) {
|
|||||||
}
|
}
|
||||||
c.lockID = ""
|
c.lockID = ""
|
||||||
|
|
||||||
base := c.URL.String()
|
url := *c.URL
|
||||||
if base[len(base)-1] != byte('/') {
|
path := url.Path
|
||||||
|
if len(path) == 0 || path[len(path)-1] != byte('/') {
|
||||||
// add a trailing /
|
// add a trailing /
|
||||||
base = fmt.Sprintf("%s/", base)
|
path = fmt.Sprintf("%s/", path)
|
||||||
}
|
}
|
||||||
|
url.Path = fmt.Sprintf("%slock", path)
|
||||||
|
|
||||||
url := fmt.Sprintf("%slock", base)
|
resp, err := c.httpPost(url.String(), info.Marshal(), "lock")
|
||||||
resp, err := c.httpPost(url, info.Marshal(), "lock")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -158,14 +159,22 @@ func (c *HTTPClient) Unlock(id string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
base := c.URL.String()
|
// copy the target URL
|
||||||
if base[len(base)-1] != byte('/') {
|
url := *c.URL
|
||||||
|
path := url.Path
|
||||||
|
if len(path) == 0 || path[len(path)-1] != byte('/') {
|
||||||
// add a trailing /
|
// add a trailing /
|
||||||
base = fmt.Sprintf("%s/", base)
|
path = fmt.Sprintf("%s/", path)
|
||||||
|
}
|
||||||
|
url.Path = fmt.Sprintf("%sunlock", path)
|
||||||
|
|
||||||
|
if c.SupportsLocking {
|
||||||
|
query := url.Query()
|
||||||
|
query.Set("ID", id)
|
||||||
|
url.RawQuery = query.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%sunlock", base)
|
resp, err := c.httpPost(url.String(), []byte{}, "unlock")
|
||||||
resp, err := c.httpPost(url, []byte{}, "unlock")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -255,7 +264,7 @@ func (c *HTTPClient) Put(data []byte) error {
|
|||||||
|
|
||||||
if c.SupportsLocking {
|
if c.SupportsLocking {
|
||||||
query := base.Query()
|
query := base.Query()
|
||||||
query.Set("lock_id", c.lockID)
|
query.Set("ID", c.lockID)
|
||||||
base.RawQuery = query.Encode()
|
base.RawQuery = query.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user