Skip to content

Commit 3b1bca4

Browse files
authored
Merge branch 'lxc:main' into main
2 parents 78ce0a1 + 99a5408 commit 3b1bca4

File tree

120 files changed

+8554
-7597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+8554
-7597
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ RUN go install -v github.com/google/go-licenses@latest && \
9595
GOTOOLCHAIN="" go install -v golang.org/x/tools/gopls@latest && \
9696
go install -v github.com/go-delve/delve/cmd/dlv@latest && \
9797
go install -v golang.org/x/tools/cmd/goimports@latest && \
98+
go install -v golang.org/x/vuln/cmd/govulncheck@latest && \
9899
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
99100

100101
# Make dependencies

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ static-analysis:
297297
ifeq ($(shell command -v go-licenses),)
298298
(cd / ; $(GO) install -v -x github.com/google/go-licenses@latest)
299299
endif
300+
ifeq ($(shell command -v govulncheck),)
301+
go install golang.org/x/vuln/cmd/govulncheck@latest
302+
endif
300303
ifeq ($(shell command -v golangci-lint),)
301304
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$($(GO) env GOPATH)/bin
302305
endif

client/incus_certificates.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ func (r *ProtocolIncus) GetCertificates() ([]api.Certificate, error) {
3636
return certificates, nil
3737
}
3838

