mirror of
https://github.com/vee1e/gittuf.git
synced 2026-09-03 11:17:08 +00:00
This commit introduces v02 of policy metadata schemas for root and targets files. The biggest change is the introduction of the Person principal type. This commit also adds a migration function from v01 to v02, though it's selectively invoked. Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
32 lines
906 B
Go
32 lines
906 B
Go
// Copyright The gittuf Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package policy
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gittuf/gittuf/internal/tuf"
|
|
tufv01 "github.com/gittuf/gittuf/internal/tuf/v01"
|
|
tufv02 "github.com/gittuf/gittuf/internal/tuf/v02"
|
|
)
|
|
|
|
// InitializeRootMetadata initializes a new instance of tuf.RootMetadata with
|
|
// default values and a given key. The default values are version set to 1,
|
|
// expiry date set to one year from now, and the provided key is added.
|
|
func InitializeRootMetadata(key tuf.Principal) (tuf.RootMetadata, error) {
|
|
var rootMetadata tuf.RootMetadata
|
|
|
|
if tufv02.AllowV02Metadata() {
|
|
rootMetadata = tufv02.NewRootMetadata()
|
|
} else {
|
|
rootMetadata = tufv01.NewRootMetadata()
|
|
}
|
|
rootMetadata.SetExpires(time.Now().AddDate(1, 0, 0).Format(time.RFC3339))
|
|
|
|
if err := rootMetadata.AddRootPrincipal(key); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return rootMetadata, nil
|
|
}
|