Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getters refactoring #255

Merged
merged 113 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
527b5c1
Add SmbGetter
sylviamoss Mar 26, 2020
1fd6e4d
Validate smb path contains host and filepath, add tests
sylviamoss Mar 27, 2020
9fa2932
Fix format
sylviamoss Mar 27, 2020
2931f37
Test circleci with samba server
sylviamoss Apr 16, 2020
8663295
fix circleci config.yml
sylviamoss Apr 16, 2020
dc15b4c
fix circleci config.yml
sylviamoss Apr 16, 2020
6aec162
fix env on circleci config.yml
sylviamoss Apr 16, 2020
dc7d1ce
fix env on circleci config.yml
sylviamoss Apr 16, 2020
7219a8e
fix circleci config.yml one more time
sylviamoss Apr 16, 2020
84b332e
fix circleci config.yml at docker volume definition
sylviamoss Apr 16, 2020
e4c17c5
fix circleci config.yml at docker volume definition
sylviamoss Apr 16, 2020
04bbbaa
fix circleci config.yml at docker volume definition
sylviamoss Apr 16, 2020
95e4f30
cd to go-getter before go mod
sylviamoss Apr 16, 2020
5213d92
remove go mod
sylviamoss Apr 16, 2020
ce3e38e
split smb test
sylviamoss Apr 16, 2020
ba4819d
fix circleci config.yml
sylviamoss Apr 16, 2020
80ad6b3
remove logs and test docker exec
sylviamoss Apr 16, 2020
e6096b2
add working dir
sylviamoss Apr 16, 2020
7fb5703
add testing docker cmd
sylviamoss Apr 16, 2020
446b379
Add docker compose
sylviamoss Apr 16, 2020
61404b9
change golang image
sylviamoss Apr 16, 2020
6de5e77
add ls to circleci config
sylviamoss Apr 16, 2020
315b03f
sakda
sylviamoss Apr 16, 2020
89e52e9
try 1
sylviamoss Apr 16, 2020
b70d6cb
try 2
sylviamoss Apr 16, 2020
65c6cd6
try one more time
sylviamoss Apr 16, 2020
03e65b3
remove weird char
sylviamoss Apr 16, 2020
baf26a9
one last think
sylviamoss Apr 16, 2020
44f7ff8
run containers at the same time
sylviamoss Apr 17, 2020
4d3aa87
skip smb tests when env var is not set
sylviamoss Apr 17, 2020
8308b6e
add failing test to see what happens
sylviamoss Apr 17, 2020
24f6452
test smbclient
sylviamoss Apr 17, 2020
c31df12
remove comment
sylviamoss Apr 17, 2020
2541772
config back to normal
sylviamoss Apr 17, 2020
95366d5
adds struct test and test cases
sylviamoss Apr 17, 2020
42ad460
fmt and undo some unecessary changes
sylviamoss Apr 17, 2020
1bb624b
remove dst folder when created on smbclient
sylviamoss Apr 17, 2020
64fb020
add GetFile tests
sylviamoss Apr 20, 2020
679547a
write smb mode
sylviamoss Apr 20, 2020
9cecc40
write smb mode tests
sylviamoss Apr 20, 2020
116f648
fix fmt
sylviamoss Apr 20, 2020
130a20e
add mounted folder as test
sylviamoss Apr 20, 2020
76c6d38
remove pass from mount command
sylviamoss Apr 20, 2020
5d602d5
change mount sec type
sylviamoss Apr 20, 2020
625e7a1
change mount sec type
sylviamoss Apr 20, 2020
e4fade8
Try cleaning docker-compose
sylviamoss Apr 20, 2020
a1c9f21
Remove local mount tests and config
sylviamoss Apr 20, 2020
b426885
try back mounting samba folder
sylviamoss Apr 20, 2020
d3bdbe7
remove mount
sylviamoss Apr 20, 2020
b2674f8
add makefile and write tests
sylviamoss Apr 21, 2020
171bb46
download dir with smbclient
sylviamoss Apr 21, 2020
4e79911
update readme
sylviamoss Apr 21, 2020
42954ff
write better ests names and update makefile
sylviamoss Apr 21, 2020
acc21a1
test smb authentication in private shared folder
sylviamoss Apr 21, 2020
5fa9370
try to mount samba shared folder
sylviamoss Apr 21, 2020
33158fe
use dockerfile instead
sylviamoss Apr 22, 2020
62a9f0a
remove unecessary code from tests
sylviamoss Apr 22, 2020
075c973
fix destination path
sylviamoss Apr 22, 2020
02a1857
improve error msg
sylviamoss Apr 22, 2020
d670e78
Fix comment typo
sylviamoss Apr 23, 2020
7f77866
Fix error msg typo
sylviamoss Apr 23, 2020
de18f12
Fix comment typo
sylviamoss Apr 23, 2020
39c210b
Fix comment typo
sylviamoss Apr 23, 2020
097b777
improve error messaging
sylviamoss Apr 23, 2020
af77482
update readme
sylviamoss Apr 23, 2020
f9b00b7
Merge branch 'add_smb_getter' of github.com:hashicorp/go-getter into …
sylviamoss Apr 23, 2020
b350351
fix format
sylviamoss Apr 23, 2020
447c3f6
Add smbdetector and client tests
sylviamoss Apr 24, 2020
e520fc4
Update readme
sylviamoss Apr 24, 2020
aaafb58
remove testing log
sylviamoss Apr 24, 2020
c326e24
user smbclient command directly
sylviamoss Apr 27, 2020
337def6
rename err variable
sylviamoss Apr 27, 2020
0238bda
User filegetter only for windows when it's available
sylviamoss Apr 27, 2020
ebf89a3
update readme
sylviamoss Apr 27, 2020
ed2ff25
fix comment description
sylviamoss Apr 27, 2020
d4b40f1
big getter refactoring
sylviamoss Apr 30, 2020
ac4a6cb
fix format
sylviamoss Apr 30, 2020
66ada4f
create detector chain of responsibility
sylviamoss May 4, 2020
fe63e44
Solve todos and improve comments
sylviamoss May 4, 2020
bed918b
Add smb windows getter
sylviamoss May 5, 2020
f0c903b
Add missing next to detector
sylviamoss May 5, 2020
2bd83fd
Update smbmountgetter
sylviamoss May 5, 2020
7f4c3d1
fix format
sylviamoss May 5, 2020
4516534
make chain a loop
sylviamoss May 6, 2020
cfb908e
loop over getters and detect for each
sylviamoss May 7, 2020
e13d3ca
Remove ValidScheme api and move some detection logic to Getters
sylviamoss May 7, 2020
9608b60
change error handling
sylviamoss May 7, 2020
0a667db
Merge branch 'v2' into getters_refactoring
sylviamoss May 7, 2020
227cd74
fix path slash for windows
sylviamoss May 7, 2020
816685a
Update Request on detection
sylviamoss May 7, 2020
00cab94
Fix tests
sylviamoss May 7, 2020
5f3ee0e
Fix error msg
sylviamoss May 7, 2020
913107c
Merge branch 'v2' into getters_refactoring
sylviamoss May 11, 2020
7334366
fix fmt
sylviamoss May 11, 2020
8af9373
Fix build fail
sylviamoss May 11, 2020
ad53e85
Fix some code organization
sylviamoss May 11, 2020
caf16e8
improve error handling
sylviamoss May 11, 2020
39a5cf7
fix main.go
sylviamoss May 11, 2020
1636ace
logs to test windows tests on circleci
sylviamoss May 11, 2020
9e480d6
make filegetter accept win c:/ filepaths
sylviamoss May 11, 2020
e9fff33
override request directly
sylviamoss May 11, 2020
93a026d
Move some tests and make the code look better'
sylviamoss May 12, 2020
12cc1d0
Fix fmt
sylviamoss May 12, 2020
cee4ecd
Fix windows test
sylviamoss May 12, 2020
c5d18ea
Update Detect interface comment
sylviamoss May 13, 2020
7327304
Update SmbMountGetter
sylviamoss May 13, 2020
209cb28
Update README
sylviamoss May 13, 2020
a3dc9e0
Test refactoring circleci config
sylviamoss May 19, 2020
b1504cd
Merge branch 'v2' into getters_refactoring
sylviamoss May 28, 2020
95f553a
move detectors back and add them to getters
sylviamoss May 28, 2020
7072459
Add detector tests back
sylviamoss Jun 2, 2020
6e2f08e
Make SmbMountGetter MacOS and Windows specific
sylviamoss Jun 2, 2020
1ab379b
Explain better the code in comments
sylviamoss Jun 2, 2020
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
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ jobs:
- store_artifacts:
path: *WIN_TEST_RESULTS

go-smb-test:
docker:
- image: circleci/golang:<< parameters.go-version >>
parameters:
go-version:
type: string
steps:
- checkout
- setup_remote_docker
- run:
name: build and start smb server and gogetter containers
command: |
docker-compose build
docker-compose up -d

- run:
name: wait for containers to start
command: sleep 60

- run:
name: run smb getter tests
command: |
docker exec -it gogetter bash -c "env ACC_SMB_TEST=1 go test -v ./... -run=TestSmb_"

workflows:
go-getter:
jobs:
Expand All @@ -190,3 +214,7 @@ workflows:
go-version: ["1.14.1"]
gotestsum-version: ["0.4.1"]
name: win-test-go-<< matrix.go-version >>
- go-smb-test:
matrix:
parameters:
go-version: ["1.14.1"]
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dockerfile to create a go-getter container with smbclient dependency that is used by the get_smb.go tests
FROM golang:latest

COPY . /go-getter
WORKDIR /go-getter

RUN go mod download
RUN apt-get update
RUN apt-get -y install smbclient
9 changes: 9 additions & 0 deletions Dockerfile-smbserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dockerfile to create a smb server that is used by the get_smb.go tests
FROM dperson/samba

# Create shared folders
RUN mkdir -p /public && mkdir -p /private

