Permalink
Browse files

Reintroduce consistent tagging to all apiserver param structures.

All serialisation tags are lower case, with words separated by dashes.
*Error return values are now consistently omitempty.
  • Loading branch information...
1 parent 0edd506 commit 769aeb4b45068389a88f9fef34f3d61915d28562 @howbazaar howbazaar committed Jun 21, 2016
View
@@ -237,16 +237,11 @@ func (c *Client) ModelUserInfo() ([]params.ModelUserInfo, error) {
return info, nil
}
-// WatchAll holds the id of the newly-created AllWatcher/AllModelWatcher.
-type WatchAll struct {
- AllWatcherId string
-}
-
// WatchAll returns an AllWatcher, from which you can request the Next
// collection of Deltas.
func (c *Client) WatchAll() (*AllWatcher, error) {
- info := new(WatchAll)
- if err := c.facade.FacadeCall("WatchAll", nil, info); err != nil {
+ var info params.AllWatcherId
+ if err := c.facade.FacadeCall("WatchAll", nil, &info); err != nil {
return nil, err
}
return NewAllWatcher(c.st, &info.AllWatcherId), nil
@@ -92,8 +92,8 @@ func (c *Client) RemoveBlocks() error {
// WatchAllModels returns an AllWatcher, from which you can request
// the Next collection of Deltas (for all models).
func (c *Client) WatchAllModels() (*api.AllWatcher, error) {
- info := new(api.WatchAll)
- if err := c.facade.FacadeCall("WatchAllModels", nil, info); err != nil {
+ var info params.AllWatcherId
+ if err := c.facade.FacadeCall("WatchAllModels", nil, &info); err != nil {
return nil, err
}
return api.NewAllModelWatcher(c.facade.RawAPICaller(), &info.AllWatcherId), nil
View
@@ -126,7 +126,7 @@ func unmarshalHTTPErrorResponse(resp *http.Response) error {
// and determine the expected error type from that, but that
// seems more fragile than this approach.
type genericErrorResponse struct {
- Error json.RawMessage
+ Error json.RawMessage `json:"error"`
}
var generic genericErrorResponse
if err := json.Unmarshal(body, &generic); err != nil {
View
@@ -73,8 +73,8 @@ var httpClientTests = []struct {
about: "bad charms error response",
handler: func(w http.ResponseWriter, req *http.Request) {
type badResponse struct {
- Error string
- CharmURL map[string]int
+ Error string `json:"error"`
+ CharmURL map[string]int `json:"charm-url"`
}
httprequest.WriteJSON(w, http.StatusUnauthorized, badResponse{
Error: "something",
@@ -150,17 +150,17 @@ func (s *httpSuite) TestHTTPClient(c *gc.C) {
}
err := s.client.Get("/", resp)
if test.expectError != "" {
- c.Assert(err, gc.ErrorMatches, test.expectError)
- c.Assert(params.ErrCode(err), gc.Equals, test.expectErrorCode)
+ c.Check(err, gc.ErrorMatches, test.expectError)
+ c.Check(params.ErrCode(err), gc.Equals, test.expectErrorCode)
if err, ok := errors.Cause(err).(*params.Error); ok {
- c.Assert(err.Info, jc.DeepEquals, test.expectErrorInfo)
+ c.Check(err.Info, jc.DeepEquals, test.expectErrorInfo)
} else if test.expectErrorInfo != nil {
c.Fatalf("no error info found in error")
}
continue
}
- c.Assert(err, gc.IsNil)
- c.Assert(resp, jc.DeepEquals, test.expectResponse)
+ c.Check(err, gc.IsNil)
+ c.Check(resp, jc.DeepEquals, test.expectResponse)
}
}
View
@@ -92,12 +92,26 @@ func (api *AgentAPIV2) getEntity(tag names.Tag) (result params.AgentGetEntitiesR
return
}
-func (api *AgentAPIV2) StateServingInfo() (result state.StateServingInfo, err error) {
+func (api *AgentAPIV2) StateServingInfo() (result params.StateServingInfo, err error) {
if !api.auth.AuthModelManager() {
err = common.ErrPerm
return
}
- return api.st.StateServingInfo()
+ info, err := api.st.StateServingInfo()
+ if err != nil {
+ return params.StateServingInfo{}, errors.Trace(err)
+ }
+ result = params.StateServingInfo{
+ APIPort: info.APIPort,
+ StatePort: info.StatePort,
+ Cert: info.Cert,
+ PrivateKey: info.PrivateKey,
+ CAPrivateKey: info.CAPrivateKey,
+ SharedSecret: info.SharedSecret,
+ SystemIdentity: info.SystemIdentity,
+ }
+
+ return result, nil
}
// MongoIsMaster is called by the IsMaster API call
@@ -11,6 +11,7 @@ import (
"time"
"github.com/juju/errors"
+ "github.com/juju/loggo"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/series"
"github.com/juju/version"
@@ -625,6 +626,7 @@ func (s *clientRepoSuite) TearDownTest(c *gc.C) {
}
func (s *clientSuite) TestClientWatchAll(c *gc.C) {
+ loggo.GetLogger("juju.apiserver").SetLogLevel(loggo.TRACE)
// A very simple end-to-end test, because
// all the logic is tested elsewhere.
m, err := s.State.AddMachine("quantal", state.JobManageModel)
@@ -115,7 +115,7 @@ type ActionExecutionResults struct {
// ActionExecutionResult holds the action tag and output used when
// recording the result of an action.
type ActionExecutionResult struct {
- ActionTag string `json:"actiontag"`
+ ActionTag string `json:"action-tag"`
Status string `json:"status"`
Results map[string]interface{} `json:"results,omitempty"`
Message string `json:"message,omitempty"`
@@ -131,7 +131,7 @@ type ApplicationsCharmActionsResults struct {
// If an error such as a missing charm or malformed application name occurs, it
// is encapsulated in this type.
type ApplicationCharmActionsResult struct {
- ApplicationTag string `json:"ApplicationTag,omitempty"`
+ ApplicationTag string `json:"application-tag,omitempty"`
Actions *charm.Actions `json:"actions,omitempty"`
Error *Error `json:"error,omitempty"`
}
@@ -5,23 +5,23 @@ package params
// AnnotationsGetResult holds entity annotations or retrieval error.
type AnnotationsGetResult struct {
- EntityTag string
- Annotations map[string]string
- Error ErrorResult
+ EntityTag string `json:"entity"`
+ Annotations map[string]string `json:"annotations"`
+ Error ErrorResult `json:"error,omitempty"`
}
// AnnotationsGetResults holds annotations associated with entities.
type AnnotationsGetResults struct {
- Results []AnnotationsGetResult
+ Results []AnnotationsGetResult `json:"results"`
}
// AnnotationsSet stores parameters for making Set call on Annotations client.
type AnnotationsSet struct {
- Annotations []EntityAnnotations
+ Annotations []EntityAnnotations `json:"annotations"`
}
// EntityAnnotations stores annotations for an entity.
type EntityAnnotations struct {
- EntityTag string
- Annotations map[string]string
+ EntityTag string `json:"entity"`
+ Annotations map[string]string `json:"annotations"`
}
@@ -15,9 +15,9 @@ var UpgradeInProgressError = errors.New(CodeUpgradeInProgress)
// Error is the type of error returned by any call to the state API.
type Error struct {
- Message string
- Code string
- Info *ErrorInfo `json:",omitempty"`
+ Message string `json:"message"`
+ Code string `json:"code"`
+ Info *ErrorInfo `json:"info,omitempty"`
}
// ErrorInfo holds additional information provided by an error.
@@ -31,14 +31,14 @@ type ErrorInfo struct {
// discharged, may allow access to the juju API.
// This field is associated with the ErrDischargeRequired
// error code.
- Macaroon *macaroon.Macaroon `json:",omitempty"`
+ Macaroon *macaroon.Macaroon `json:"macaroon,omitempty"`
// MacaroonPath holds the URL path to be associated
// with the macaroon. The macaroon is potentially
// valid for all URLs under the given path.
// If it is empty, the macaroon will be associated with
// the original URL from which the error was returned.
- MacaroonPath string `json:",omitempty"`
+ MacaroonPath string `json:"macaroon-path,omitempty"`
}
func (e Error) Error() string {
@@ -11,12 +11,12 @@ import (
// BackupsCreateArgs holds the args for the API Create method.
type BackupsCreateArgs struct {
- Notes string
+ Notes string `json:"notes"`
}
// BackupsInfoArgs holds the args for the API Info method.
type BackupsInfoArgs struct {
- ID string
+ ID string `json:"id"`
}
// BackupsListArgs holds the args for the API List method.
@@ -25,55 +25,55 @@ type BackupsListArgs struct {
// BackupsDownloadArgs holds the args for the API Download method.
type BackupsDownloadArgs struct {
- ID string
+ ID string `json:"id"`
}
// BackupsUploadArgs holds the args for the API Upload method.
type BackupsUploadArgs struct {
- Data []byte
- Metadata BackupsMetadataResult
+ Data []byte `json:"data"`
+ Metadata BackupsMetadataResult `json:"metadata"`
}
// BackupsRemoveArgs holds the args for the API Remove method.
type BackupsRemoveArgs struct {
- ID string
+ ID string `json:"id"`
}
// BackupsListResult holds the list of all stored backups.
type BackupsListResult struct {
- List []BackupsMetadataResult
+ List []BackupsMetadataResult `json:"list"`
}
// BackupsListResult holds the list of all stored backups.
type BackupsUploadResult struct {
- ID string
+ ID string `json:"id"`
}
// BackupsMetadataResult holds the metadata for a backup as returned by
// an API backups method (such as Create).
type BackupsMetadataResult struct {
- ID string
-
- Checksum string
- ChecksumFormat string
- Size int64
- Stored time.Time // May be zero...
-
- Started time.Time
- Finished time.Time // May be zero...
- Notes string
- Model string
- Machine string
- Hostname string
- Version version.Number
- Series string
-
- CACert string
- CAPrivateKey string
+ ID string `json:"id"`
+
+ Checksum string `json:"checksum"`
+ ChecksumFormat string `json:"checksum-format"`
+ Size int64 `json:"size"`
+ Stored time.Time `json:"stored"` // May be zero...
+
+ Started time.Time `json:"started"`
+ Finished time.Time `json:"finished"` // May be zero...
+ Notes string `json:"notes"`
+ Model string `json:"model"`
+ Machine string `json:"machine"`
+ Hostname string `json:"hostname"`
+ Version version.Number `json:"version"`
+ Series string `json:"series"`
+
+ CACert string `json:"ca-cert"`
+ CAPrivateKey string `json:"ca-private-key"`
}
// RestoreArgs Holds the backup file or id
type RestoreArgs struct {
// BackupId holds the id of the backup in server if any
- BackupId string
+ BackupId string `json:"backup-id"`
}
@@ -5,20 +5,20 @@ package params
// CharmInfo stores parameters for a charms.CharmInfo call.
type CharmInfo struct {
- CharmURL string
+ CharmURL string `json:"charm-url"`
}
// CharmsList stores parameters for a charms.List call
type CharmsList struct {
- Names []string
+ Names []string `json:"names"`
}
// CharmsListResult stores result from a charms.List call
type CharmsListResult struct {
- CharmURLs []string
+ CharmURLs []string `json:"charm-urls"`
}
// IsMeteredResult stores result from a charms.IsMetered call
type IsMeteredResult struct {
- Metered bool
+ Metered bool `json:"metered"`
}
@@ -22,7 +22,7 @@ type ImageMetadataFilter struct {
Stream string `json:"stream,omitempty"`
// VirtType stores virtualisation type.
- VirtType string `json:"virt_type,omitempty"`
+ VirtType string `json:"virt-type,omitempty"`
// RootStorageType stores storage type.
RootStorageType string `json:"root-storage-type,omitempty"`
@@ -31,7 +31,7 @@ type ImageMetadataFilter struct {
// CloudImageMetadata holds cloud image metadata properties.
type CloudImageMetadata struct {
// ImageId is an image identifier.
- ImageId string `json:"image_id"`
+ ImageId string `json:"image-id"`
// Stream contains reference to a particular stream,
// for e.g. "daily" or "released"
@@ -50,13 +50,13 @@ type CloudImageMetadata struct {
Arch string `json:"arch"`
// VirtType contains the virtualisation type of the cloud image, for e.g. "pv", "hvm". "kvm".
- VirtType string `json:"virt_type,omitempty"`
+ VirtType string `json:"virt-type,omitempty"`
// RootStorageType contains type of root storage, for e.g. "ebs", "instance".
- RootStorageType string `json:"root_storage_type,omitempty"`
+ RootStorageType string `json:"root-storage-type,omitempty"`
// RootStorageSize contains size of root storage in gigabytes (GB).
- RootStorageSize *uint64 `json:"root_storage_size,omitempty"`
+ RootStorageSize *uint64 `json:"root-storage-size,omitempty"`
// Source describes where this image is coming from: is it public? custom?
Source string `json:"source"`
@@ -85,5 +85,5 @@ type CloudImageMetadataList struct {
// MetadataImageIds holds image ids and can be used to identify related image metadata.
type MetadataImageIds struct {
- Ids []string `json:"image_ids"`
+ Ids []string `json:"image-ids"`
}
Oops, something went wrong.

0 comments on commit 769aeb4

Please sign in to comment.