-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add certStoreManager interface to wrap operations on namespaced…
… certStores [multi-tenancy PR 5] (#1382)
- Loading branch information
Showing
16 changed files
with
291 additions
and
59 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
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,28 @@ | ||
/* | ||
Copyright The Ratify 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 utils | ||
|
||
import ( | ||
"context" | ||
"crypto/x509" | ||
|
||
ctxUtils "github.com/deislabs/ratify/internal/context" | ||
"github.com/deislabs/ratify/pkg/controllers" | ||
) | ||
|
||
// returns the internal certificate map | ||
// TODO: returns certificates from both cluster-wide and given namespace as namespaced verifier could access both. | ||
func GetCertificatesMap(ctx context.Context) map[string][]*x509.Certificate { | ||
return controllers.NamespacedCertStores.GetCertStores(ctxUtils.GetNamespace(ctx)) | ||
} |
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,35 @@ | ||
/* | ||
Copyright The Ratify 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 utils | ||
|
||
import ( | ||
"context" | ||
"crypto/x509" | ||
"testing" | ||
|
||
"github.com/deislabs/ratify/pkg/controllers" | ||
|
||
ctxUtils "github.com/deislabs/ratify/internal/context" | ||
cs "github.com/deislabs/ratify/pkg/customresources/certificatestores" | ||
) | ||
|
||
func TestGetCertificatesMap(t *testing.T) { | ||
controllers.NamespacedCertStores = cs.NewActiveCertStores() | ||
controllers.NamespacedCertStores.AddStore("default", "default/certStore", []*x509.Certificate{}) | ||
ctx := ctxUtils.SetContextWithNamespace(context.Background(), "default") | ||
|
||
if certs := GetCertificatesMap(ctx); len(certs) != 1 { | ||
t.Fatalf("Expected 1 certificate store, got %d", len(certs)) | ||
} | ||
} |
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,31 @@ | ||
/* | ||
Copyright The Ratify 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 certificatestores | ||
|
||
import "crypto/x509" | ||
|
||
// CertStoreManager is an interface that defines the methods for managing certificate stores across different scopes. | ||
type CertStoreManager interface { | ||
// GetCertStores returns certificates for the given scope. | ||
GetCertStores(scope string) map[string][]*x509.Certificate | ||
|
||
// AddStore adds the given certificate under the given scope. | ||
AddStore(scope, storeName string, cert []*x509.Certificate) | ||
|
||
// DeleteStore deletes the certificate from the given scope. | ||
DeleteStore(scope, storeName string) | ||
|
||
// IsEmpty returns true if there are no certificates. | ||
IsEmpty() bool | ||
} |
Oops, something went wrong.