Skip to content
Open
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
Empty file removed src/.gitkeep
Empty file.
18 changes: 10 additions & 8 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
spec_file = server/spec/synche-server-api.yaml
spec_file = synche-server-api2.yaml
build_dir = ../build
schema_dir = schema

generate:
# important: the principal should be set to schema.User
swagger generate spec -m -w $(schema_dir) -i $(spec_file) -o $(spec_file)

swagger generate server \
--name Synche \
--spec $(spec_file) \
--principal gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/database/schema.User \
--principal github.com/xy3/synche/src/server/schema.User \
--flag-strategy=pflag \
--exclude-main \
-t server
--target server

swagger generate client \
--spec $(spec_file) \
-c apiclient \
-t client
-c client


build:
go build -o $(build_dir)/synche client/main.go && \
go build -o $(build_dir)/synche-server server/main.go
go build -o $(build_dir)/synche cmd/client/main.go && \
go build -o $(build_dir)/synched cmd/server/main.go
14 changes: 7 additions & 7 deletions src/client/apiclient/auth.go → src/client/auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apiclient
package client

import (
"context"
Expand All @@ -7,10 +7,10 @@ import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
log "github.com/sirupsen/logrus"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/apiclient/tokens"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/apiclient/users"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/models"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/files"
"github.com/xy3/synche/src/client/tokens"
users2 "github.com/xy3/synche/src/client/users"
"github.com/xy3/synche/src/files"
"github.com/xy3/synche/src/models"
"golang.org/x/crypto/ssh/terminal"
"os"
"time"
Expand Down Expand Up @@ -47,7 +47,7 @@ func AuthenticateClient(tokenFile string) error {

// Login Logs in user with their email and password
func Login(email, password string) (*models.AccessAndRefreshToken, error) {
resp, err := Client.Users.Login(&users.LoginParams{
resp, err := Client.Users.Login(&users2.LoginParams{
Email: email,
Password: password,
Context: context.Background(),
Expand Down Expand Up @@ -76,7 +76,7 @@ func TerminalLogin() (*models.AccessAndRefreshToken, error) {
// checkTokenWorks Validates token
func checkTokenWorks(accessToken string) error {
tempAuth := httptransport.APIKeyAuth("X-Token", "header", accessToken)
_, err := Client.Users.Profile(&users.ProfileParams{Context: context.Background()}, tempAuth)
_, err := Client.Users.Profile(&users2.ProfileParams{Context: context.Background()}, tempAuth)

return err
}
Expand Down
10 changes: 5 additions & 5 deletions src/client/apiclient/auth_test.go → src/client/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package apiclient
package client

import (
"encoding/json"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/models"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/files"
"github.com/xy3/synche/src/files"
"github.com/xy3/synche/src/models"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -69,8 +69,8 @@ func TestGetSavedToken(t *testing.T) {
t.Errorf("getSavedToken: Invalid token")
}

files.AppFS.Remove(testDir)
files.AppFS.Remove(testFile)
_ = files.AppFS.Remove(testDir)
_ = files.AppFS.Remove(testFile)

t.Log("getSavedToken: All tests passed")
}
11 changes: 5 additions & 6 deletions src/client/upload/chunk.go → src/client/chunk.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package upload
package client

import (
"bytes"
"context"
"github.com/go-openapi/runtime"
log "github.com/sirupsen/logrus"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/apiclient"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/apiclient/transfer"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/data"
"github.com/xy3/synche/src/client/transfer"
"github.com/xy3/synche/src/files"
"sync"
"time"
)
Expand All @@ -24,7 +23,7 @@ func AsyncChunkUpload(wg *sync.WaitGroup, params *transfer.UploadChunkParams, up
timeout <- true
}()

resp, err := apiclient.Client.Transfer.UploadChunk(params, apiclient.ClientAuth)
resp, err := Client.Transfer.UploadChunk(params, ClientAuth)
if err != nil {
uploadErrors <- err
log.Error(err)
Expand All @@ -42,7 +41,7 @@ func AsyncChunkUpload(wg *sync.WaitGroup, params *transfer.UploadChunkParams, up
return
}

func NewChunkUploadParams(chunk data.Chunk, fileID uint64) *transfer.UploadChunkParams {
func NewChunkUploadParams(chunk files.Chunk, fileID uint64) *transfer.UploadChunkParams {
chunkData := runtime.NamedReader(chunk.Hash, bytes.NewReader(*chunk.Bytes))
return &transfer.UploadChunkParams{
ChunkData: chunkData,
Expand Down
17 changes: 8 additions & 9 deletions src/client/upload/chunk_test.go → src/client/chunk_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package upload_test
package client_test

import (
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/data"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/upload"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/files"
"github.com/xy3/synche/src/client"
"github.com/xy3/synche/src/files"
"testing"
)

func TestChunkUpload_NewParams(t *testing.T) {
files.SetFileSystem(afero.NewMemMapFs())

testCases := []struct {
Name string
Chunk data.Chunk
FileID uint64
Name string
Chunk files.Chunk
FileID uint64
ChunkBytes []byte
ExpectedError error
}{
{
Chunk: data.Chunk{Hash: "hash", Num: 1},
Chunk: files.Chunk{Hash: "hash", Num: 1},
FileID: 1,
ChunkBytes: []byte("test file content"),
ExpectedError: nil,
Expand All @@ -30,7 +29,7 @@ func TestChunkUpload_NewParams(t *testing.T) {
t.Run(
tc.Name, func(t *testing.T) {
tc.Chunk.Bytes = &tc.ChunkBytes
params := upload.NewChunkUploadParams(tc.Chunk, tc.FileID)
params := client.NewChunkUploadParams(tc.Chunk, tc.FileID)
if tc.ExpectedError == nil {
require.Equal(t, tc.FileID, params.FileID)
require.Equal(t, tc.Chunk.Num, params.ChunkNumber)
Expand Down
11 changes: 5 additions & 6 deletions src/client/config/config.go → src/client/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package config
package client

import (
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/client/apiclient"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/config"
"github.com/xy3/synche/src/config"
"path"
)

Expand All @@ -18,9 +17,9 @@ var Config = Configuration{
Workers: 10,
},
Server: ServerConfig{
Host: apiclient.DefaultHost,
BasePath: apiclient.DefaultBasePath,
Https: len(apiclient.DefaultSchemes) > 1,
Host: DefaultHost,
BasePath: DefaultBasePath,
Https: len(DefaultSchemes) > 1,
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package config
package client

import (
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/config"
"gitlab.computing.dcu.ie/collint9/2021-ca400-collint9-coynemt2/src/files"
"github.com/xy3/synche/src/config"
"github.com/xy3/synche/src/files"
"testing"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apiclient
package client

import (
httptransport "github.com/go-openapi/runtime/client"
Expand Down
15 changes: 0 additions & 15 deletions src/client/data/chunk.go

This file was deleted.

146 changes: 146 additions & 0 deletions src/client/files/create_dir_path_parameters.go

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

Loading