Skip to content

Commit

Permalink
feat: add Image field to Function object
Browse files Browse the repository at this point in the history
Signed-off-by: SdgJlbl <[email protected]>
  • Loading branch information
SdgJlbl committed Sep 22, 2023
1 parent a0ec8c1 commit 6c94da8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/asset/function.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ message Function {
map<string, FunctionInput> inputs = 17;
map<string, FunctionOutput> outputs = 18;
FunctionStatus status = 19;
Addressable image = 20;
}

// NewFunction is used to register an Function.
Expand Down
1 change: 1 addition & 0 deletions lib/asset/function_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (a *NewFunction) Validate() error {
validation.Field(&a.NewPermissions, validation.Required),
validation.Field(&a.Inputs, validation.By(validateInputs)),
validation.Field(&a.Outputs, validation.By(validateOutputs)),
// validation.Field(&a.Image, validation.Required),
)
}

Expand Down
13 changes: 10 additions & 3 deletions server/standalone/dbal/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type sqlFunction struct {
CreationDate time.Time
Metadata map[string]string
Status asset.FunctionStatus
Image asset.Addressable
}

func (a *sqlFunction) toFunction() *asset.Function {
Expand All @@ -36,6 +37,7 @@ func (a *sqlFunction) toFunction() *asset.Function {
CreationDate: timestamppb.New(a.CreationDate),
Metadata: a.Metadata,
Status: a.Status,
Image: &a.Image,
}
}

Expand All @@ -51,10 +53,15 @@ func (d *DBAL) AddFunction(function *asset.Function) error {
return err
}

err = d.addAddressable(function.Image)
if err != nil {
return err
}

stmt := getStatementBuilder().
Insert("functions").
Columns("key", "channel", "name", "description", "functionAddress", "permissions", "owner", "creation_date", "metadata", "status").
Values(function.Key, d.channel, function.Name, function.Description.StorageAddress, function.Archive.StorageAddress, function.Permissions, function.Owner, function.CreationDate.AsTime(), function.Metadata, function.Status.String())
Values(function.Key, d.channel, function.Name, function.Description.StorageAddress, function.Archive.StorageAddress, function.Permissions, function.Owner, function.CreationDate.AsTime(), function.Metadata, function.Status.String(), function.Image.StorageAddress)

err = d.exec(stmt)
if err != nil {
Expand Down Expand Up @@ -87,7 +94,7 @@ func (d *DBAL) GetFunction(key string) (*asset.Function, error) {
}

al := sqlFunction{}
err = row.Scan(&al.Key, &al.Name, &al.Description.StorageAddress, &al.Description.Checksum, &al.Archive.StorageAddress, &al.Archive.Checksum, &al.Permissions, &al.Owner, &al.CreationDate, &al.Metadata, &al.Status)
err = row.Scan(&al.Key, &al.Name, &al.Description.StorageAddress, &al.Description.Checksum, &al.Archive.StorageAddress, &al.Archive.Checksum, &al.Permissions, &al.Owner, &al.CreationDate, &al.Metadata, &al.Status, &al.Image.StorageAddress, &al.Image.Checksum)

if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
Expand Down Expand Up @@ -175,7 +182,7 @@ func (d *DBAL) queryFunctions(p *common.Pagination, filter *asset.FunctionQueryF
for rows.Next() {
al := sqlFunction{}

err = rows.Scan(&al.Key, &al.Name, &al.Description.StorageAddress, &al.Description.Checksum, &al.Archive.StorageAddress, &al.Archive.Checksum, &al.Permissions, &al.Owner, &al.CreationDate, &al.Metadata, &al.Status)
err = rows.Scan(&al.Key, &al.Name, &al.Description.StorageAddress, &al.Description.Checksum, &al.Archive.StorageAddress, &al.Archive.Checksum, &al.Permissions, &al.Owner, &al.CreationDate, &al.Metadata, &al.Status, &al.Image.StorageAddress, &al.Image.Checksum)
if err != nil {
return nil, "", err
}
Expand Down

0 comments on commit 6c94da8

Please sign in to comment.