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

pandatix / nvdapi / 13234429891

10 Feb 2025 05:49AM UTC coverage: 75.904% (-14.5%) from 90.361%
13234429891

Pull #119

github

web-flow
build(deps): bump github/codeql-action from 3.28.8 to 3.28.9

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.8 to 3.28.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/dd746615b...9e8d0789d)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #119: build(deps): bump github/codeql-action from 3.28.8 to 3.28.9

63 of 83 relevant lines covered (75.9%)

0.88 hits per line

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

80.49
/v2/encoder.go
1
package nvdapi
2

3
import (
4
        "fmt"
5
        "net/url"
6
        "reflect"
7
        "strconv"
8
        "strings"
9

10
        "github.com/pandatix/nvdapi/common"
11
)
12

13
// getEndp is a wrapper around common.GetEndp that reroutes the
14
// params encoding.
15
func getEndp(client common.HTTPClient, endp string, params, resp any, opts ...common.Option) error {
1✔
16
        return common.GetEndp(client, endp+"?"+encode(params), nil, resp, opts...)
1✔
17
}
1✔
18

19
// encode returns an URL query raw string encoded from a given
20
// struct, due to the NVD services v2 API.
21
// its formed of 3 parts, separated by a colon (","):
22
//   - name of attribute
23
//   - "omitempty" or empty
24
//   - "noValue" to set the attribute in query but without value,
25
//     else stays empty
26
func encode(params any) (out string) {
1✔
27
        elems := []string{}
1✔
28
        v := reflect.ValueOf(params)
1✔
29
        t := reflect.TypeOf(params)
1✔
30

1✔
31
        l := v.NumField()
1✔
32
        for i := 0; i < l; i++ {
2✔
33
                f := v.Field(i)
1✔
34

1✔
35
                tag := t.Field(i).Tag.Get("nvd")
1✔
36
                pts := strings.Split(tag, ",")
1✔
37

1✔
38
                // Skip if omitempty and nil
1✔
39
                if pts[1] == "omitempty" && f.IsNil() {
2✔
40
                        continue
1✔
41
                }
42

43
                // Deref if pointer
44
                if f.Kind() == reflect.Pointer {
2✔
45
                        f = f.Elem()
1✔
46
                }
1✔
47

48
                // Write down if don't need value
49
                if pts[2] == "noValue" && f.Kind() == reflect.Bool && f.Bool() {
1✔
50
                        elems = append(elems, pts[0])
×
51
                        continue
×
52
                }
53

54
                // Write down
55
                switch f.Kind() {
1✔
56
                case reflect.String:
1✔
57
                        elems = append(elems, pts[0]+"="+url.QueryEscape(f.String()))
1✔
58

59
                case reflect.Int:
1✔
60
                        elems = append(elems, pts[0]+"="+strconv.Itoa(int(f.Int())))
1✔
61

62
                case reflect.Bool:
×
63
                        // In this case, will be false.
64
                        // It is problematic as you can't differentiate the complementary binary sets.
65

66
                case reflect.TypeOf(EventName("")).Kind():
×
67
                        // Special kind involved in GetCVEHistoryParams
×
68
                        elems = append(elems, pts[0]+"="+url.QueryEscape(f.String()))
×
69

70
                default:
×
71
                        panic(fmt.Sprintf("unhandled type : %v", f.Kind()))
×
72
                }
73
        }
74

75
        for i := 0; i < len(elems); i++ {
2✔
76
                if i != 0 {
2✔
77
                        out += "&"
1✔
78
                }
1✔
79
                out += elems[i]
1✔
80
        }
81
        return
1✔
82
}
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