-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2e876f
commit 8123a5d
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// Zone is an interface defining API behaviour for zones | ||
type Zone interface { | ||
Get(name string) (*entity.Zone, error) | ||
Update(name string, params *entity.ZoneParams) (*entity.Zone, error) | ||
Delete(name string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// Zones is an interface for listing and creating Zone objects | ||
type Zones interface { | ||
Get() ([]entity.Zone, error) | ||
Create(params *entity.ZoneParams) (*entity.Zone, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"net/url" | ||
|
||
"github.com/google/go-querystring/query" | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// Zone Contains functionality for manipulating the Zone entity. | ||
type Zone struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (z *Zone) client(name string) APIClient { | ||
return z.APIClient.GetSubObject("zones").GetSubObject(name) | ||
} | ||
|
||
// Get Zone details. | ||
func (z *Zone) Get(name string) (*entity.Zone, error) { | ||
zone := new(entity.Zone) | ||
err := z.client(name).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, zone) | ||
}) | ||
|
||
return zone, err | ||
} | ||
|
||
// Update Zone. | ||
func (z *Zone) Update(name string, params *entity.ZoneParams) (*entity.Zone, error) { | ||
qsp, err := query.Values(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
zone := new(entity.Zone) | ||
err = z.client(name).Put(qsp, func(data []byte) error { | ||
return json.Unmarshal(data, zone) | ||
}) | ||
|
||
return zone, err | ||
} | ||
|
||
// Delete Zone. | ||
func (z *Zone) Delete(name string) error { | ||
return z.client(name).Delete() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//nolint:dupl // disable dupl check on client for now | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"net/url" | ||
|
||
"github.com/google/go-querystring/query" | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// Zones implements api.Zones | ||
type Zones struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (z *Zones) client() APIClient { | ||
return z.APIClient.GetSubObject("zones") | ||
} | ||
|
||
// Get fetches a list of Zone objects | ||
func (z *Zones) Get() ([]entity.Zone, error) { | ||
zones := make([]entity.Zone, 0) | ||
err := z.client().Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, &zones) | ||
}) | ||
|
||
return zones, err | ||
} | ||
|
||
// Create creates a new Zone | ||
func (z *Zones) Create(params *entity.ZoneParams) (*entity.Zone, error) { | ||
qsp, err := query.Values(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
zone := new(entity.Zone) | ||
err = z.client().Post("", qsp, func(data []byte) error { | ||
return json.Unmarshal(data, zone) | ||
}) | ||
|
||
return zone, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters