-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thread configurable trustroot resync period to bundle trustroot func (#…
…171) * move trustroot resync period configration to different package Signed-off-by: Meredith Lancaster <[email protected]> * add license Signed-off-by: Meredith Lancaster <[email protected]> * comment Signed-off-by: Meredith Lancaster <[email protected]> * rename files Signed-off-by: Meredith Lancaster <[email protected]> --------- Signed-off-by: Meredith Lancaster <[email protected]>
- Loading branch information
1 parent
7f89d5a
commit 90e9ff0
Showing
7 changed files
with
93 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Copyright 2024 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package tuf | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"knative.dev/pkg/controller" | ||
) | ||
|
||
type trustrootResyncPeriodKey struct{} | ||
|
||
// ToContext returns a context that includes a key trustrootResyncPeriod | ||
// set to the included duration | ||
func ToContext(ctx context.Context, duration time.Duration) context.Context { | ||
return context.WithValue(ctx, trustrootResyncPeriodKey{}, duration) | ||
} | ||
|
||
// FromContextOrDefaults returns a stored trustrootResyncPeriod if attached. | ||
// If not found, it returns a default duration | ||
func FromContextOrDefaults(ctx context.Context) time.Duration { | ||
x, ok := ctx.Value(trustrootResyncPeriodKey{}).(time.Duration) | ||
if ok { | ||
return x | ||
} | ||
return controller.DefaultResyncPeriod | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Copyright 2024 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package tuf | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"knative.dev/pkg/controller" | ||
rtesting "knative.dev/pkg/reconciler/testing" | ||
) | ||
|
||
func TestContextDuration(t *testing.T) { | ||
ctx, _ := rtesting.SetupFakeContext(t) | ||
|
||
expected := controller.DefaultResyncPeriod | ||
actual := FromContextOrDefaults(ctx) | ||
if expected != actual { | ||
t.Fatal("Expected the context to store the value and be retrievable") | ||
} | ||
|
||
expected = time.Hour | ||
ctx = ToContext(ctx, expected) | ||
actual = FromContextOrDefaults(ctx) | ||
|
||
if expected != actual { | ||
t.Fatal("Expected the context to store the value and be retrievable") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters