Repository: mailgun/mailgun-go
Pull request #403 (2025-03-14 11:13:22)

DE-1501 Add support for the 'enabled' parameter in the ListIPs API call for v4
#400 for v4


Patch:
diff --git a/domains.go b/domains.go
index 54127f6..551ac66 100644
--- a/domains.go
+++ b/domains.go
@@ -271,8 +271,10 @@ type CreateDomainOptions struct {
 	Wildcard           bool
 	ForceDKIMAuthority bool
 	DKIMKeySize        int
-	IPS                []string
-	WebScheme          string
+	IPs                []string
+	// Deprecated: Use IPs instead.
+	IPS       []string
+	WebScheme string
 }
 
 // CreateDomain instructs Mailgun to create a new domain for your account.
@@ -305,6 +307,9 @@ func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *Crea
 		if len(opts.IPS) != 0 {
 			payload.addValue("ips", strings.Join(opts.IPS, ","))
 		}
+		if len(opts.IPs) != 0 {
+			payload.addValue("ips", strings.Join(opts.IPs, ","))
+		}
 		if opts.Password != "" {
 			payload.addValue("smtp_password", opts.Password)
 		}
diff --git a/examples/examples.go b/examples/examples.go
index 8c43abe..fe5291a 100644
--- a/examples/examples.go
+++ b/examples/examples.go
@@ -432,7 +432,7 @@ func ListDomainIPS(domain, apiKey string) ([]mailgun.IPAddress, error) {
 	ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
 	defer cancel()
 
-	return mg.ListDomainIPS(ctx)
+	return mg.ListDomainIPs(ctx)
 }
 
 func GetDomainTracking(domain, apiKey string) (mailgun.DomainTracking, error) {
diff --git a/ips.go b/ips.go
index a899168..6f42e57 100644
--- a/ips.go
+++ b/ips.go
@@ -18,7 +18,31 @@ type okResp struct {
 	Message string `json:"message"`
 }
 
+// ListIPs returns a list of IPs assigned to your account
+func (mg *MailgunImpl) ListIPs(ctx context.Context, dedicated, enabled bool) ([]IPAddress, error) {
+	r := newHTTPRequest(generatePublicApiUrl(mg, ipsEndpoint))
+	r.setClient(mg.Client())
+	if dedicated {
+		r.addParameter("dedicated", "true")
+	}
+	if enabled {
+		r.addParameter("enabled", "true")
+	}
+	r.setBasicAuth(basicAuthUser, mg.APIKey())
+
+	var resp ipAddressListResponse
+	if err := getResponseFromJSON(ctx, r, &resp); err != nil {
+		return nil, err
+	}
+	var result []IPAddress
+	for _, ip := range resp.Items {
+		result = append(result, IPAddress{IP: ip})
+	}
+	return result, nil
+}
+
 // ListIPS returns a list of IPs assigned to your account
+// Deprecated: use ListIPs instead
 func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress, error) {
 	r := newHTTPRequest(generatePublicApiUrl(mg, ipsEndpoint))
 	r.setClient(mg.Client())
@@ -48,8 +72,8 @@ func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error)
 	return resp, err
 }
 
-// ListDomainIPS returns a list of IPs currently assigned to the specified domain.
-func (mg *MailgunImpl) ListDomainIPS(ctx context.Context) ([]IPAddress, error) {
+// ListDomainIPs returns a list of IPs currently assigned to the specified domain.
+func (mg *MailgunImpl) ListDomainIPs(ctx context.Context) ([]IPAddress, error) {
 	r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + mg.domain + "/ips")
 	r.setClient(mg.Client())
 	r.setBasicAuth(basicAuthUser, mg.APIKey())
@@ -65,6 +89,12 @@ func (mg *MailgunImpl) ListDomainIPS(ctx context.Context) ([]IPAddress, error) {
 	return result, nil
 }
 
+// ListDomainIPS returns a list of IPs currently assigned to the specified domain.
+// Deprecated: use ListDomainIPs instead.
+func (mg *MailgunImpl) ListDomainIPS(ctx context.Context) ([]IPAddress, error) {
+	return mg.ListDomainIPs(ctx)
+}
+
 // Assign a dedicated IP to the domain specified.
 func (mg *MailgunImpl) AddDomainIP(ctx context.Context, ip string) error {
 	r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + mg.domain + "/ips")
diff --git a/mailgun.go b/mailgun.go
index e2e3aea..8b46807 100644
--- a/mailgun.go
+++ b/mailgun.go
@@ -233,8 +233,12 @@ type Mailgun interface {
 	ListEvents(*ListEventOptions) *EventIterator
 	PollEvents(*ListEventOptions) *EventPoller
 
+	ListIPs(ctx context.Context, dedicated, enabled bool) ([]IPAddress, error)
+	// Deprecated: use ListIPs instead
 	ListIPS(ctx context.Context, dedicated bool) ([]IPAddress, error)
 	GetIP(ctx context.Context, ip string) (IPAddress, error)
+	ListDomainIPs(ctx context.Context) ([]IPAddress, error)
+
 	ListDomainIPS(ctx context.Context) ([]IPAddress, error)
 	AddDomainIP(ctx context.Context, ip string) error
 	DeleteDomainIP(ctx context.Context, ip string) error


Test patch:
diff --git a/ips_test.go b/ips_test.go
index 4c1d200..e5bac10 100644
--- a/ips_test.go
+++ b/ips_test.go
@@ -36,7 +36,7 @@ func TestListIPS(t *testing.T) {
 	assert.Equal(t, "luna.mailgun.net", ip.RDNS)
 }
 
-func TestDomainIPS(t *testing.T) {
+func TestDomainIPs(t *testing.T) {
 	mg := mailgun.NewMailgun(testDomain, testKey)
 	mg.SetAPIBase(server.URL())
 
@@ -44,7 +44,7 @@ func TestDomainIPS(t *testing.T) {
 	err := mg.AddDomainIP(ctx, "192.172.1.1")
 	require.NoError(t, err)
 
-	list, err := mg.ListDomainIPS(ctx)
+	list, err := mg.ListDomainIPs(ctx)
 	require.NoError(t, err)
 
 	require.Len(t, list, 1)
@@ -53,7 +53,7 @@ func TestDomainIPS(t *testing.T) {
 	err = mg.DeleteDomainIP(ctx, "192.172.1.1")
 	require.NoError(t, err)
 
-	list, err = mg.ListDomainIPS(ctx)
+	list, err = mg.ListDomainIPs(ctx)
 	require.NoError(t, err)
 
 	require.Len(t, list, 0)