Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
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
6 changes: 3 additions & 3 deletions .tools/nvim/__http__/console/registry-image.graphql.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
global:
image: "test-image:t1.0.0"
image: "imageName1:imageTag1"
---

label: List Registry Images
Expand Down Expand Up @@ -56,8 +56,8 @@ variables:

label: Get Registry Image URL
query: |+
query Core_getRegistryImageURL($image: String!, $meta: Map!) {
core_getRegistryImageURL(image: $image, meta: $meta) {
query Core_getRegistryImageURL {
core_getRegistryImageURL {
url
scriptUrl
}
Expand Down
56 changes: 8 additions & 48 deletions apps/console/internal/app/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/console/internal/app/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type Query {
core_getImagePullSecret(name: String!): ImagePullSecret @isLoggedInAndVerified @hasAccount
core_resyncImagePullSecret(name: String!): Boolean! @isLoggedInAndVerified @hasAccount

core_getRegistryImageURL(image: String!, meta: Map!): RegistryImageURL! @isLoggedInAndVerified @hasAccount
core_getRegistryImageURL: RegistryImageURL! @isLoggedInAndVerified @hasAccount
core_getRegistryImage(image: String!,): RegistryImage @isLoggedInAndVerified @hasAccount
core_listRegistryImages(pq: CursorPaginationIn): RegistryImagePaginatedRecords @isLoggedInAndVerified @hasAccount

Expand Down
4 changes: 2 additions & 2 deletions apps/console/internal/app/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/console/internal/domain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type Domain interface {

ResyncEnvironment(ctx ConsoleContext, name string) error

GetRegistryImageURL(ctx ConsoleContext, image string, meta map[string]any) (*entities.RegistryImageURL, error)
GetRegistryImageURL(ctx ConsoleContext) (*entities.RegistryImageURL, error)
GetRegistryImage(ctx ConsoleContext, image string) (*entities.RegistryImage, error)
DeleteRegistryImage(ctx ConsoleContext, image string) error
CreateRegistryImage(ctx context.Context, accountName string, image string, meta map[string]any) (*entities.RegistryImage, error)
Expand Down
14 changes: 3 additions & 11 deletions apps/console/internal/domain/registry-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/kloudlite/api/apps/console/internal/entities"
fc "github.com/kloudlite/api/apps/console/internal/entities/field-constants"
Expand Down Expand Up @@ -46,19 +45,12 @@ func getImageNameTag(image string) (string, string) {
return parts[0], "latest"
}

func (d *domain) GetRegistryImageURL(ctx ConsoleContext, image string, meta map[string]any) (*entities.RegistryImageURL, error) {
func (d *domain) GetRegistryImageURL(ctx ConsoleContext) (*entities.RegistryImageURL, error) {
encodedToken := encodeAccessToken(ctx.AccountName, d.envVars.WebhookTokenHashingSecret)

imageName, imageTag := getImageNameTag(image)

metaJSON, err := json.Marshal(meta)
if err != nil {
return nil, err
}

return &entities.RegistryImageURL{
URL: fmt.Sprintf(`curl -X POST "%s" -H "Authorization: %s" -H "Content-Type: application/json" -d '{"image": "%s:%s", "meta": %s}'`, d.envVars.WebhookURL, encodedToken, imageName, imageTag, metaJSON),
ScriptURL: "",
URL: fmt.Sprintf(`curl -X POST "%s" -H "Authorization: %s" -H "Content-Type: application/json" -d '{"image": "imageName:imageTag", "meta": {"repository": "github", "registry": "docker", "author":"kloudlite"}}'`, d.envVars.WebhookURL, encodedToken),
ScriptURL: fmt.Sprintf(`curl "%s" | authorization=%s image=imageName:imageTag meta="repository=github,registry=docker,author=kloudlite" sh`, d.envVars.WebhookURL, encodedToken),
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ const (
RegistryImageMeta = "meta"
)

// constant vars generated for struct RegistryImageURL
const (
RegistryImageURLScriptUrl = "scriptUrl"
RegistryImageURLUrl = "url"
)

// constant vars generated for struct ResourceMapping
const (
ResourceMappingBaseEntity = "BaseEntity"
Expand Down
20 changes: 19 additions & 1 deletion apps/webhook/internal/app/image-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
types2 "github.com/kloudlite/api/pkg/messaging/types"
"github.com/pkg/errors"
"go.uber.org/fx"
"io"
"net/http"
"os"
"strings"
"time"
)
Expand Down Expand Up @@ -67,7 +69,7 @@ func LoadImageHook() fx.Option {

app := server.Raw()

app.Post("/image", func(ctx *fiber.Ctx) error {
app.Post("/image-metadata", func(ctx *fiber.Ctx) error {
logger := logr.WithName("image-hook")

headers := ctx.GetReqHeaders()
Expand Down Expand Up @@ -138,6 +140,22 @@ func LoadImageHook() fx.Option {
).Infof("queued webhook")
return ctx.Status(http.StatusAccepted).JSON(map[string]string{"status": "ok"})
})

app.Get("/image-metadata", func(c *fiber.Ctx) error {
f, err := os.Open("kl-image-script.sh")
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("Error opening script: %s", err.Error()))
}
defer f.Close()
all, err := io.ReadAll(f)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("Error reading script: %s", err.Error()))
}
script := string(all)
script = strings.ReplaceAll(script, "$WEBHOOK_URL", envVars.WebhookURL)
return c.SendString(script)
})

return nil
})
}
1 change: 1 addition & 0 deletions apps/webhook/internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Env struct {

CommsService string `env:"COMMS_SERVICE" required:"true"`
DiscordWebhookUrl string `env:"DISCORD_WEBHOOK_URL" required:"false"`
WebhookURL string `env:"WEBHOOK_URL" required:"true"`

WebhookTokenHashingSecret string `env:"WEBHOOK_TOKEN_HASHING_SECRET" required:"true"`
}
17 changes: 17 additions & 0 deletions apps/webhook/kl-image-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

meta=$(echo "$meta" | tr -d ' ')

json_data='{"image": "'"$image"'", "meta": {'

IFS=',' read -r -a array <<< "$meta"
for element in "${array[@]}"
do
key=$(echo "$element" | cut -d '=' -f 1)
value=$(echo "$element" | cut -d '=' -f 2)
json_data+='"'"$key"'":"'"$value"'",'
done

json_data=${json_data%,}'}}'

curl -X POST $WEBHOOK_URL -H "Authorization: $authorization" -H "Content-Type: application/json" -d "$json_data"