-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a753e82
commit 19ba6b1
Showing
1 changed file
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package guardrails | ||
|
||
import ( | ||
guardrailsv1alpha1 "" | ||
"context" | ||
"fmt" | ||
"go/format" | ||
"github.com/trustyai-explainability/trustyai-service-operator/controllers/guardrails" | ||
) | ||
|
||
func (r *GuardrailsOrchestratorReconciler) getSecret(ctx context.Context, name, namespace) { | ||
secret := &corev1.Secret{} | ||
err := r.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, secret) | ||
if err != nil { | ||
if errors.IsNotFound(err) { | ||
return nil, fmt.Errorf("secret %s not found in namespace %s: %w", name, namespace, err) | ||
} | ||
return nil, fmt.Errorf("failed to get secret %s in namespace %s: %w", name, namespace, err) | ||
} | ||
return secret, nil | ||
} | ||
|
||
func (r *GuardrailsOrchestratorReconciler) getDetectorTLSCert(orchestrator guardrailsv1alpha1.GuardrailOrchestrator) (*corev1.Secret, error) { | ||
detectorTLSSecretName := orchestrator.Spec. | ||
|
||
if detectorTLSSecretName != "" { | ||
secret, err := r.getSecret(ctx, detectorTLSSecretName, orchestrator.Namespace) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if secret != nil { | ||
return secret, nil | ||
|
||
} | ||
} | ||
} | ||
func (r *GuardrailsOrchestratorReconciler) validateTLSSecret(secret *corev1.Secret) error { | ||
// check Secret type is tls | ||
if secret.Type != "kubernetes.io/tls" { | ||
return fmt.Errorf("No secret for TLS credentials found") | ||
} | ||
mandatoryKeys := []string{ | ||
"cert_path", | ||
"key_path" | ||
} | ||
|
||
for _, key in range mamandatoryKeys { | ||
value, exists := secret.Data[key] | ||
if !exists { | ||
return fmt.Errorf("Mandatory key %s missing from secret", key) | ||
} | ||
if len(value) == 0 { | ||
return fmt.Errorf("Mandatory key %s is empty", key) | ||
} | ||
} | ||
} | ||
|
||
func (r *GuardrailsOrchestratorReconciler) getGeneratorTLSCert(orchestrator guardrailsv1alpha1.GuardrailOrchestrator) (*corev1.Secret, error) { | ||
generatorTLSSecretName := orchestrator.Spec | ||
|
||
if generatorTLSSecretName != "" { | ||
secret, err := r.getSecret(ctx, generatorTLSSecretName, orchestrator.Namespace) | ||
if err != nil ( | ||
return nil, error | ||
) | ||
if secret != nil ( | ||
return secret, nil | ||
) | ||
} | ||
} | ||
|