39+
// GetCertificatesWithFilter returns a filtered list of certificates.
40+
func (r *ProtocolIncus) GetCertificatesWithFilter(filters []string) ([]api.Certificate, error) {
41+
certificates := []api.Certificate{}
42+
43+
v := url.Values{}
44+
v.Set("recursion", "1")
45+
v.Set("filter", parseFilters(filters))
46+
47+
// Fetch the raw value
48+
_, err := r.queryStruct("GET", fmt.Sprintf("/certificates?%s", v.Encode()), nil, "", &certificates)
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
return certificates, nil
54+
}
55+
3956
// GetCertificate returns the certificate entry for the provided fingerprint.
4057
func (r *ProtocolIncus) GetCertificate(fingerprint string) (*api.Certificate, string, error) {
4158
certificate := api.Certificate{}

client/incus_images.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func incusDownloadImage(fingerprint string, uri string, userAgent string, do fun
279279
}
280280

281281
// Hashing
282-
hashSHA256 := sha256.New()
282+
hash256 := sha256.New()
283283

284284
// Deal with split images
285285
if ctype == "multipart/form-data" {
@@ -300,7 +300,7 @@ func incusDownloadImage(fingerprint string, uri string, userAgent string, do fun
300300
return nil, fmt.Errorf("Invalid multipart image")
301301
}
302302

303-
size, err := io.Copy(io.MultiWriter(req.MetaFile, hashSHA256), part)
303+
size, err := io.Copy(io.MultiWriter(req.MetaFile, hash256), part)
304304
if err != nil {
305305
return nil, err
306306
}
@@ -318,7 +318,7 @@ func incusDownloadImage(fingerprint string, uri string, userAgent string, do fun
318318
return nil, fmt.Errorf("Invalid multipart image")
319319
}
320320

321-
size, err = io.Copy(io.MultiWriter(req.RootfsFile, hashSHA256), part)
321+
size, err = io.Copy(io.MultiWriter(req.RootfsFile, hash256), part)
322322
if err != nil {
323323
return nil, err
324324
}
@@ -327,7 +327,7 @@ func incusDownloadImage(fingerprint string, uri string, userAgent string, do fun
327327
resp.RootfsName = part.FileName()
328328

329329
// Check the hash
330-
hash := fmt.Sprintf("%x", hashSHA256.Sum(nil))
330+
hash := fmt.Sprintf("%x", hash256.Sum(nil))
331331
if imageType != "oci" && !strings.HasPrefix(hash, fingerprint) {
332332
return nil, fmt.Errorf("Image fingerprint doesn't match. Got %s expected %s", hash, fingerprint)
333333
}
@@ -346,7 +346,7 @@ func incusDownloadImage(fingerprint string, uri string, userAgent string, do fun
346346
return nil, fmt.Errorf("No filename in Content-Disposition header")
347347
}
348348

349-
size, err := io.Copy(io.MultiWriter(req.MetaFile, hashSHA256), body)
349+
size, err := io.Copy(io.MultiWriter(req.MetaFile, hash256), body)
350350
if err != nil {
351351
return nil, err
352352
}
@@ -355,7 +355,7 @@ func incusDownloadImage(fingerprint string, uri string, userAgent string, do fun
355355
resp.MetaName = filename
356356

357357
// Check the hash
358-
hash := fmt.Sprintf("%x", hashSHA256.Sum(nil))
358+
hash := fmt.Sprintf("%x", hash256.Sum(nil))
359359
if imageType != "oci" && !strings.HasPrefix(hash, fingerprint) {
360360
return nil, fmt.Errorf("Image fingerprint doesn't match. Got %s expected %s", hash, fingerprint)
361361
}

client/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type InstanceServer interface {
8989
// Certificate functions
9090
GetCertificateFingerprints() (fingerprints []string, err error)
9191
GetCertificates() (certificates []api.Certificate, err error)
92+
GetCertificatesWithFilter(filters []string) ([]api.Certificate, error)
9293
GetCertificate(fingerprint string) (certificate *api.Certificate, ETag string, err error)
9394
CreateCertificate(certificate api.CertificatesPost) (err error)
9495
UpdateCertificate(fingerprint string, certificate api.CertificatePut, ETag string) (err error)

cmd/generate-config/incus_doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func getSortedKeysFromMap[K string, V IterableAny](m map[K]V) []K {
7575

7676
func parse(path string, outputJSONPath string, excludedPaths []string) (*doc, error) {
7777
jsonDoc := &doc{}
78-
docKeys := make(map[string]struct{}, 0)
78+
docKeys := make(map[string]struct{})
7979
projectEntries := make(map[string]any)
8080
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
8181
if err != nil {

cmd/generate-database/db/parse.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func Parse(localPath string, pkgs []*types.Package, name string, kind string) (*
175175
m.Package = pkg.Name()
176176
m.Name = name
177177
m.Fields = fields
178-
m.Type = tableType(pkgs, name, fields)
178+
m.Type = tableType(pkgs, fields)
179179
m.Filterable = true
180180

181181
oldStructHasTags := false
@@ -303,19 +303,33 @@ func ParseStmt(name string, defs map[*ast.Ident]types.Object, registeredSQLStmts
303303
}
304304

305305
// tableType determines the TableType for the given struct fields.
306-
func tableType(pkgs []*types.Package, name string, fields []*Field) TableType {
306+
func tableType(pkgs []*types.Package, fields []*Field) TableType {
307307
fieldNames := FieldNames(fields)
308-
entities := strings.Split(lex.SnakeCase(name), "_")
309-
if len(entities) == 2 {
308+
idFields := []string{}
309+
for _, field := range fields {
310+
if field.Name == "ID" {
311+
idFields = nil
312+
break
313+
}
314+
315+
if strings.HasSuffix(lex.SnakeCase(field.Name), "_id") {
316+
structName, ok := strings.CutSuffix(field.Name, "ID")
317+
if ok {
318+
idFields = append(idFields, structName)
319+
}
320+
}
321+
}
322+
323+
if len(idFields) == 2 {
310324
var struct1 *types.Struct
311325
var struct2 *types.Struct
312326
for _, pkg := range pkgs {
313327
if struct1 == nil {
314-
struct1 = findStruct(pkg.Scope(), lex.PascalCase(lex.Singular(entities[0])))
328+
struct1 = findStruct(pkg.Scope(), lex.PascalCase(lex.Singular(idFields[0])))
315329
}
316330

317331
if struct2 == nil {
318-
struct2 = findStruct(pkg.Scope(), lex.PascalCase(lex.Singular(entities[1])))
332+
struct2 = findStruct(pkg.Scope(), lex.PascalCase(lex.Singular(idFields[1])))
319333
}
320334
}
321335

cmd/generate-database/db/stmt.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"go/ast"
88
"go/types"
9+
"slices"
910
"strings"
1011

1112
"golang.org/x/tools/go/packages"
@@ -141,7 +142,9 @@ func (s *Stmt) objects(buf *file.Buffer) error {
141142
return err
142143
}
143144

144-
joins = append(joins, join)
145+
if !slices.Contains(joins, join) {
146+
joins = append(joins, join)
147+
}
145148
}
146149

147150
table += strings.Join(joins, "")
@@ -310,7 +313,10 @@ func (s *Stmt) namesBy(buf *file.Buffer) error {
310313
return err
311314
}
312315

313-
joins = append(joins, join)
316+
if !slices.Contains(joins, join) {
317+
joins = append(joins, join)
318+
}
319+
314320
column = field.joinConfig()
315321
} else {
316322
column = mapping.FieldColumnName(field.Name, tableName)
@@ -406,7 +412,10 @@ func (s *Stmt) id(buf *file.Buffer) error {
406412
column = field.joinConfig()
407413

408414
join, err := field.JoinClause(mapping, table)
409-
joins = append(joins, join)
415+
if !slices.Contains(joins, join) {
416+
joins = append(joins, join)
417+
}
418+
410419
if err != nil {
411420
return err
412421
}

cmd/generate-database/lex/form.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func Plural(s string) string {
1616
return s + "es"
1717
}
1818

19+
if strings.HasSuffix(s, "y") {
20+
return s[:len(s)-1] + "ies"
21+
}
22+
1923
if s[len(s)-1] != 's' {
2024
return s + "s"
2125
}
@@ -26,7 +30,12 @@ func Plural(s string) string {
2630
// Singular converts to singular form ("foos" -> "foo").
2731
func Singular(s string) string {
2832
// TODO: smarter algorithm? :)
29-
before, ok := strings.CutSuffix(s, "es")
33+
before, ok := strings.CutSuffix(s, "ies")
34+
if ok {
35+
return before + "y"
36+
}
37+
38+
before, ok = strings.CutSuffix(s, "es")
3039
if ok && (strings.HasSuffix(before, "ch") || strings.HasSuffix(before, "sh") || strings.HasSuffix(before, "ss")) {
3140
return before
3241
}

cmd/incus-agent/dev_incus.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ func hoistReq(f func(*Daemon, http.ResponseWriter, *http.Request) *devIncusRespo
251251
}
252252

253253
func devIncusAPI(d *Daemon) http.Handler {
254-
m := mux.NewRouter()
255-
m.UseEncodedPath() // Allow encoded values in path segments.
254+
router := mux.NewRouter()
255+
router.UseEncodedPath() // Allow encoded values in path segments.
256256

257257
for _, handler := range handlers {
258-
m.HandleFunc(handler.path, hoistReq(handler.f, d))
258+
router.HandleFunc(handler.path, hoistReq(handler.f, d))
259259
}
260260

261-
return m
261+
return router
262262
}
263263

264264
// Create a new net.Listener bound to the unix socket of the DevIncus endpoint.

0 commit comments

Comments
 (0)