mirror of https://github.com/grafana/loki
fix(deps): update github.com/prometheus/prometheus (main) (#15950)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Paul Rogers <paul.rogers@grafana.com>pull/16402/head
parent
5b16c0be7d
commit
b37eefe24f
@ -0,0 +1,29 @@ |
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package log |
||||
|
||||
import ( |
||||
"log/slog" |
||||
|
||||
"github.com/go-kit/log" |
||||
slgk "github.com/tjhop/slog-gokit" |
||||
) |
||||
|
||||
// SlogFromGoKit returns slog adapter for logger.
|
||||
func SlogFromGoKit(logger log.Logger) *slog.Logger { |
||||
var sl slog.Level |
||||
switch logLevel.String() { |
||||
case "info": |
||||
sl = slog.LevelInfo |
||||
case "warn": |
||||
sl = slog.LevelWarn |
||||
case "error": |
||||
sl = slog.LevelError |
||||
default: |
||||
sl = slog.LevelDebug |
||||
} |
||||
|
||||
lvl := slog.LevelVar{} |
||||
lvl.Set(sl) |
||||
return slog.New(slgk.NewGoKitHandler(logger, &lvl)) |
||||
} |
||||
@ -0,0 +1,96 @@ |
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package log |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"log/slog" |
||||
"testing" |
||||
|
||||
"github.com/go-kit/log/level" |
||||
"github.com/stretchr/testify/assert" |
||||
"github.com/stretchr/testify/mock" |
||||
"github.com/stretchr/testify/require" |
||||
) |
||||
|
||||
type mockLogger struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
func (m *mockLogger) Log(keyvals ...interface{}) error { |
||||
args := m.Called(keyvals...) |
||||
return args.Error(0) |
||||
} |
||||
|
||||
func TestSlogFromGoKit(t *testing.T) { |
||||
levels := []level.Value{ |
||||
level.DebugValue(), |
||||
level.InfoValue(), |
||||
level.WarnValue(), |
||||
level.ErrorValue(), |
||||
} |
||||
slogLevels := []slog.Level{ |
||||
slog.LevelDebug, |
||||
slog.LevelInfo, |
||||
slog.LevelWarn, |
||||
slog.LevelError, |
||||
} |
||||
|
||||
// Store original log level to restore after tests
|
||||
originalLevel := logLevel.String() |
||||
t.Cleanup(func() { |
||||
_ = logLevel.Set(originalLevel) |
||||
}) |
||||
|
||||
t.Run("enabled for the right slog levels when go-kit level configured", func(t *testing.T) { |
||||
for i, l := range levels { |
||||
switch i { |
||||
case 0: |
||||
require.NoError(t, logLevel.Set("debug")) |
||||
case 1: |
||||
require.NoError(t, logLevel.Set("info")) |
||||
case 2: |
||||
require.NoError(t, logLevel.Set("warn")) |
||||
case 3: |
||||
require.NoError(t, logLevel.Set("error")) |
||||
default: |
||||
panic(fmt.Errorf("unhandled level %d", i)) |
||||
} |
||||
|
||||
mLogger := &mockLogger{} |
||||
logger := level.NewFilter(mLogger, logLevel.Option) |
||||
slogger := SlogFromGoKit(logger) |
||||
|
||||
for j, sl := range slogLevels { |
||||
if j >= i { |
||||
assert.Truef(t, slogger.Enabled(context.Background(), sl), "slog logger should be enabled for go-kit level %v / slog level %v", l, sl) |
||||
} else { |
||||
assert.Falsef(t, slogger.Enabled(context.Background(), sl), "slog logger should not be enabled for go-kit level %v / slog level %v", l, sl) |
||||
} |
||||
} |
||||
} |
||||
}) |
||||
|
||||
t.Run("wraps go-kit logger", func(_ *testing.T) { |
||||
mLogger := &mockLogger{} |
||||
slogger := SlogFromGoKit(mLogger) |
||||
|
||||
for _, l := range levels { |
||||
mLogger.On("Log", level.Key(), l, "caller", mock.AnythingOfType("string"), "time", mock.AnythingOfType("time.Time"), "msg", "test", "attr", slog.StringValue("value")).Times(1).Return(nil) |
||||
attrs := []any{"attr", "value"} |
||||
switch l { |
||||
case level.DebugValue(): |
||||
slogger.Debug("test", attrs...) |
||||
case level.InfoValue(): |
||||
slogger.Info("test", attrs...) |
||||
case level.WarnValue(): |
||||
slogger.Warn("test", attrs...) |
||||
case level.ErrorValue(): |
||||
slogger.Error("test", attrs...) |
||||
default: |
||||
panic(fmt.Errorf("unrecognized level %v", l)) |
||||
} |
||||
} |
||||
}) |
||||
} |
||||
2
vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared/constants.go
generated
vendored
2
vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared/constants.go
generated
vendored
@ -0,0 +1,20 @@ |
||||
# Breaking Changes |
||||
|
||||
## v1.8.0 |
||||
|
||||
### New errors from `NewManagedIdentityCredential` in some environments |
||||
|
||||
`NewManagedIdentityCredential` now returns an error when `ManagedIdentityCredentialOptions.ID` is set in a hosting environment whose managed identity API doesn't support user-assigned identities. `ManagedIdentityCredential.GetToken()` formerly logged a warning in these cases. Returning an error instead prevents the credential authenticating an unexpected identity. The affected hosting environments are: |
||||
* Azure Arc |
||||
* Azure ML (when a resource or object ID is specified; client IDs are supported) |
||||
* Cloud Shell |
||||
* Service Fabric |
||||
|
||||
## v1.6.0 |
||||
|
||||
### Behavioral change to `DefaultAzureCredential` in IMDS managed identity scenarios |
||||
|
||||
As of `azidentity` v1.6.0, `DefaultAzureCredential` makes a minor behavioral change when it uses IMDS managed |
||||
identity. It sends its first request to IMDS without the "Metadata" header, to expedite validating whether the endpoint |
||||
is available. This precedes the credential's first token request and is guaranteed to fail with a 400 error. This error |
||||
response can appear in logs but doesn't indicate authentication failed. |
||||
18
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/authentication_record.go
generated
vendored
18
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/authentication_record.go
generated
vendored
6
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/azure_cli_credential.go
generated
vendored
6
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/azure_cli_credential.go
generated
vendored
31
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/azure_pipelines_credential.go
generated
vendored
31
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/azure_pipelines_credential.go
generated
vendored
24
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/chained_token_credential.go
generated
vendored
24
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/chained_token_credential.go
generated
vendored
16
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/client_assertion_credential.go
generated
vendored
16
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/client_assertion_credential.go
generated
vendored
18
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/client_certificate_credential.go
generated
vendored
18
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/client_certificate_credential.go
generated
vendored
14
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/client_secret_credential.go
generated
vendored
14
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/client_secret_credential.go
generated
vendored
18
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/confidential_client.go
generated
vendored
18
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/confidential_client.go
generated
vendored
23
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/default_azure_credential.go
generated
vendored
23
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/default_azure_credential.go
generated
vendored
43
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/device_code_credential.go
generated
vendored
43
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/device_code_credential.go
generated
vendored
@ -0,0 +1,86 @@ |
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package internal |
||||
|
||||
import ( |
||||
"sync" |
||||
|
||||
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/cache" |
||||
) |
||||
|
||||
// Cache represents a persistent cache that makes authentication data available across processes.
|
||||
// Construct one with [github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache.New]. This package's
|
||||
// [persistent user authentication example] shows how to use a persistent cache to reuse user
|
||||
// logins across application runs. For service principal credential types such as
|
||||
// [ClientCertificateCredential], simply set the Cache field on the credential options.
|
||||
//
|
||||
// [persistent user authentication example]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#example-package-PersistentUserAuthentication
|
||||
type Cache struct { |
||||
// impl is a pointer so a Cache can carry persistent state across copies
|
||||
impl *impl |
||||
} |
||||
|
||||
// impl is a Cache's private implementation
|
||||
type impl struct { |
||||
// factory constructs storage implementations
|
||||
factory func(bool) (cache.ExportReplace, error) |
||||
// cae and noCAE are previously constructed storage implementations. CAE
|
||||
// and non-CAE tokens must be stored separately because MSAL's cache doesn't
|
||||
// observe token claims. If a single storage implementation held both kinds
|
||||
// of tokens, it could create a reauthentication or error loop by returning
|
||||
// a non-CAE token lacking a required claim.
|
||||
cae, noCAE cache.ExportReplace |
||||
// mu synchronizes around cae and noCAE
|
||||
mu *sync.RWMutex |
||||
} |
||||
|
||||
func (i *impl) exportReplace(cae bool) (cache.ExportReplace, error) { |
||||
if i == nil { |
||||
// zero-value Cache: return a nil ExportReplace and MSAL will cache in memory
|
||||
return nil, nil |
||||
} |
||||
var ( |
||||
err error |
||||
xr cache.ExportReplace |
||||
) |
||||
i.mu.RLock() |
||||
xr = i.cae |
||||
if !cae { |
||||
xr = i.noCAE |
||||
} |
||||
i.mu.RUnlock() |
||||
if xr != nil { |
||||
return xr, nil |
||||
} |
||||
i.mu.Lock() |
||||
defer i.mu.Unlock() |
||||
if cae { |
||||
if i.cae == nil { |
||||
if xr, err = i.factory(cae); err == nil { |
||||
i.cae = xr |
||||
} |
||||
} |
||||
return i.cae, err |
||||
} |
||||
if i.noCAE == nil { |
||||
if xr, err = i.factory(cae); err == nil { |
||||
i.noCAE = xr |
||||
} |
||||
} |
||||
return i.noCAE, err |
||||
} |
||||
|
||||
// NewCache is the constructor for Cache. It takes a factory instead of an instance
|
||||
// because it doesn't know whether the Cache will store both CAE and non-CAE tokens.
|
||||
func NewCache(factory func(cae bool) (cache.ExportReplace, error)) Cache { |
||||
return Cache{&impl{factory: factory, mu: &sync.RWMutex{}}} |
||||
} |
||||
|
||||
// ExportReplace returns an implementation satisfying MSAL's ExportReplace interface.
|
||||
// It's a function instead of a method on Cache so packages in azidentity and
|
||||
// azidentity/cache can call it while applications can't. "cae" declares whether the
|
||||
// caller intends this implementation to store CAE tokens.
|
||||
func ExportReplace(c Cache, cae bool) (cache.ExportReplace, error) { |
||||
return c.impl.exportReplace(cae) |
||||
} |
||||
@ -1,18 +0,0 @@ |
||||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package internal |
||||
|
||||
// TokenCachePersistenceOptions contains options for persistent token caching
|
||||
type TokenCachePersistenceOptions struct { |
||||
// AllowUnencryptedStorage controls whether the cache should fall back to storing its data in plain text
|
||||
// when encryption isn't possible. Setting this true doesn't disable encryption. The cache always attempts
|
||||
// encryption before falling back to plaintext storage.
|
||||
AllowUnencryptedStorage bool |
||||
|
||||
// Name identifies the cache. Set this to isolate data from other applications.
|
||||
Name string |
||||
} |
||||
@ -1,31 +0,0 @@ |
||||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package internal |
||||
|
||||
import ( |
||||
"errors" |
||||
|
||||
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/cache" |
||||
) |
||||
|
||||
var errMissingImport = errors.New("import github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache to enable persistent caching") |
||||
|
||||
// NewCache constructs a persistent token cache when "o" isn't nil. Applications that intend to
|
||||
// use a persistent cache must first import the cache module, which will replace this function
|
||||
// with a platform-specific implementation.
|
||||
var NewCache = func(o *TokenCachePersistenceOptions, enableCAE bool) (cache.ExportReplace, error) { |
||||
if o == nil { |
||||
return nil, nil |
||||
} |
||||
return nil, errMissingImport |
||||
} |
||||
|
||||
// CacheFilePath returns the path to the cache file for the given name.
|
||||
// Defining it in this package makes it available to azidentity tests.
|
||||
var CacheFilePath = func(name string) (string, error) { |
||||
return "", errMissingImport |
||||
} |
||||
163
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/managed_identity_client.go
generated
vendored
163
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/managed_identity_client.go
generated
vendored
52
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/managed_identity_credential.go
generated
vendored
52
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/managed_identity_credential.go
generated
vendored
40
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/test-resources-post.ps1
generated
vendored
40
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/test-resources-post.ps1
generated
vendored
28
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/username_password_credential.go
generated
vendored
28
vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/username_password_credential.go
generated
vendored
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,258 @@ |
||||
package godo |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"net/http" |
||||
"time" |
||||
) |
||||
|
||||
const ( |
||||
dropletAutoscaleBasePath = "/v2/droplets/autoscale" |
||||
) |
||||
|
||||
// DropletAutoscaleService defines an interface for managing droplet autoscale pools through DigitalOcean API
|
||||
type DropletAutoscaleService interface { |
||||
Create(context.Context, *DropletAutoscalePoolRequest) (*DropletAutoscalePool, *Response, error) |
||||
Get(context.Context, string) (*DropletAutoscalePool, *Response, error) |
||||
List(context.Context, *ListOptions) ([]*DropletAutoscalePool, *Response, error) |
||||
ListMembers(context.Context, string, *ListOptions) ([]*DropletAutoscaleResource, *Response, error) |
||||
ListHistory(context.Context, string, *ListOptions) ([]*DropletAutoscaleHistoryEvent, *Response, error) |
||||
Update(context.Context, string, *DropletAutoscalePoolRequest) (*DropletAutoscalePool, *Response, error) |
||||
Delete(context.Context, string) (*Response, error) |
||||
DeleteDangerous(context.Context, string) (*Response, error) |
||||
} |
||||
|
||||
// DropletAutoscalePool represents a DigitalOcean droplet autoscale pool
|
||||
type DropletAutoscalePool struct { |
||||
ID string `json:"id"` |
||||
Name string `json:"name"` |
||||
Config *DropletAutoscaleConfiguration `json:"config"` |
||||
DropletTemplate *DropletAutoscaleResourceTemplate `json:"droplet_template"` |
||||
CreatedAt time.Time `json:"created_at"` |
||||
UpdatedAt time.Time `json:"updated_at"` |
||||
CurrentUtilization *DropletAutoscaleResourceUtilization `json:"current_utilization,omitempty"` |
||||
Status string `json:"status"` |
||||
} |
||||
|
||||
// DropletAutoscaleConfiguration represents a DigitalOcean droplet autoscale pool configuration
|
||||
type DropletAutoscaleConfiguration struct { |
||||
MinInstances uint64 `json:"min_instances,omitempty"` |
||||
MaxInstances uint64 `json:"max_instances,omitempty"` |
||||
TargetCPUUtilization float64 `json:"target_cpu_utilization,omitempty"` |
||||
TargetMemoryUtilization float64 `json:"target_memory_utilization,omitempty"` |
||||
CooldownMinutes uint32 `json:"cooldown_minutes,omitempty"` |
||||
TargetNumberInstances uint64 `json:"target_number_instances,omitempty"` |
||||
} |
||||
|
||||
// DropletAutoscaleResourceTemplate represents a DigitalOcean droplet autoscale pool resource template
|
||||
type DropletAutoscaleResourceTemplate struct { |
||||
Size string `json:"size"` |
||||
Region string `json:"region"` |
||||
Image string `json:"image"` |
||||
Tags []string `json:"tags"` |
||||
SSHKeys []string `json:"ssh_keys"` |
||||
VpcUUID string `json:"vpc_uuid"` |
||||
WithDropletAgent bool `json:"with_droplet_agent"` |
||||
ProjectID string `json:"project_id"` |
||||
IPV6 bool `json:"ipv6"` |
||||
UserData string `json:"user_data"` |
||||
} |
||||
|
||||
// DropletAutoscaleResourceUtilization represents a DigitalOcean droplet autoscale pool resource utilization
|
||||
type DropletAutoscaleResourceUtilization struct { |
||||
Memory float64 `json:"memory,omitempty"` |
||||
CPU float64 `json:"cpu,omitempty"` |
||||
} |
||||
|
||||
// DropletAutoscaleResource represents a DigitalOcean droplet autoscale pool resource
|
||||
type DropletAutoscaleResource struct { |
||||
DropletID uint64 `json:"droplet_id"` |
||||
CreatedAt time.Time `json:"created_at"` |
||||
UpdatedAt time.Time `json:"updated_at"` |
||||
HealthStatus string `json:"health_status"` |
||||
UnhealthyReason string `json:"unhealthy_reason,omitempty"` |
||||
Status string `json:"status"` |
||||
CurrentUtilization *DropletAutoscaleResourceUtilization `json:"current_utilization,omitempty"` |
||||
} |
||||
|
||||
// DropletAutoscaleHistoryEvent represents a DigitalOcean droplet autoscale pool history event
|
||||
type DropletAutoscaleHistoryEvent struct { |
||||
HistoryEventID string `json:"history_event_id"` |
||||
CurrentInstanceCount uint64 `json:"current_instance_count"` |
||||
DesiredInstanceCount uint64 `json:"desired_instance_count"` |
||||
Reason string `json:"reason"` |
||||
Status string `json:"status"` |
||||
ErrorReason string `json:"error_reason,omitempty"` |
||||
CreatedAt time.Time `json:"created_at"` |
||||
UpdatedAt time.Time `json:"updated_at"` |
||||
} |
||||
|
||||
// DropletAutoscalePoolRequest represents a DigitalOcean droplet autoscale pool create/update request
|
||||
type DropletAutoscalePoolRequest struct { |
||||
Name string `json:"name"` |
||||
Config *DropletAutoscaleConfiguration `json:"config"` |
||||
DropletTemplate *DropletAutoscaleResourceTemplate `json:"droplet_template"` |
||||
} |
||||
|
||||
type dropletAutoscalePoolRoot struct { |
||||
AutoscalePool *DropletAutoscalePool `json:"autoscale_pool"` |
||||
} |
||||
|
||||
type dropletAutoscalePoolsRoot struct { |
||||
AutoscalePools []*DropletAutoscalePool `json:"autoscale_pools"` |
||||
Links *Links `json:"links"` |
||||
Meta *Meta `json:"meta"` |
||||
} |
||||
|
||||
type dropletAutoscaleMembersRoot struct { |
||||
Droplets []*DropletAutoscaleResource `json:"droplets"` |
||||
Links *Links `json:"links"` |
||||
Meta *Meta `json:"meta"` |
||||
} |
||||
|
||||
type dropletAutoscaleHistoryEventsRoot struct { |
||||
History []*DropletAutoscaleHistoryEvent `json:"history"` |
||||
Links *Links `json:"links"` |
||||
Meta *Meta `json:"meta"` |
||||
} |
||||
|
||||
// DropletAutoscaleServiceOp handles communication with droplet autoscale-related methods of the DigitalOcean API
|
||||
type DropletAutoscaleServiceOp struct { |
||||
client *Client |
||||
} |
||||
|
||||
var _ DropletAutoscaleService = &DropletAutoscaleServiceOp{} |
||||
|
||||
// Create a new droplet autoscale pool
|
||||
func (d *DropletAutoscaleServiceOp) Create(ctx context.Context, createReq *DropletAutoscalePoolRequest) (*DropletAutoscalePool, *Response, error) { |
||||
req, err := d.client.NewRequest(ctx, http.MethodPost, dropletAutoscaleBasePath, createReq) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
root := new(dropletAutoscalePoolRoot) |
||||
resp, err := d.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
return root.AutoscalePool, resp, nil |
||||
} |
||||
|
||||
// Get an existing droplet autoscale pool
|
||||
func (d *DropletAutoscaleServiceOp) Get(ctx context.Context, id string) (*DropletAutoscalePool, *Response, error) { |
||||
req, err := d.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s", dropletAutoscaleBasePath, id), nil) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
root := new(dropletAutoscalePoolRoot) |
||||
resp, err := d.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
return root.AutoscalePool, resp, err |
||||
} |
||||
|
||||
// List all existing droplet autoscale pools
|
||||
func (d *DropletAutoscaleServiceOp) List(ctx context.Context, opts *ListOptions) ([]*DropletAutoscalePool, *Response, error) { |
||||
path, err := addOptions(dropletAutoscaleBasePath, opts) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
req, err := d.client.NewRequest(ctx, http.MethodGet, path, nil) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
root := new(dropletAutoscalePoolsRoot) |
||||
resp, err := d.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
if root.Links != nil { |
||||
resp.Links = root.Links |
||||
} |
||||
if root.Meta != nil { |
||||
resp.Meta = root.Meta |
||||
} |
||||
return root.AutoscalePools, resp, err |
||||
} |
||||
|
||||
// ListMembers all members for an existing droplet autoscale pool
|
||||
func (d *DropletAutoscaleServiceOp) ListMembers(ctx context.Context, id string, opts *ListOptions) ([]*DropletAutoscaleResource, *Response, error) { |
||||
path, err := addOptions(fmt.Sprintf("%s/%s/members", dropletAutoscaleBasePath, id), opts) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
req, err := d.client.NewRequest(ctx, http.MethodGet, path, nil) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
root := new(dropletAutoscaleMembersRoot) |
||||
resp, err := d.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
if root.Links != nil { |
||||
resp.Links = root.Links |
||||
} |
||||
if root.Meta != nil { |
||||
resp.Meta = root.Meta |
||||
} |
||||
return root.Droplets, resp, err |
||||
} |
||||
|
||||
// ListHistory all history events for an existing droplet autoscale pool
|
||||
func (d *DropletAutoscaleServiceOp) ListHistory(ctx context.Context, id string, opts *ListOptions) ([]*DropletAutoscaleHistoryEvent, *Response, error) { |
||||
path, err := addOptions(fmt.Sprintf("%s/%s/history", dropletAutoscaleBasePath, id), opts) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
req, err := d.client.NewRequest(ctx, http.MethodGet, path, nil) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
root := new(dropletAutoscaleHistoryEventsRoot) |
||||
resp, err := d.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
if root.Links != nil { |
||||
resp.Links = root.Links |
||||
} |
||||
if root.Meta != nil { |
||||
resp.Meta = root.Meta |
||||
} |
||||
return root.History, resp, err |
||||
} |
||||
|
||||
// Update an existing autoscale pool
|
||||
func (d *DropletAutoscaleServiceOp) Update(ctx context.Context, id string, updateReq *DropletAutoscalePoolRequest) (*DropletAutoscalePool, *Response, error) { |
||||
req, err := d.client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("%s/%s", dropletAutoscaleBasePath, id), updateReq) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
root := new(dropletAutoscalePoolRoot) |
||||
resp, err := d.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
return root.AutoscalePool, resp, nil |
||||
} |
||||
|
||||
// Delete an existing autoscale pool
|
||||
func (d *DropletAutoscaleServiceOp) Delete(ctx context.Context, id string) (*Response, error) { |
||||
req, err := d.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s", dropletAutoscaleBasePath, id), nil) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return d.client.Do(ctx, req, nil) |
||||
} |
||||
|
||||
// DeleteDangerous deletes an existing autoscale pool with all underlying resources
|
||||
func (d *DropletAutoscaleServiceOp) DeleteDangerous(ctx context.Context, id string) (*Response, error) { |
||||
req, err := d.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s/dangerous", dropletAutoscaleBasePath, id), nil) |
||||
req.Header.Set("X-Dangerous", "true") |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return d.client.Do(ctx, req, nil) |
||||
} |
||||
@ -0,0 +1,135 @@ |
||||
package godo |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"net/http" |
||||
"time" |
||||
) |
||||
|
||||
const resourceV6Type = "ReservedIPv6" |
||||
const reservedIPV6sBasePath = "v2/reserved_ipv6" |
||||
|
||||
// ReservedIPV6sService is an interface for interfacing with the reserved IPV6s
|
||||
// endpoints of the Digital Ocean API.
|
||||
type ReservedIPV6sService interface { |
||||
List(context.Context, *ListOptions) ([]ReservedIPV6, *Response, error) |
||||
Get(context.Context, string) (*ReservedIPV6, *Response, error) |
||||
Create(context.Context, *ReservedIPV6CreateRequest) (*ReservedIPV6, *Response, error) |
||||
Delete(context.Context, string) (*Response, error) |
||||
} |
||||
|
||||
// ReservedIPV6sServiceOp handles communication with the reserved IPs related methods of the
|
||||
// DigitalOcean API.
|
||||
type ReservedIPV6sServiceOp struct { |
||||
client *Client |
||||
} |
||||
|
||||
var _ ReservedIPV6sService = (*ReservedIPV6sServiceOp)(nil) |
||||
|
||||
// ReservedIPV6 represents a Digital Ocean reserved IP.
|
||||
type ReservedIPV6 struct { |
||||
RegionSlug string `json:"region_slug"` |
||||
IP string `json:"ip"` |
||||
ReservedAt time.Time `json:"reserved_at"` |
||||
Droplet *Droplet `json:"droplet,omitempty"` |
||||
} |
||||
type reservedIPV6Root struct { |
||||
ReservedIPV6 *ReservedIPV6 `json:"reserved_ipv6"` |
||||
} |
||||
|
||||
type reservedIPV6sRoot struct { |
||||
ReservedIPV6s []ReservedIPV6 `json:"reserved_ipv6s"` |
||||
Links *Links `json:"links"` |
||||
Meta *Meta `json:"meta"` |
||||
} |
||||
|
||||
func (f ReservedIPV6) String() string { |
||||
return Stringify(f) |
||||
} |
||||
|
||||
// URN returns the reserved IP in a valid DO API URN form.
|
||||
func (f ReservedIPV6) URN() string { |
||||
return ToURN(resourceV6Type, f.IP) |
||||
} |
||||
|
||||
// ReservedIPV6CreateRequest represents a request to reserve a reserved IP.
|
||||
type ReservedIPV6CreateRequest struct { |
||||
Region string `json:"region_slug,omitempty"` |
||||
} |
||||
|
||||
// List all reserved IPV6s.
|
||||
func (r *ReservedIPV6sServiceOp) List(ctx context.Context, opt *ListOptions) ([]ReservedIPV6, *Response, error) { |
||||
path := reservedIPV6sBasePath |
||||
path, err := addOptions(path, opt) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
|
||||
req, err := r.client.NewRequest(ctx, http.MethodGet, path, nil) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
|
||||
root := new(reservedIPV6sRoot) |
||||
resp, err := r.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
if root.Meta != nil { |
||||
resp.Meta = root.Meta |
||||
} |
||||
if root.Links != nil { |
||||
resp.Links = root.Links |
||||
} |
||||
|
||||
return root.ReservedIPV6s, resp, err |
||||
} |
||||
|
||||
// Get an individual reserved IPv6.
|
||||
func (r *ReservedIPV6sServiceOp) Get(ctx context.Context, ip string) (*ReservedIPV6, *Response, error) { |
||||
path := fmt.Sprintf("%s/%s", reservedIPV6sBasePath, ip) |
||||
|
||||
req, err := r.client.NewRequest(ctx, http.MethodGet, path, nil) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
|
||||
root := new(reservedIPV6Root) |
||||
resp, err := r.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, resp, err |
||||
} |
||||
|
||||
return root.ReservedIPV6, resp, err |
||||
} |
||||
|
||||
// Create a new IPv6
|
||||
func (r *ReservedIPV6sServiceOp) Create(ctx context.Context, reserveRequest *ReservedIPV6CreateRequest) (*ReservedIPV6, *Response, error) { |
||||
path := reservedIPV6sBasePath |
||||
|
||||
req, err := r.client.NewRequest(ctx, http.MethodPost, path, reserveRequest) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
|
||||
root := new(reservedIPV6Root) |
||||
resp, err := r.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, resp, err |
||||
} |
||||
|
||||
return root.ReservedIPV6, resp, err |
||||
} |
||||
|
||||
// Delete a reserved IPv6.
|
||||
func (r *ReservedIPV6sServiceOp) Delete(ctx context.Context, ip string) (*Response, error) { |
||||
path := fmt.Sprintf("%s/%s", reservedIPV6sBasePath, ip) |
||||
|
||||
req, err := r.client.NewRequest(ctx, http.MethodDelete, path, nil) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return r.client.Do(ctx, req, nil) |
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
package godo |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"net/http" |
||||
) |
||||
|
||||
// ReservedIPActionsService is an interface for interfacing with the
|
||||
// reserved IPs actions endpoints of the Digital Ocean API.
|
||||
// See: https://docs.digitalocean.com/reference/api/api-reference/#tag/Reserved-IP-Actions
|
||||
type ReservedIPV6ActionsService interface { |
||||
Assign(ctx context.Context, ip string, dropletID int) (*Action, *Response, error) |
||||
Unassign(ctx context.Context, ip string) (*Action, *Response, error) |
||||
} |
||||
|
||||
// ReservedIPActionsServiceOp handles communication with the reserved IPs
|
||||
// action related methods of the DigitalOcean API.
|
||||
type ReservedIPV6ActionsServiceOp struct { |
||||
client *Client |
||||
} |
||||
|
||||
// Assign a reserved IP to a droplet.
|
||||
func (s *ReservedIPV6ActionsServiceOp) Assign(ctx context.Context, ip string, dropletID int) (*Action, *Response, error) { |
||||
request := &ActionRequest{ |
||||
"type": "assign", |
||||
"droplet_id": dropletID, |
||||
} |
||||
return s.doV6Action(ctx, ip, request) |
||||
} |
||||
|
||||
// Unassign a rerserved IP from the droplet it is currently assigned to.
|
||||
func (s *ReservedIPV6ActionsServiceOp) Unassign(ctx context.Context, ip string) (*Action, *Response, error) { |
||||
request := &ActionRequest{"type": "unassign"} |
||||
return s.doV6Action(ctx, ip, request) |
||||
} |
||||
|
||||
func (s *ReservedIPV6ActionsServiceOp) doV6Action(ctx context.Context, ip string, request *ActionRequest) (*Action, *Response, error) { |
||||
path := reservedIPV6ActionPath(ip) |
||||
|
||||
req, err := s.client.NewRequest(ctx, http.MethodPost, path, request) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
|
||||
root := new(actionRoot) |
||||
resp, err := s.client.Do(ctx, req, root) |
||||
if err != nil { |
||||
return nil, resp, err |
||||
} |
||||
|
||||
return root.Event, resp, err |
||||
} |
||||
|
||||
func reservedIPV6ActionPath(ip string) string { |
||||
return fmt.Sprintf("%s/%s/actions", reservedIPV6sBasePath, ip) |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue