Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions controllers/integrationsecret/integrationsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ func checkConnection(ctx context.Context, secret *corev1.Secret) error {
case "argocd":
path = "/api/v1/projects"
req = newRequest(ctx, string(secret.Data["url"])).SetHeader("Authorization", "Bearer "+string(secret.Data["token"]))
case "chat-assistant":
return checkCodemie(ctx, secret)
default:
path = "/"
req = newRequest(ctx, string(secret.Data["url"]))
Expand Down Expand Up @@ -311,32 +309,3 @@ func hasIntegrationSecretLabelLabel(object client.Object) bool {
return label == "true"
}

func checkCodemie(ctx context.Context, secret *corev1.Secret) error {
log := ctrl.LoggerFrom(ctx).WithValues(logKeyUrl, string(secret.Data["apiUrl"])+"/v1/user")
log.Info("Making request to Codemie")

res := make(map[string]interface{})

resp, err := newRequest(ctx, string(secret.Data["apiUrl"])).
SetAuthToken(string(secret.Data["token"])).
ForceContentType("application/json").
SetResult(&res).
Get("/v1/user")
if err != nil {
log.Error(err, "Failed to connect to Codemie")

return fmt.Errorf("failed to connect to Codemie")
}

if !resp.IsSuccess() {
return fmt.Errorf("codemie http status code %s", resp.Status())
}

// If token is invalid, Codemie API returns 200 status code.
// For this reason, we need to check response body.
if _, ok := res["userId"]; !ok {
return errors.New("failed to connect to Codemie")
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ func TestReconcileIntegrationSecret_Reconcile(t *testing.T) {
ns := "default"
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.String(), "success") {
if strings.Contains(r.URL.String(), "codemie") {
_, err := w.Write([]byte(`{"userId":"123"}`))
assert.NoError(t, err)
}

w.WriteHeader(http.StatusOK)

return
Expand Down Expand Up @@ -404,86 +399,6 @@ func TestReconcileIntegrationSecret_Reconcile(t *testing.T) {
wantErr: require.NoError,
wantConAnnotation: "",
},
{
name: "success codemie",
secretName: "codemie",
client: func(t *testing.T) client.Client {
return fake.NewClientBuilder().WithScheme(s).WithObjects(
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: "codemie",
Labels: map[string]string{
integrationSecretTypeLabel: "chat-assistant",
},
},
Data: map[string][]byte{
"apiUrl": []byte(server.URL + "/success/codemie"),
"token": []byte("token"),
},
},
).Build()
},
wantRes: reconcile.Result{
RequeueAfter: successConnectionRequeueTime,
},
wantErr: require.NoError,
wantConAnnotation: "true",
},
{
name: "codemie empty response",
secretName: "codemie",
client: func(t *testing.T) client.Client {
return fake.NewClientBuilder().WithScheme(s).WithObjects(
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: "codemie",
Labels: map[string]string{
integrationSecretTypeLabel: "chat-assistant",
},
},
Data: map[string][]byte{
"apiUrl": []byte(server.URL + "/success"),
"token": []byte("token"),
},
},
).Build()
},
wantRes: reconcile.Result{
RequeueAfter: failConnectionRequeueTime,
},
wantErr: require.NoError,
wantConAnnotation: "false",
wantConErrAnnotation: "connection failed",
},
{
name: "failed to connect to codemie",
secretName: "codemie",
client: func(t *testing.T) client.Client {
return fake.NewClientBuilder().WithScheme(s).WithObjects(
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: "codemie",
Labels: map[string]string{
integrationSecretTypeLabel: "chat-assistant",
},
},
Data: map[string][]byte{
"apiUrl": []byte(server.URL),
"token": []byte("token"),
},
},
).Build()
},
wantRes: reconcile.Result{
RequeueAfter: failConnectionRequeueTime,
},
wantErr: require.NoError,
wantConAnnotation: "false",
wantConErrAnnotation: "connection failed",
},
}

for _, tt := range tests {
Expand Down
Loading