mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 19:21:19 +00:00
da20785685
Former-commit-id: 23f542f43b4b493e38f5aa4c29788ed93a63b43b [formerly 71b23a6a28eb045fcfeab6329de69f1e5455486b] Former-commit-id: d12b3a6decc876f010a71f98e11df7387c1aaf2a
119 lines
2.6 KiB
Go
119 lines
2.6 KiB
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// ServiceProperties represents the storage account service properties
|
|
type ServiceProperties struct {
|
|
Logging *Logging
|
|
HourMetrics *Metrics
|
|
MinuteMetrics *Metrics
|
|
Cors *Cors
|
|
}
|
|
|
|
// Logging represents the Azure Analytics Logging settings
|
|
type Logging struct {
|
|
Version string
|
|
Delete bool
|
|
Read bool
|
|
Write bool
|
|
RetentionPolicy *RetentionPolicy
|
|
}
|
|
|
|
// RetentionPolicy indicates if retention is enabled and for how many days
|
|
type RetentionPolicy struct {
|
|
Enabled bool
|
|
Days *int
|
|
}
|
|
|
|
// Metrics provide request statistics.
|
|
type Metrics struct {
|
|
Version string
|
|
Enabled bool
|
|
IncludeAPIs *bool
|
|
RetentionPolicy *RetentionPolicy
|
|
}
|
|
|
|
// Cors includes all the CORS rules
|
|
type Cors struct {
|
|
CorsRule []CorsRule
|
|
}
|
|
|
|
// CorsRule includes all settings for a Cors rule
|
|
type CorsRule struct {
|
|
AllowedOrigins string
|
|
AllowedMethods string
|
|
MaxAgeInSeconds int
|
|
ExposedHeaders string
|
|
AllowedHeaders string
|
|
}
|
|
|
|
func (c Client) getServiceProperties(service string, auth authentication) (*ServiceProperties, error) {
|
|
query := url.Values{
|
|
"restype": {"service"},
|
|
"comp": {"properties"},
|
|
}
|
|
uri := c.getEndpoint(service, "", query)
|
|
headers := c.getStandardHeaders()
|
|
|
|
resp, err := c.exec(http.MethodGet, uri, headers, nil, auth)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.body.Close()
|
|
|
|
if err := checkRespCode(resp.statusCode, []int{http.StatusOK}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out ServiceProperties
|
|
err = xmlUnmarshal(resp.body, &out)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &out, nil
|
|
}
|
|
|
|
func (c Client) setServiceProperties(props ServiceProperties, service string, auth authentication) error {
|
|
query := url.Values{
|
|
"restype": {"service"},
|
|
"comp": {"properties"},
|
|
}
|
|
uri := c.getEndpoint(service, "", query)
|
|
|
|
// Ideally, StorageServiceProperties would be the output struct
|
|
// This is to avoid golint stuttering, while generating the correct XML
|
|
type StorageServiceProperties struct {
|
|
Logging *Logging
|
|
HourMetrics *Metrics
|
|
MinuteMetrics *Metrics
|
|
Cors *Cors
|
|
}
|
|
input := StorageServiceProperties{
|
|
Logging: props.Logging,
|
|
HourMetrics: props.HourMetrics,
|
|
MinuteMetrics: props.MinuteMetrics,
|
|
Cors: props.Cors,
|
|
}
|
|
|
|
body, length, err := xmlMarshal(input)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
headers := c.getStandardHeaders()
|
|
headers["Content-Length"] = fmt.Sprintf("%v", length)
|
|
|
|
resp, err := c.exec(http.MethodPut, uri, headers, body, auth)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer readAndCloseBody(resp.body)
|
|
|
|
return checkRespCode(resp.statusCode, []int{http.StatusAccepted})
|
|
}
|