forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beats CM now handle the new response format from Kibana. (elastic#11377)
Format is defined in elastic/kibana#27408 Main objective is to easier bubbling or errors and messages. ``` export interface ReturnType { error?: { message: string; code?: number; }; success: boolean; } ```
- Loading branch information
Showing
12 changed files
with
107 additions
and
42 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
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
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
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
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
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,53 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package api | ||
|
||
import "fmt" | ||
|
||
// Action are the actions executed on the API. | ||
type Action int | ||
|
||
// List of the valid Actions executed by the API. | ||
//go:generate stringer -type=LicenseType -linecomment=true | ||
const ( | ||
Created Action = iota + 1 // created | ||
) | ||
|
||
var mapStringToAction = map[string]Action{ | ||
"created": Created, | ||
} | ||
|
||
// UnmarshalJSON unmarshal an action string into a constant. | ||
func (a *Action) UnmarshalJSON(b []byte) error { | ||
k := string(b) | ||
if len(b) <= 2 { | ||
return fmt.Errorf( | ||
"invalid string for action type, received: '%s'", | ||
k, | ||
) | ||
} | ||
v, found := mapStringToAction[k[1:len(k)-1]] | ||
if !found { | ||
return fmt.Errorf( | ||
"unknown action '%s' returned from the API, valid actions are: 'created'", | ||
k, | ||
) | ||
} | ||
*a = v | ||
return nil | ||
} | ||
|
||
// BaseResponse the common response from all the API calls. | ||
type BaseResponse struct { | ||
Action Action `json:"action,omitempty"` | ||
Success bool `json:"success"` | ||
Error ErrorResponse `json:"error,omitempty"` | ||
} | ||
|
||
// ErrorResponse contains human readable and machine readable information when an error happens. | ||
type ErrorResponse struct { | ||
Message string `json:"message"` | ||
Code int `json:"code"` | ||
} |
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