Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project replacing IntString to Int #19

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

Todas as modificações desse projeto devem ser adicionadas a esse arquivo.

O formato foi baseado em [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
e o projeto está seguindo o versionamento conforme [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.2] - 27/12/2024

### Fix

- Alterado IsGateway e ExcludePing para BoolInt

## [0.3.0] - 08/10/2024

### Fix

- Adicionado função GetSubnetsByVlan


## [0.2.3] - 17/07/2024

### Fix

- Ajustado Subnet.GatewayId de string para int

### Fix

- Removido anotação ",string" das structs com int
- Criado função BoolInt e substituido BoolIntString
- Ajustado testes unitários
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![GoDoc](https://godoc.org/github.com/pavel-z1/phpipam-sdk-go?status.svg)](https://godoc.org/github.com/pavel-z1/phpipam-sdk-go)
[![GoDoc](https://godoc.org/github.com/lucasdk3/phpipam-sdk-go?status.svg)](https://godoc.org/github.com/lucasdk3/phpipam-sdk-go)

# phpipam-sdk-go - Partial SDK for PHPIPAM

Expand All @@ -15,7 +15,7 @@ provider to help insert data gathered from AWS and beyond.

See the [GoDoc][2] for the SDK usage details.

[2]: https://godoc.org/github.com/pavel-z1/phpipam-sdk-go
[2]: https://godoc.org/github.com/lucasdk3/phpipam-sdk-go

## A Note on Custom Fields

Expand Down
32 changes: 16 additions & 16 deletions controllers/addresses/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ package addresses
import (
"fmt"

"github.com/pavel-z1/phpipam-sdk-go/phpipam"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/client"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/session"
"github.com/lucasdk3/phpipam-sdk-go/phpipam"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/client"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/session"
)

// Address represents an IP address resource within PHPIPAM.
type Address struct {
// The ID of the IP address entry within PHPIPAM.
ID int `json:"id,string,omitempty"`
ID int `json:"id,omitempty"`

// The ID of the subnet that the address belongs to.
SubnetID int `json:"subnetId,string,omitempty"`
SubnetID int `json:"subnetId,omitempty"`

// The IP address, without a CIDR subnet mask.
IPAddress string `json:"ip,omitempty"`

// true if this IP address is a gateway address.
IsGateway phpipam.BoolIntString `json:"is_gateway,omitempty"`
IsGateway phpipam.BoolInt `json:"is_gateway,omitempty"`

// A detailed description of the IP address entry.
Description string `json:"description,omitempty"`
Expand All @@ -37,16 +37,16 @@ type Address struct {
Owner string `json:"owner,omitempty"`

// The tag ID for the IP address.
Tag int `json:"tag,string,omitempty"`
Tag int `json:"tag,omitempty"`

// true if PTR records should not be created for this IP address.
PTRIgnore phpipam.BoolIntString `json:"PTRIgnore,omitempty"`
PTRIgnore phpipam.BoolInt `json:"PTRIgnore,omitempty"`

// The ID of a PowerDNS PTR record.
PTRRecordID int `json:"PTR,string,omitempty"`
PTRRecordID int `json:"PTR,omitempty"`

// An ID of a device that this address belongs to.
DeviceID int `json:"deviceId,string,omitempty"`
DeviceID int `json:"deviceId,omitempty"`

// A switchport number/label that this IP address belongs to.
Port string `json:"port,omitempty"`
Expand All @@ -59,7 +59,7 @@ type Address struct {
LastSeen string `json:"lastSeen,omitempty"`

// true if you want to exclude this address from ping scans.
ExcludePing phpipam.BoolIntString `json:"excludePing,omitempty"`
ExcludePing phpipam.BoolInt `json:"excludePing,omitempty"`

// The date of the last edit to this resource.
EditDate string `json:"editDate,omitempty"`
Expand Down Expand Up @@ -93,8 +93,8 @@ func (c *Controller) CreateAddress(in Address) (message string, err error) {

// CreateAddress creates a first free in subnet address by sending a POST request.
func (c *Controller) CreateFirstFreeAddress(id int, in Address) (out string, err error) {
err = c.SendRequest("POST", fmt.Sprintf("/addresses/first_free/%d/", id), &in, &out)
return
err = c.SendRequest("POST", fmt.Sprintf("/addresses/first_free/%d/", id), &in, &out)
return
}

// GetAddressByID GETs an address via its ID.
Expand All @@ -114,9 +114,9 @@ func (c *Controller) GetAddressesByIP(ipaddr string) (out []Address, err error)

// GetAddressesByIP searches for an address by its IP with in given subnet
// When having multiple subnets with same ip range this will return the address in the given subnet
// Those subnet may not talk to each other but still exist under on phpIPAM instance especially on ones migrated from previous versions
func (c *Controller) GetAddressesByIpInSubnet(ipaddr string,subnetID int) (out Address, err error) {
err = c.SendRequest("GET", fmt.Sprintf("/addresses/%s/%d", ipaddr,subnetID), &struct{}{}, &out)
// Those subnet may not talk to each other but still exist under on phpIPAM instance especially on ones migrated from previous versions
func (c *Controller) GetAddressesByIpInSubnet(ipaddr string, subnetID int) (out Address, err error) {
err = c.SendRequest("GET", fmt.Sprintf("/addresses/%s/%d", ipaddr, subnetID), &struct{}{}, &out)
return
}

Expand Down
40 changes: 19 additions & 21 deletions controllers/addresses/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"reflect"
"testing"

"github.com/pavel-z1/phpipam-sdk-go/phpipam"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/session"
"github.com/pavel-z1/phpipam-sdk-go/testacc"
"github.com/lucasdk3/phpipam-sdk-go/phpipam"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/session"
"github.com/lucasdk3/phpipam-sdk-go/testacc"
)

var testCreateAddressInput = Address{
Expand Down Expand Up @@ -41,22 +41,22 @@ const testGetAddressByIDOutputJSON = `
"code": 200,
"success": true,
"data": {
"id": "11",
"subnetId": "3",
"id": 11,
"subnetId": 3,
"ip": "10.10.1.10",
"is_gateway": null,
"description": "foobar",
"hostname": null,
"mac": null,
"owner": null,
"tag": "2",
"tag": 2,
"deviceId": null,
"port": null,
"note": null,
"lastSeen": null,
"excludePing": null,
"PTRignore": null,
"PTR": "0",
"PTR": 0,
"firewallAddressObject": null,
"editDate": null,
"links": [
Expand All @@ -83,7 +83,7 @@ const testGetAddressByIDOutputJSON = `
`

var testGetAddressesByIPOutputExpected = []Address{
Address{
{
ID: 11,
SubnetID: 3,
IPAddress: "10.10.1.10",
Expand All @@ -98,22 +98,22 @@ const testGetAddressesByIPOutputJSON = `
"success": true,
"data": [
{
"id": "11",
"subnetId": "3",
"id": 11,
"subnetId": 3,
"ip": "10.10.1.10",
"is_gateway": null,
"description": "foobar",
"hostname": null,
"mac": null,
"owner": null,
"tag": "2",
"tag": 2,
"deviceId": null,
"port": null,
"note": null,
"lastSeen": null,
"excludePing": null,
"PTRignore": null,
"PTR": "0",
"PTR": 0,
"firewallAddressObject": null,
"editDate": null,
"links": [
Expand All @@ -128,11 +128,10 @@ const testGetAddressesByIPOutputJSON = `
`

var testGetAddressesByIpInSubnetOutputExpected = Address{
ID: 11,
ID: 1,
SubnetID: 3,
IPAddress: "10.10.1.10",
Description: "foobar",

}

const testGetAddressesByIpInSubnetOutputJSON = `
Expand All @@ -141,8 +140,8 @@ const testGetAddressesByIpInSubnetOutputJSON = `
"success": true,
"data":
{
"id": "11",
"subnetId": "3",
"id": 1,
"subnetId": 3,
"ip": "10.10.1.10",
"is_gateway": null,
"description": "foobar",
Expand All @@ -154,7 +153,7 @@ const testGetAddressesByIpInSubnetOutputJSON = `
"lastSeen": null,
"excludePing": null,
"PTRignore": null,
"PTR": "0",
"PTR": 0,
"firewallAddressObject": null,
"editDate": null,
"links": [
Expand All @@ -168,14 +167,14 @@ const testGetAddressesByIpInSubnetOutputJSON = `
`

var testGetAddressCustomFieldsSchemaExpected = map[string]phpipam.CustomField{
"CustomTestAddresses": phpipam.CustomField{
"CustomTestAddresses": {
Name: "CustomTestAddresses",
Type: "varchar(255)",
Comment: "Test field for addresses controller",
Null: "YES",
Default: "",
},
"CustomTestAddresses2": phpipam.CustomField{
"CustomTestAddresses2": {
Name: "CustomTestAddresses2",
Type: "varchar(255)",
Comment: "Test field for addresses controller (second field)",
Expand Down Expand Up @@ -325,7 +324,7 @@ func TestGetAddressesByIpInSubnet(t *testing.T) {
client := NewController(sess)

expected := testGetAddressesByIpInSubnetOutputExpected
actual, err := client.GetAddressesByIpInSubnet("10.10.1.10/24",3)
actual, err := client.GetAddressesByIpInSubnet("10.10.1.10/24", 3)
if err != nil {
t.Fatalf("Bad: %s", err)
}
Expand All @@ -335,7 +334,6 @@ func TestGetAddressesByIpInSubnet(t *testing.T) {
}
}


func TestGetAddressCustomFieldsSchema(t *testing.T) {
ts := httpOKTestServer(testGetAddressCustomFieldsSchemaJSON)
defer ts.Close()
Expand Down
10 changes: 5 additions & 5 deletions controllers/l2domains/l2domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package l2domains
import (
"fmt"

"github.com/pavel-z1/phpipam-sdk-go/controllers/vlans"
//"github.com/pavel-z1/phpipam-sdk-go/phpipam"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/client"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/session"
"github.com/lucasdk3/phpipam-sdk-go/controllers/vlans"
//"github.com/lucasdk3/phpipam-sdk-go/phpipam"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/client"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/session"
)

// L2Domain represents a PHPIPAM l2domain.
type L2Domain struct {
// The L2 domain ID.
ID int `json:"id,string,omitempty"`
ID int `json:"id,omitempty"`

// The L2 domains name.
Name string `json:"name,omitempty"`
Expand Down
22 changes: 11 additions & 11 deletions controllers/sections/sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package sections
import (
"fmt"

"github.com/pavel-z1/phpipam-sdk-go/controllers/subnets"
"github.com/pavel-z1/phpipam-sdk-go/phpipam"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/client"
"github.com/pavel-z1/phpipam-sdk-go/phpipam/session"
"github.com/lucasdk3/phpipam-sdk-go/controllers/subnets"
"github.com/lucasdk3/phpipam-sdk-go/phpipam"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/client"
"github.com/lucasdk3/phpipam-sdk-go/phpipam/session"
)

// Section represents a PHPIPAM section.
type Section struct {
// The section ID.
ID int `json:"id,string,omitempty"`
ID int `json:"id,omitempty"`

// The section's name.
Name string `json:"name,omitempty"`
Expand All @@ -23,7 +23,7 @@ type Section struct {
Description string `json:"description,omitempty"`

// The ID of the section's parent, if nested.
MasterSection int `json:"masterSection,string,omitempty"`
MasterSection int `json:"masterSection,omitempty"`

// A JSON object, stringified, that represents the permissions for this
// section.
Expand All @@ -36,24 +36,24 @@ type Section struct {
SubnetOrdering string `json:"subnetOrdering,omitempty"`

// The order position of this section when displaying sections.
Order int `json:"order,string,omitempty"`
Order int `json:"order,omitempty"`

// The date of the last edit to this resource.
EditDate string `json:"editDate,omitempty"`

// Whether or not to show VLANs in the subnet listing of this section.
ShowVLAN phpipam.BoolIntString `json:"showVLAN,omitempty"`
ShowVLAN phpipam.BoolInt `json:"showVLAN,omitempty"`

// Whether or not to show VRF information in the subnet listing of this
// section.
ShowVRF phpipam.BoolIntString `json:"showVRF,omitempty"`
ShowVRF phpipam.BoolInt `json:"showVRF,omitempty"`

// Whether or not to show only supernets in the subnet listing of this
// section.
ShowSupernetOnly phpipam.BoolIntString `json:"showSupernetOnly,omitempty"`
ShowSupernetOnly phpipam.BoolInt `json:"showSupernetOnly,omitempty"`

// The ID of the DNS resolver to be used for this section.
DNS int `json:"DNS,string,omitempty"`
DNS int `json:"DNS,omitempty"`
}

// Controller is the base client for the Sections controller.
Expand Down
Loading