# Create shared files and directories under the shared folders (data and mnt)
RUN echo 'Hello' > /public/file.txt && mkdir -p /public/subdir && echo 'Hello' > /public/subdir/file.txt
RUN echo 'Hello' > /private/file.txt && mkdir -p /private/subdir && echo 'Hello' > /private/subdir/file.txt
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
start-smb:
@docker-compose build
docker-compose up -d samba

smbtests-prepare:
@docker-compose build
@docker-compose up -d
@sleep 60

smbtests:
@docker cp ./ gogetter:/go-getter/
@docker exec -it gogetter bash -c "env ACC_SMB_TEST=1 go test -v ./... -run=TestSmb_"
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ can be augmented at runtime by implementing the `Getter` interface.
* HTTP
* Amazon S3
* Google GCP
* SMB

In addition to the above protocols, go-getter has what are called "detectors."
These take a URL and attempt to automatically choose the best protocol for
Expand Down Expand Up @@ -360,3 +361,45 @@ In order to access to GCS, authentication credentials should be provided. More i
#### GCS Testing

The tests for `get_gcs.go` require you to have GCP credentials set in your environment. These credentials can have any level of permissions to any project, they just need to exist. This means setting `GOOGLE_APPLICATION_CREDENTIALS="~/path/to/credentials.json"` or `GOOGLE_CREDENTIALS="{stringified-credentials-json}"`. Due to this configuration, `get_gcs_test.go` will fail for external contributors in CircleCI.

### SMB (smb)

There are two options that go-getter will use to download a file in a smb shared folder. The first option uses
[`smbclient`](https://www.samba.org/samba/docs/current/man-html/smbclient.1.html) and the second one uses the file system
to look for a file in a local mount of the shared folder in the OS specific volume folder. go-getter will try to download
files from a smb shared folder whenever the url is prefixed with `smb://`.

⚠️ The [`smbclient`](https://www.samba.org/samba/docs/current/man-html/smbclient.1.html) command is available only for Linux.
This is the ONLY option for a Linux user and therefore the client must be installed.

The `smbclient` cli is not available for Windows and MacOS. The go-getter
will try to get files using the file system, when this happens the getter uses the FileGetter implementation.

When connecting to a smb server, the OS creates a local mount in a system specific volume folder, and go-getter will
try to access the following folders when looking for local mounts.

- MacOS: /Volumes/<shared_path>
- Windows: \\\\\<host>\\\<shared_path>

The following examples work for all the OSes:
- smb://host/shared/dir (downloads directory content)
- smb://host/shared/dir/file (downloads file)

The following examples work for Linux:
- smb://username:password@host/shared/dir (downloads directory content)
- smb://username@host/shared/dir
- smb://username:password@host/shared/dir/file (downloads file)
- smb://username@host/shared/dir/file

⚠️ The above examples also work on the other OSes but the authentication is not used to access the file system.



#### SMB Testing
The test for `get_smb.go` requires a smb server running which can be started inside a docker container by
running `make start-smb`. Once the container is up the shared folder can be accessed via `smb://<ip|name>/public/<dir|file>` or
`smb://user:password@<ip|name>/private/<dir|file>` by another container or machine in the same network.

To run the tests inside `get_smb_test.go` and `client_test.go`, prepare the environment with `make smbtests-prepare`. On prepare some
mock files and directories will be added to the shared folder and a go-getter container will start together with the samba server.
Once the environment for testing is prepared, run `make smbtests` to run the tests.
Loading