• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-cli / 1807248277

08 May 2025 11:21AM UTC coverage: 1.701% (-0.04%) from 1.737%
1807248277

Pull #284

gitlab-ci

danielskinstad
chore: add input sanitization to devices list

Return error if page or per-page argument is less than 1

Signed-off-by: Daniel Skinstad Drabitzius <daniel.drabitzius@northern.tech>
Pull Request #284: feat: use paginated endpoint to list artifacts

0 of 64 new or added lines in 3 files covered. (0.0%)

4 existing lines in 2 files now uncovered.

45 of 2646 relevant lines covered (1.7%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/artifacts_list.go
1
// Copyright 2023 Northern.tech AS
2
//
3
//        Licensed under the Apache License, Version 2.0 (the "License");
4
//        you may not use this file except in compliance with the License.
5
//        You may obtain a copy of the License at
6
//
7
//            http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//        Unless required by applicable law or agreed to in writing, software
10
//        distributed under the License is distributed on an "AS IS" BASIS,
11
//        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//        See the License for the specific language governing permissions and
13
//        limitations under the License.
14
package cmd
15

16
import (
17
        "errors"
18

19
        "github.com/spf13/cobra"
20
        "github.com/spf13/viper"
21

22
        "github.com/mendersoftware/mender-cli/client/deployments"
23
)
24

25
const (
26
        argDetailLevel = "detail"
27
)
28

29
var artifactsListCmd = &cobra.Command{
30
        Use:   "list",
31
        Short: "Get a list of artifacts from the Mender server.",
32
        Run: func(c *cobra.Command, args []string) {
×
33
                cmd, err := NewArtifactsListCmd(c, args)
×
34
                CheckErr(err)
×
35
                CheckErr(cmd.Run())
×
36
        },
×
37
}
38

39
func init() {
×
40
        artifactsListCmd.Flags().IntP(argDetailLevel, "d", 0, "artifacts list detail level [0..3]")
×
NEW
41
        artifactsListCmd.Flags().IntP(argPerPage, "N", 20, "Number of results to display")
×
NEW
42
        artifactsListCmd.Flags().IntP(argPage, "P", 1, "Page number to return")
×
NEW
43
        artifactsListCmd.Flags().BoolP(
×
NEW
44
                argRawMode,
×
NEW
45
                "r",
×
NEW
46
                false,
×
NEW
47
                "artifacts list raw mode (json from mender server)")
×
UNCOV
48
}
×
49

50
type ArtifactsListCmd struct {
51
        server        string
52
        skipVerify    bool
53
        token         string
54
        detailLevel   int
55
        rawMode       bool
56
        page, perPage int
57
}
58

59
func NewArtifactsListCmd(cmd *cobra.Command, args []string) (*ArtifactsListCmd, error) {
×
60
        server := viper.GetString(argRootServer)
×
61
        if server == "" {
×
62
                return nil, errors.New("No server")
×
63
        }
×
64

NEW
65
        flags := cmd.Flags()
×
NEW
66

×
67
        skipVerify, err := cmd.Flags().GetBool(argRootSkipVerify)
×
68
        if err != nil {
×
69
                return nil, err
×
70
        }
×
71

72
        detailLevel, err := cmd.Flags().GetInt(argDetailLevel)
×
73
        if err != nil {
×
74
                return nil, err
×
75
        }
×
76

NEW
77
        rawMode, err := flags.GetBool(argRawMode)
×
NEW
78
        if err != nil {
×
NEW
79
                return nil, err
×
NEW
80
        }
×
81

NEW
82
        perPage, err := flags.GetInt(argPerPage)
×
NEW
83
        if err != nil {
×
NEW
84
                return nil, err
×
NEW
85
        }
×
86

NEW
87
        page, err := flags.GetInt(argPage)
×
NEW
88
        if err != nil {
×
NEW
89
                return nil, err
×
NEW
90
        }
×
91

NEW
92
        if page <= 0 || perPage <= 0 {
×
NEW
93
                return nil, errors.New("page and per-page arguments must be larger than 0")
×
NEW
94
        }
×
95

96
        token, err := getAuthToken(cmd)
×
97
        if err != nil {
×
98
                return nil, err
×
99
        }
×
100

101
        return &ArtifactsListCmd{
×
102
                server:      server,
×
103
                token:       token,
×
104
                skipVerify:  skipVerify,
×
105
                detailLevel: detailLevel,
×
NEW
106
                rawMode:     rawMode,
×
NEW
107
                perPage:     perPage,
×
NEW
108
                page:        page,
×
UNCOV
109
        }, nil
×
110
}
111

112
func (c *ArtifactsListCmd) Run() error {
×
113

×
114
        client := deployments.NewClient(c.server, c.skipVerify)
×
NEW
115
        return client.ListArtifacts(c.token, c.detailLevel, c.perPage, c.page, c.rawMode)
×
116
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc