mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
* Remove `make updatedeps` from Travis build. We'll follow up with more specific plans around dependency updating in subsequent PRs. * Update all `make` targets to set `GO15VENDOREXPERIMENT=1` and to filter out `/vendor/` from `./...` where appropriate. * Temporarily remove `vet` from the `make test` target until we can figure out how to get it to not vet `vendor/`. (Initial experimentation failed to yield the proper incantation.) Everything is pinned to current master, with the exception of: * Azure/azure-sdk-for-go which is pinned before the breaking change today * aws/aws-sdk-go which is pinned to the most recent tag The documentation still needs to be updated, which we can do in a follow up PR. The goal here is to unblock release.
93 lines
3.1 KiB
Go
93 lines
3.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// FileServiceClient contains operations for Microsoft Azure File Service.
|
|
type FileServiceClient struct {
|
|
client Client
|
|
}
|
|
|
|
// pathForFileShare returns the URL path segment for a File Share resource
|
|
func pathForFileShare(name string) string {
|
|
return fmt.Sprintf("/%s", name)
|
|
}
|
|
|
|
// CreateShare operation creates a new share under the specified account. If the
|
|
// share with the same name already exists, the operation fails.
|
|
//
|
|
// See https://msdn.microsoft.com/en-us/library/azure/dn167008.aspx
|
|
func (f FileServiceClient) CreateShare(name string) error {
|
|
resp, err := f.createShare(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.body.Close()
|
|
return checkRespCode(resp.statusCode, []int{http.StatusCreated})
|
|
}
|
|
|
|
// CreateShareIfNotExists creates a new share under the specified account if
|
|
// it does not exist. Returns true if container is newly created or false if
|
|
// container already exists.
|
|
//
|
|
// See https://msdn.microsoft.com/en-us/library/azure/dn167008.aspx
|
|
func (f FileServiceClient) CreateShareIfNotExists(name string) (bool, error) {
|
|
resp, err := f.createShare(name)
|
|
if resp != nil {
|
|
defer resp.body.Close()
|
|
if resp.statusCode == http.StatusCreated || resp.statusCode == http.StatusConflict {
|
|
return resp.statusCode == http.StatusCreated, nil
|
|
}
|
|
}
|
|
return false, err
|
|
}
|
|
|
|
// CreateShare creates a Azure File Share and returns its response
|
|
func (f FileServiceClient) createShare(name string) (*storageResponse, error) {
|
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{"restype": {"share"}})
|
|
headers := f.client.getStandardHeaders()
|
|
headers["Content-Length"] = "0"
|
|
return f.client.exec("PUT", uri, headers, nil)
|
|
}
|
|
|
|
// DeleteShare operation marks the specified share for deletion. The share
|
|
// and any files contained within it are later deleted during garbage
|
|
// collection.
|
|
//
|
|
// See https://msdn.microsoft.com/en-us/library/azure/dn689090.aspx
|
|
func (f FileServiceClient) DeleteShare(name string) error {
|
|
resp, err := f.deleteShare(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.body.Close()
|
|
return checkRespCode(resp.statusCode, []int{http.StatusAccepted})
|
|
}
|
|
|
|
// DeleteShareIfExists operation marks the specified share for deletion if it
|
|
// exists. The share and any files contained within it are later deleted during
|
|
// garbage collection. Returns true if share existed and deleted with this call,
|
|
// false otherwise.
|
|
//
|
|
// See https://msdn.microsoft.com/en-us/library/azure/dn689090.aspx
|
|
func (f FileServiceClient) DeleteShareIfExists(name string) (bool, error) {
|
|
resp, err := f.deleteShare(name)
|
|
if resp != nil {
|
|
defer resp.body.Close()
|
|
if resp.statusCode == http.StatusAccepted || resp.statusCode == http.StatusNotFound {
|
|
return resp.statusCode == http.StatusAccepted, nil
|
|
}
|
|
}
|
|
return false, err
|
|
}
|
|
|
|
// deleteShare makes the call to Delete Share operation endpoint and returns
|
|
// the response
|
|
func (f FileServiceClient) deleteShare(name string) (*storageResponse, error) {
|
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{"restype": {"share"}})
|
|
return f.client.exec("DELETE", uri, f.client.getStandardHeaders(), nil)
|
|
}
|