forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip_ranges.go
59 lines (49 loc) · 1.78 KB
/
ip_ranges.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tfe
import (
"context"
)
// Compile-time proof of interface implementation.
var _ IPRanges = (*ipRanges)(nil)
// IP Ranges provides a list of HCP Terraform or Terraform Enterprise's IP ranges.
//
// TFE API docs: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/ip-ranges
type IPRanges interface {
// Retrieve HCP Terraform IP ranges. If `modifiedSince` is not an empty string
// then it will only return the IP ranges changes since that date.
// The format for `modifiedSince` can be found here:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since
Read(ctx context.Context, modifiedSince string) (*IPRange, error)
}
// ipRanges implements IPRanges interface.
type ipRanges struct {
client *Client
}
// IPRange represents a list of HCP Terraform's IP ranges
type IPRange struct {
// List of IP ranges in CIDR notation used for connections from user site to HCP Terraform APIs
API []string `json:"api"`
// List of IP ranges in CIDR notation used for notifications
Notifications []string `json:"notifications"`
// List of IP ranges in CIDR notation used for outbound requests from Sentinel policies
Sentinel []string `json:"sentinel"`
// List of IP ranges in CIDR notation used for connecting to VCS providers
VCS []string `json:"vcs"`
}
// Read an IPRange that was not modified since the specified date.
func (i *ipRanges) Read(ctx context.Context, modifiedSince string) (*IPRange, error) {
req, err := i.client.NewRequest("GET", "/api/meta/ip-ranges", nil)
if err != nil {
return nil, err
}
if modifiedSince != "" {
req.Header.Add("If-Modified-Since", modifiedSince)
}
ir := &IPRange{}
err = req.DoJSON(ctx, ir)
if err != nil {
return nil, err
}
return ir, nil
}