mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 12:28:01 +08:00
feat(mgmt): added mgmt extension which returns current zot configuration (#1198)
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
@@ -211,3 +211,23 @@ func DirExists(d string) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Used to filter a json fields by using an intermediate struct.
|
||||
func MarshalThroughStruct(obj interface{}, throughStruct interface{}) ([]byte, error) {
|
||||
toJSON, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(toJSON, throughStruct)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
toJSON, err = json.Marshal(throughStruct)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return toJSON, nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,28 @@ func TestCommon(t *testing.T) {
|
||||
So(common.Contains([]string{}, "apple"), ShouldBeFalse)
|
||||
})
|
||||
|
||||
Convey("test MarshalThroughStruct()", t, func() {
|
||||
cfg := config.New()
|
||||
|
||||
newCfg := struct {
|
||||
DistSpecVersion string
|
||||
}{}
|
||||
|
||||
_, err := common.MarshalThroughStruct(cfg, &newCfg)
|
||||
So(err, ShouldBeNil)
|
||||
So(newCfg.DistSpecVersion, ShouldEqual, cfg.DistSpecVersion)
|
||||
|
||||
// negative
|
||||
obj := make(chan int)
|
||||
toObj := config.New()
|
||||
|
||||
_, err = common.MarshalThroughStruct(obj, &toObj)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
_, err = common.MarshalThroughStruct(toObj, &obj)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("test getTLSConfig()", t, func() {
|
||||
caCertPool, _ := x509.SystemCertPool()
|
||||
tlsConfig, err := common.GetTLSConfig("wrongPath", caCertPool)
|
||||
|
||||
Reference in New Issue
Block a user