-
Notifications
You must be signed in to change notification settings - Fork 28
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
6353a21
commit bdada2c
Showing
9 changed files
with
154 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" | ||
) | ||
|
||
// PackageRepositories is an interface for listing and creating | ||
// Package Repository records | ||
type PackageRepositories interface { | ||
Get() ([]entity.PackageRepository, error) | ||
Create(params *entity.PackageRepositoryParams) (*entity.PackageRepository, 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,12 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// PackageRepository represents the MAAS Server Package Repository endpoint | ||
type PackageRepository interface { | ||
Get(id int) (*entity.PackageRepository, error) | ||
Update(id int, params *entity.PackageRepositoryParams) (*entity.PackageRepository, error) | ||
Delete(id int) 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//nolint:dupl // disable dupl check on client for now | ||
package client | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//nolint:dupl // disable dupl check on client for now | ||
package client | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//nolint:dupl // disable dupl check on client for now | ||
package client | ||
|
||
import ( | ||
|
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" | ||
) | ||
|
||
// PackageRepositories implements api.PackageRepositories | ||
type PackageRepositories struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (p *PackageRepositories) client() APIClient { | ||
return p.APIClient.GetSubObject("package-repositories") | ||
} | ||
|
||
// Get fetches a list of PackageRepositories | ||
func (p *PackageRepositories) Get() ([]entity.PackageRepository, error) { | ||
packageRepositories := make([]entity.PackageRepository, 0) | ||
err := p.client().Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, &packageRepositories) | ||
}) | ||
|
||
return packageRepositories, err | ||
} | ||
|
||
// Create creates a new PackageRepository | ||
func (p *PackageRepositories) Create(packageRepositoryParams *entity.PackageRepositoryParams) (*entity.PackageRepository, error) { | ||
qsp, err := query.Values(packageRepositoryParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
packageRepository := new(entity.PackageRepository) | ||
err = p.client().Post("", qsp, func(data []byte) error { | ||
return json.Unmarshal(data, packageRepository) | ||
}) | ||
|
||
return packageRepository, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//nolint:dupl // disable dupl check on client for now | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/google/go-querystring/query" | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// PackageRepository implements api.PackageRepository | ||
type PackageRepository struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (p *PackageRepository) client(id int) APIClient { | ||
return p.APIClient.GetSubObject("package-repositories").GetSubObject(fmt.Sprintf("%v", id)) | ||
} | ||
|
||
// Get fetches a packageRepository | ||
func (p *PackageRepository) Get(id int) (*entity.PackageRepository, error) { | ||
packageRepository := new(entity.PackageRepository) | ||
err := p.client(id).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, packageRepository) | ||
}) | ||
|
||
return packageRepository, err | ||
} | ||
|
||
// Update updates a given PackageRepository | ||
func (p *PackageRepository) Update(id int, packageRepositoryParams *entity.PackageRepositoryParams) (*entity.PackageRepository, error) { | ||
qsp, err := query.Values(packageRepositoryParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
packageRepository := new(entity.PackageRepository) | ||
err = p.client(id).Put(qsp, func(data []byte) error { | ||
return json.Unmarshal(data, packageRepository) | ||
}) | ||
|
||
return packageRepository, err | ||
} | ||
|
||
// Delete deletes a given PackageRepository | ||
func (p *PackageRepository) Delete(id int) error { | ||
return p.client(id).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,29 @@ | ||
package entity | ||
|
||
type PackageRepository struct { | ||
Name string `json:"name,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
Key string `json:"key,omitempty"` | ||
ResourceURI string `json:"resource_uri,omitempty"` | ||
Distributions []string `json:"distributions,omitempty"` | ||
DisabledPockets []string `json:"disabled_pockets,omitempty"` | ||
DisabledComponents []string `json:"disabled_components,omitempty"` | ||
Components []string `json:"components,omitempty"` | ||
Arches []string `json:"arches,omitempty"` | ||
ID int `json:"id,omitempty"` | ||
DisableSources bool `json:"disable_sources,omitempty"` | ||
Enabled bool `json:"enabled,omitempty"` | ||
} | ||
|
||
type PackageRepositoryParams struct { | ||
Name string `url:"name,omitempty"` | ||
URL string `url:"url,omitempty"` | ||
Distributions string `url:"distributions,omitempty"` | ||
DisabledPockets string `url:"disabled_pockets,omitempty"` | ||
DisabledComponents string `url:"disabled_components,omitempty"` | ||
Components string `url:"components,omitempty"` | ||
Arches string `url:"arches,omitempty"` | ||
Key string `url:"key,omitempty"` | ||
DisableSources bool `url:"disable_sources,omitempty"` | ||
Enabled bool `url:"enabled,omitempty"` | ||
} |