mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add comments to exported types to pass go-lint
This commit is contained in:
parent
be51da44bf
commit
161fc48b5a
@ -13,11 +13,13 @@ import (
|
|||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StackListFilter represents a filter for a stack list
|
||||||
type StackListFilter struct {
|
type StackListFilter struct {
|
||||||
SwarmID string `json:"SwarmId,omitempty"`
|
SwarmID string `json:"SwarmId,omitempty"`
|
||||||
EndpointID portainer.EndpointID `json:"EndpointId,omitempty"`
|
EndpointID portainer.EndpointID `json:"EndpointId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config represents a Portainer client configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
User string
|
User string
|
||||||
@ -27,6 +29,7 @@ type Config struct {
|
|||||||
DoNotUseToken bool
|
DoNotUseToken bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PortainerClient represents a Portainer API client
|
||||||
type PortainerClient interface {
|
type PortainerClient interface {
|
||||||
// Authenticate a user to get an auth token
|
// Authenticate a user to get an auth token
|
||||||
Authenticate() (token string, err error)
|
Authenticate() (token string, err error)
|
||||||
@ -305,7 +308,7 @@ func (n *portainerClientImp) GetStatus() (status portainer.Status, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new client
|
// NewClient creates a new Portainer API client
|
||||||
func NewClient(httpClient *http.Client, config Config) PortainerClient {
|
func NewClient(httpClient *http.Client, config Config) PortainerClient {
|
||||||
return &portainerClientImp{
|
return &portainerClientImp{
|
||||||
httpClient: httpClient,
|
httpClient: httpClient,
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetTranslatedStackType returns a stack's Type field (int) translated to it's human readable form (string)
|
||||||
func GetTranslatedStackType(s portainer.Stack) string {
|
func GetTranslatedStackType(s portainer.Stack) string {
|
||||||
switch s.Type {
|
switch s.Type {
|
||||||
case 1:
|
case 1:
|
||||||
@ -17,6 +18,7 @@ func GetTranslatedStackType(s portainer.Stack) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StackCreateRequest represents the body of a request to POST /stacks
|
||||||
type StackCreateRequest struct {
|
type StackCreateRequest struct {
|
||||||
Name string
|
Name string
|
||||||
SwarmID string
|
SwarmID string
|
||||||
@ -24,16 +26,19 @@ type StackCreateRequest struct {
|
|||||||
Env []portainer.Pair `json:",omitempty"`
|
Env []portainer.Pair `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StackUpdateRequest represents the body of a request to PUT /stacks/{id}
|
||||||
type StackUpdateRequest struct {
|
type StackUpdateRequest struct {
|
||||||
StackFileContent string
|
StackFileContent string
|
||||||
Env []portainer.Pair `json:",omitempty"`
|
Env []portainer.Pair `json:",omitempty"`
|
||||||
Prune bool
|
Prune bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StackFileInspectResponse represents the body of a response for a request to GET /stack/{id}/file
|
||||||
type StackFileInspectResponse struct {
|
type StackFileInspectResponse struct {
|
||||||
StackFileContent string
|
StackFileContent string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenericError represents the body of a generic error returned by the Portainer API
|
||||||
type GenericError struct {
|
type GenericError struct {
|
||||||
Err string
|
Err string
|
||||||
Details string
|
Details string
|
||||||
@ -47,11 +52,13 @@ func (e *GenericError) Error() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthenticateUserRequest represents the body of a request to POST /auth
|
||||||
type AuthenticateUserRequest struct {
|
type AuthenticateUserRequest struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthenticateUserResponse represents the body of a response for a request to POST /auth
|
||||||
type AuthenticateUserResponse struct {
|
type AuthenticateUserResponse struct {
|
||||||
Jwt string
|
Jwt string
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
var cachedClient client.PortainerClient
|
var cachedClient client.PortainerClient
|
||||||
|
|
||||||
// Get the cached client or a new one
|
// GetClient returns the cached Portainer API client. If none is present, creates and returns a new one).
|
||||||
func GetClient() (c client.PortainerClient, err error) {
|
func GetClient() (c client.PortainerClient, err error) {
|
||||||
if cachedClient == nil {
|
if cachedClient == nil {
|
||||||
cachedClient, err = GetDefaultClient()
|
cachedClient, err = GetDefaultClient()
|
||||||
@ -29,7 +29,7 @@ func GetClient() (c client.PortainerClient, err error) {
|
|||||||
return cachedClient, nil
|
return cachedClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the default client
|
// GetDefaultClient returns a new Portainer API client with the default configuration
|
||||||
func GetDefaultClient() (c client.PortainerClient, err error) {
|
func GetDefaultClient() (c client.PortainerClient, err error) {
|
||||||
config, err := GetDefaultClientConfig()
|
config, err := GetDefaultClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -82,7 +82,7 @@ func GetDefaultClient() (c client.PortainerClient, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the default config for a client
|
// GetDefaultClientConfig returns the default configuration for a Portainer API client
|
||||||
func GetDefaultClientConfig() (config client.Config, err error) {
|
func GetDefaultClientConfig() (config client.Config, err error) {
|
||||||
apiURL, err := url.Parse(strings.TrimRight(viper.GetString("url"), "/") + "/api/")
|
apiURL, err := url.Parse(strings.TrimRight(viper.GetString("url"), "/") + "/api/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -101,7 +101,7 @@ func GetDefaultClientConfig() (config client.Config, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the default http client for a Portainer client
|
// GetDefaultHTTPClient returns the default HTTP client for a Portainer API client
|
||||||
func GetDefaultHTTPClient() *http.Client {
|
func GetDefaultHTTPClient() *http.Client {
|
||||||
return &http.Client{
|
return &http.Client{
|
||||||
Timeout: viper.GetDuration("timeout"),
|
Timeout: viper.GetDuration("timeout"),
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LoadCofig loads the configuration file currently used by viper into a new viper instance
|
||||||
func LoadCofig() (v *viper.Viper, err error) {
|
func LoadCofig() (v *viper.Viper, err error) {
|
||||||
// Set config file name
|
// Set config file name
|
||||||
var configFile string
|
var configFile string
|
||||||
@ -34,6 +35,7 @@ func LoadCofig() (v *viper.Viper, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckConfigKeyExists checks a given configuration key exists in the default viper
|
||||||
func CheckConfigKeyExists(key string) (keyExists bool) {
|
func CheckConfigKeyExists(key string) (keyExists bool) {
|
||||||
for _, k := range viper.AllKeys() {
|
for _, k := range viper.AllKeys() {
|
||||||
if k == key {
|
if k == key {
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewTabWriter returns a new tabwriter.Writer
|
||||||
func NewTabWriter(headers []string) (*tabwriter.Writer, error) {
|
func NewTabWriter(headers []string) (*tabwriter.Writer, error) {
|
||||||
writer := tabwriter.NewWriter(os.Stdout, 20, 2, 3, ' ', 0)
|
writer := tabwriter.NewWriter(os.Stdout, 20, 2, 3, ' ', 0)
|
||||||
_, err := fmt.Fprintln(writer, strings.Join(headers, "\t"))
|
_, err := fmt.Fprintln(writer, strings.Join(headers, "\t"))
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Common errors
|
||||||
const (
|
const (
|
||||||
ErrStackNotFound = Error("Stack not found")
|
ErrStackNotFound = Error("Stack not found")
|
||||||
ErrStackClusterNotFound = Error("Stack cluster not found")
|
ErrStackClusterNotFound = Error("Stack cluster not found")
|
||||||
@ -29,6 +30,7 @@ func (e Error) Error() string {
|
|||||||
return string(e)
|
return string(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultEndpoint returns the default endpoint (if only one endpoint exists)
|
||||||
func GetDefaultEndpoint() (endpoint portainer.Endpoint, err error) {
|
func GetDefaultEndpoint() (endpoint portainer.Endpoint, err error) {
|
||||||
portainerClient, err := GetClient()
|
portainerClient, err := GetClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,6 +55,8 @@ func GetDefaultEndpoint() (endpoint portainer.Endpoint, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStackByName returns a stack by its name from the (endpoint filtered) list
|
||||||
|
// of all stacks
|
||||||
func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) {
|
func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||||
portainerClient, err := GetClient()
|
portainerClient, err := GetClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,6 +77,8 @@ func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEndpointByName returns an endpoint by its name from the list of all
|
||||||
|
// endpoints
|
||||||
func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
|
func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
|
||||||
portainerClient, err := GetClient()
|
portainerClient, err := GetClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -93,6 +99,8 @@ func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEndpointGroupByName returns an endpoint group by its name from the list
|
||||||
|
// of all endpoint groups
|
||||||
func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup, err error) {
|
func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup, err error) {
|
||||||
portainerClient, err := GetClient()
|
portainerClient, err := GetClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -113,6 +121,8 @@ func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEndpointFromListByID returns an endpoint by its id from a list of
|
||||||
|
// endpoints
|
||||||
func GetEndpointFromListByID(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) {
|
func GetEndpointFromListByID(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) {
|
||||||
for i := range endpoints {
|
for i := range endpoints {
|
||||||
if endpoints[i].ID == id {
|
if endpoints[i].ID == id {
|
||||||
@ -122,6 +132,8 @@ func GetEndpointFromListByID(endpoints []portainer.Endpoint, id portainer.Endpoi
|
|||||||
return endpoint, ErrEndpointNotFound
|
return endpoint, ErrEndpointNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEndpointFromListByName returns an endpoint by its name from a list of
|
||||||
|
// endpoints
|
||||||
func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (endpoint portainer.Endpoint, err error) {
|
func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (endpoint portainer.Endpoint, err error) {
|
||||||
for i := range endpoints {
|
for i := range endpoints {
|
||||||
if endpoints[i].Name == name {
|
if endpoints[i].Name == name {
|
||||||
@ -131,6 +143,7 @@ func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (end
|
|||||||
return endpoint, ErrEndpointNotFound
|
return endpoint, ErrEndpointNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEndpointSwarmClusterID returns an endpoint's swarm cluster id
|
||||||
func GetEndpointSwarmClusterID(endpointID portainer.EndpointID) (endpointSwarmClusterID string, err error) {
|
func GetEndpointSwarmClusterID(endpointID portainer.EndpointID) (endpointSwarmClusterID string, err error) {
|
||||||
// Get docker information for endpoint
|
// Get docker information for endpoint
|
||||||
portainerClient, err := GetClient()
|
portainerClient, err := GetClient()
|
||||||
@ -167,6 +180,7 @@ func selectValue(jsonMap map[string]interface{}, jsonPath []string) (interface{}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFormatHelp returns the help string for --format flags
|
||||||
func GetFormatHelp(v interface{}) (r string) {
|
func GetFormatHelp(v interface{}) (r string) {
|
||||||
typeOfV := reflect.TypeOf(v)
|
typeOfV := reflect.TypeOf(v)
|
||||||
r = fmt.Sprintf(`
|
r = fmt.Sprintf(`
|
||||||
|
@ -19,6 +19,7 @@ var (
|
|||||||
buildDate string
|
buildDate string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BuildVersionString returns the tool's version
|
||||||
func BuildVersionString() string {
|
func BuildVersionString() string {
|
||||||
osArch := runtime.GOOS + "/" + runtime.GOARCH
|
osArch := runtime.GOOS + "/" + runtime.GOARCH
|
||||||
|
|
||||||
@ -33,6 +34,8 @@ func BuildVersionString() string {
|
|||||||
return fmt.Sprintf("%s %s %s BuildDate: %s", programName, version, osArch, buildDate)
|
return fmt.Sprintf("%s %s %s BuildDate: %s", programName, version, osArch, buildDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildUseAgentString returns the tool's User-Agent in requests to the
|
||||||
|
// Portainer API
|
||||||
func BuildUseAgentString() string {
|
func BuildUseAgentString() string {
|
||||||
var theVersion = version
|
var theVersion = version
|
||||||
if theVersion == "" {
|
if theVersion == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user