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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
# Added by goreleaser init:
dist/
.DS_Store
2 changes: 1 addition & 1 deletion cmd/appstreamfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func run(ctx context.Context, opts *RunOptions) error {
if opts.bucket == "" || opts.key == "" {
return fmt.Errorf("missing required S3 options: bucket and key")
}
backendSource, err = backend.NewS3Backend(opts.bucket, opts.key, opts.versionId, "appstream_machine_role")
backendSource, err = backend.NewS3Backend(ctx, opts.bucket, opts.key, opts.versionId, "appstream_machine_role")

default:
return fmt.Errorf("invalid source provided")
Expand Down
4 changes: 2 additions & 2 deletions internal/backend/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (s3Backend *S3Backend) GetConfig(ctx context.Context) (*config.Config, erro
return &configData, nil
}

func NewS3Backend(bucket, key, versionId, profile string) (BackendSource, error) {
client, err := NewS3Client(profile)
func NewS3Backend(ctx context.Context, bucket, key, versionId, profile string) (BackendSource, error) {
client, err := NewS3Client(ctx, profile)

if err != nil {
return nil, fmt.Errorf("not able to create s3 client: %w", err)
Expand Down
4 changes: 1 addition & 3 deletions internal/backend/s3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ func (c *S3BackendClient) GetObject(ctx context.Context, bucket string, key stri
return c.s3Client.GetObject(ctx, objectInput)
}

func NewS3Client(profile string) (S3Client, error) {
func NewS3Client(ctx context.Context, profile string) (S3Client, error) {
opts := []func(*s3Config.LoadOptions) error{}

if profile != "" {
opts = append(opts, s3Config.WithSharedConfigProfile(profile))
}

ctx := context.Background()

cfg, err := s3Config.LoadDefaultConfig(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("failed to load SDK configuration: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ImplementConfig(ctx context.Context, c *config.Config) error {

for _, f := range c.Files {
fmt.Println("Deploying file", f.Path)
err := services.FileDeploySvc.DeployFile(&f)
err := services.FileDeploySvc.DeployFile(ctx, &f)

if err != nil {
return fmt.Errorf("error deploying file %s: %w", f.Path, err)
Expand Down
8 changes: 7 additions & 1 deletion internal/service/file_deploy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"bufio"
"context"
"fmt"
"os"
"path/filepath"
Expand All @@ -12,7 +13,12 @@ import (
type FileDeploySvc struct {
}

func (s *FileDeploySvc) DeployFile(f *config.File) error {
func (s *FileDeploySvc) DeployFile(ctx context.Context, f *config.File) error {

if err := ctx.Err(); err != nil {
return err
}

if err := os.MkdirAll(filepath.Dir(f.Path), 0770); err != nil {
return fmt.Errorf("error creating required directories for %s: %w", f.Path, err)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/service/file_deploy_service_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package service

import (
"context"
"os"
"testing"

"github.com/aslamcodes/appstreamfile/internal/config"
)

func TestFileDeploy(t *testing.T) {
ctx := context.TODO()

file, err := os.CreateTemp("../../testdata", "test.txt")
defer func() {
os.Remove(file.Name())
Expand All @@ -24,7 +27,7 @@ func TestFileDeploy(t *testing.T) {

s := FileDeploySvc{}

s.DeployFile(f)
s.DeployFile(ctx, f)

content, err := os.ReadFile(f.Path)

Expand Down
4 changes: 4 additions & 0 deletions internal/service/installer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type InstallerSvc struct {
}

func (s *InstallerSvc) InstallScript(ctx context.Context, inst *config.Installer) error {
if err := ctx.Err(); err != nil {
return err
}

var (
exe string
ext string
Expand Down