-
Notifications
You must be signed in to change notification settings - Fork 239
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
Feroze Mohideen
committed
May 13, 2024
1 parent
27359a7
commit 0cdc16d
Showing
20 changed files
with
416 additions
and
20 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,69 @@ | ||
package upstash_integration | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/porter-dev/porter/api/server/handlers" | ||
"github.com/porter-dev/porter/api/server/shared" | ||
"github.com/porter-dev/porter/api/server/shared/apierrors" | ||
"github.com/porter-dev/porter/api/server/shared/config" | ||
"github.com/porter-dev/porter/api/types" | ||
"github.com/porter-dev/porter/internal/models" | ||
"github.com/porter-dev/porter/internal/telemetry" | ||
) | ||
|
||
// ListUpstashIntegrationsHandler is a struct for listing all upstash integrations for a given project | ||
type ListUpstashIntegrationsHandler struct { | ||
handlers.PorterHandlerReadWriter | ||
} | ||
|
||
// NewListUpstashIntegrationsHandler constructs a ListUpstashIntegrationsHandler | ||
func NewListUpstashIntegrationsHandler( | ||
config *config.Config, | ||
decoderValidator shared.RequestDecoderValidator, | ||
writer shared.ResultWriter, | ||
) *ListUpstashIntegrationsHandler { | ||
return &ListUpstashIntegrationsHandler{ | ||
PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer), | ||
} | ||
} | ||
|
||
// UpstashIntegration describes a upstash integration | ||
type UpstashIntegration struct { | ||
CreatedAt time.Time `json:"created_at"` | ||
} | ||
|
||
// ListUpstashIntegrationsResponse describes the list upstash integrations response body | ||
type ListUpstashIntegrationsResponse struct { | ||
// Integrations is a list of upstash integrations | ||
Integrations []UpstashIntegration `json:"integrations"` | ||
} | ||
|
||
// ServeHTTP returns a list of upstash integrations associated with the specified project | ||
func (h *ListUpstashIntegrationsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
ctx, span := telemetry.NewSpan(r.Context(), "serve-list-upstash-integrations") | ||
defer span.End() | ||
|
||
project, _ := ctx.Value(types.ProjectScope).(*models.Project) | ||
|
||
resp := ListUpstashIntegrationsResponse{} | ||
integrationList := make([]UpstashIntegration, 0) | ||
|
||
integrations, err := h.Repo().UpstashIntegration().Integrations(ctx, project.ID) | ||
if err != nil { | ||
err := telemetry.Error(ctx, span, err, "error getting datastores") | ||
h.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError)) | ||
return | ||
} | ||
|
||
for _, int := range integrations { | ||
integrationList = append(integrationList, UpstashIntegration{ | ||
CreatedAt: int.CreatedAt, | ||
}) | ||
} | ||
|
||
resp.Integrations = integrationList | ||
|
||
h.WriteResult(w, r, resp) | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
import { z } from "zod"; | ||
|
||
import { | ||
upstashIntegrationValidator, | ||
type ClientUpstashIntegration, | ||
} from "lib/upstash/types"; | ||
|
||
import api from "shared/api"; | ||
|
||
type TUseUpstash = { | ||
getUpstashIntegrations: ({ | ||
projectId, | ||
}: { | ||
projectId: number; | ||
}) => Promise<ClientUpstashIntegration[]>; | ||
}; | ||
export const useUpstash = (): TUseUpstash => { | ||
const getUpstashIntegrations = async ({ | ||
projectId, | ||
}: { | ||
projectId: number; | ||
}): Promise<ClientUpstashIntegration[]> => { | ||
const response = await api.getUpstashIntegrations( | ||
"<token>", | ||
{}, | ||
{ | ||
projectId, | ||
} | ||
); | ||
|
||
const results = await z | ||
.object({ integrations: z.array(upstashIntegrationValidator) }) | ||
.parseAsync(response.data); | ||
|
||
return results.integrations; | ||
}; | ||
|
||
return { | ||
getUpstashIntegrations, | ||
}; | ||
}; |
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,8 @@ | ||
import { z } from "zod"; | ||
|
||
export const upstashIntegrationValidator = z.object({ | ||
created_at: z.string(), | ||
}); | ||
export type ClientUpstashIntegration = z.infer< | ||
typeof upstashIntegrationValidator | ||
>; |
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
Oops, something went wrong.