Skip to content

Commit 5f3e150

Browse files
added build test (#5)
1 parent 8173cc6 commit 5f3e150

11 files changed

+172
-86
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Connector-Zenko Changelog
1+
# Storj-Zenko Changelog
22

3-
## [1.0.5] - 17-08-2020
3+
## [1.0.5] - 01-09-2020
44
### Changelog:
5-
* Resolved upload path issue.
5+
* Added test file for CI-CD pipeline.
66

77
## [1.0.5] - 22-05-2020
88
### Changelog:

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM golang:1.15
2+
RUN mkdir /app
3+
COPY . /app/
4+
WORKDIR /app/cmd
5+
RUN go test -v main_test.go

README.assets/Home.md

+30-14
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22

33
![](https://github.com/storj-thirdparty/connector-zenko/blob/master/README.assets/arch.drawio.png)
44

5-
65
## Config Files
6+
77
There are two config files that contain Storj network and Zenko connection information. The tool is designed so you can specify a config file as part of your tooling/workflow.
88

9-
##### ```zenko_property.json```
10-
Inside the ```./config``` directory there is a ```zenko_property.json``` file, with following information about your Zenko instance:
9+
### `zenko_property.json`
10+
11+
Inside the `/config` directory there is a `zenko_property.json` file, with following information about your Zenko instance:
1112

1213
* zenkoEndpoint - S3 End point of Zenko Instance
1314
* accessKeyID - S3 Access Key ID created in Zenko Instance
1415
* secretAccessKey - S3 Secret Access Key created in Zenko Instance
1516

16-
##### ```storj_config.json```
17-
Inside the ```./config``` directory a ```storj_config.json``` file, with Storj network configuration information in JSON format:
17+
### `storj_config.json`
18+
Inside the `./config` directory a `storj_config.json` file, with Storj network configuration information in JSON format:
1819

1920
* apiKey - API Key created in Storj Satellite GUI
2021
* satelliteURL - Storj Satellite URL
2122
* encryptionPassphrase - Storj Encryption Passphrase.
2223
* bucket - Name of the bucket to upload data into.
23-
* uploadPath - Path on Storj Bucket to store data (optional) or "" or "/" (mandatory)
24+
* uploadPath - Path on Storj Bucket to store data (optional) or "/"
2425
* serializedAccess - Serialized access shared while uploading data used to access bucket without API Key
2526
* allowDownload - Set true to create serialized access with restricted download
2627
* allowUpload - Set true to create serialized access with restricted upload
@@ -30,48 +31,63 @@ Inside the ```./config``` directory a ```storj_config.json``` file, with Storj n
3031
* notAfter - Set time that is always after notBefore
3132

3233
## Run
34+
3335
Zenko files are iterated through and streamed in 32KB chunks to the Storj network.
3436

35-
The following flags can be used with the ```store``` command:
37+
The following flags can be used with the `store` command:
3638

37-
* ```accesskey``` - Connects to the Storj network using a serialized access key instead of an API key, satellite url and encryption passphrase .
38-
* ```share``` - Generates a restricted shareable serialized access with the restrictions specified in the Storj configuration file.
39+
* `accesskey` - Connects to the Storj network using a serialized access key instead of an API key, satellite url and encryption passphrase.
40+
* `share` - Generates a restricted shareable serialized access with the restrictions specified in the Storj configuration file.
3941

4042
Once you have built the project you can run the following:
4143

42-
##### Get help
44+
### Get help
45+
4346
```
4447
$ ./connector-zenko --help
4548
```
46-
##### Check version
49+
50+
### Check version
51+
4752
```
4853
$ ./connector-zenko version
4954
```
50-
##### Create backup from Zenko and upload them to Storj
55+
56+
### Create backup from Zenko and upload them to Storj
57+
5158
```
5259
$ ./connector-zenko store --zenko <path_to_zenko_config_file> --storj <path_to_storj_config_file>
5360
```
54-
##### Create backup files from Zenko and upload them to Storj bucket using Access Key
61+
62+
### Create backup files from Zenko and upload them to Storj bucket using Access Key
63+
5564
```
5665
$ ./connector-zenko store --accesskey
5766
```
58-
##### Create backup files from Zenko and upload them to Storj and generate a Shareable Access Key based on restrictions in ```storj_config.json```.
67+
68+
### Create backup files from Zenko and upload them to Storj and generate a Shareable Access Key based on restrictions in `storj_config.json`.
69+
5970
```
6071
$ ./connector-zenko store --share
6172
```
6273
6374
## Testing
75+
6476
* The project has been tested on the following operating systems:
77+
6578
```
6679
* Windows
6780
* Version: 10 Pro
6881
* Processor: Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz 2.00GHz
82+
* Zenko version: v1.2.0
6983
7084
* macOS Catalina
7185
* Version: 10.15.4
7286
* Processor: 2.5 GHz Dual-Core Intel Core i5
87+
* Zenko version: v1.2.0
7388
7489
* ubuntu
7590
* Version: 16.04 LTS
7691
* Processor: AMD A6-7310 APU with AMD Radeon R4 Graphics × 4
92+
* Zenko version: v1.2.0
7793
```

README.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
[![Go Report Card](https://goreportcard.com/badge/github.com/storj-thirdparty/connector-zenko)](https://goreportcard.com/report/github.com/storj-thirdparty/connector-zenko)
55
![Cloud Build](https://storage.googleapis.com/storj-utropic-services-badges/builds/connector-zenko/branches/master.svg)
66

7-
87
## Overview
98

109
Command line application (on Windows/Linux/Mac) for taking data backup from Zenko to Storj. Application connects to Zenko server and the souce code for interaction to Storj for cloud storage which is written in Golang.
1110

1211
Zenko is infrastructure software to control Data in Multi-Cloud IT Environments without cloud lock-in and has features such as enabling unified data management from anywhere through a secure cloud portal, providing a single S3 endpoint through which data can be stored, retrieved and searched across any location.
1312

1413
### Features of connector-zenko:
14+
1515
* Connects S3 compatible cloud storages (e.g. Amazon AWS, Azure Blob, Google Cloud Storage, Wasabi) to the Zenko instance for backing up their data to StorJ V3 network.
1616
* Upload any type of data from Zenko to Storj (single or multiple at once) whether it is a folder, document, data file, image, video, etc.
1717
```
@@ -26,49 +26,63 @@ Available Commands:
2626

2727
```store``` - Connect to the specified Zenko instance (default: ```zenko_property.json```). Backups of the Zenko storage are generated using tooling provided by Zenko then uploaded to the Storj network. Connect to a Storj v3 network using the access specified in the Storj configuration file (default: ```storj_config.json```).
2828

29-
3029
Sample configuration files are provided in the ```./config``` folder.
3130

3231
## Requirements and Install
32+
3333
To build from scratch, [install the latest Go](https://golang.org/doc/install#install).
3434

3535
> Note: Ensure go modules are enabled (GO111MODULE=on)
3636
3737
#### Option #1: clone this repo (most common)
38+
3839
To clone the repo
40+
3941
```
4042
git clone https://github.com/storj-thirdparty/connector-zenko.git
4143
```
44+
4245
Then, build the project using the following:
46+
4347
```
4448
cd connector-zenko
4549
go build
4650
```
51+
4752
#### Option #2: go get into your gopath
53+
4854
To download the project inside your GOPATH use the following command:
55+
4956
```
5057
go get github.com/storj-thirdparty/connector-zenko
5158
```
59+
5260
## Run (short version)
61+
5362
Once you have built the project run the following commands as per your requirement:
5463

5564
##### Get help
65+
5666
```
5767
$ ./connector-zenko --help
5868
```
69+
5970
##### Check version
71+
6072
```
6173
$ ./connector-zenko --version
6274
```
75+
6376
##### Create backup from Zenko and upload to Storj
77+
6478
```
6579
$ ./connector-zenko store
6680
```
81+
6782
## Documentation
6883

6984
For more information on runtime flags, configuration, testing, and diagrams, check out the [Detail](//github.com/storj-thirdparty/connector-zenko/wiki) or jump to:
7085

71-
7286
* [Config Files](//github.com/storj-thirdparty/connector-zenko/wiki/#config-files)
7387
* [Run (long version)](//github.com/storj-thirdparty/connector-zenko/wiki/#run)
7488
* [Testing](//github.com/storj-thirdparty/connector-zenko/wiki/#testing)

cloudbuild.yaml

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
steps:
2-
# see https://www.npmjs.com/package/editorconfig-checker
2+
- name: gcr.io/cloud-builders/gcloud
3+
entrypoint: 'bash'
4+
args: ["-c","gcloud secrets versions access latest --secret=testFile >>testFile.txt" ]
5+
- name: gcr.io/cloud-builders/gcloud
6+
entrypoint: 'bash'
7+
args: ["-c","gcloud secrets versions access latest --secret=connector_secret >>./config/storj_config_test.json" ]
8+
- name: gcr.io/cloud-builders/docker
9+
args: ['build', '-t', 'gcr.io/$PROJECT_ID/connector-zenko', '.']
310
- id: eclint
411
name: "e53e225/editorconfig-checker"
512
- id: go_version
613
name: "gcr.io/cloud-builders/go"
714
args: ["version"]
8-
env: ["GOPATH=."]
15+
env: ["GOPATH=."]
916
- id: go_linter
1017
name: "golangci/golangci-lint"
1118
args: ["golangci-lint","run"]
12-
env: ["GO111MODULE=on", "CGO_ENABLED=0"]
13-
- id: go_security
14-
name: "securego/gosec"
15-
args: [ "./..." ]
19+
env: ["GO111MODULE=on", "CGO_ENABLED=0"]
1620
- id: go_build
1721
name: "mirror.gcr.io/library/golang"
1822
env: ['GO111MODULE=on']
1923
args: ['go', 'build', './...']
2024
- id: doc_check
2125
name: "ubuntu"
2226
args: ['bash', './test/doc-check.sh']
23-
# name: "gcr.io/cloud-builders/go"
24-
# args: ["build"]
25-
# env: ["GOPATH=.","GO111MODULE=on", "CGO_ENABLED=0"]
26-
# - id: go_test
27-
# name: "gcr.io/cloud-builders/go"
28-
# args: ["test","helloworld"]
29-
# env: ["GOPATH=."]
27+
- id: go_security
28+
name: "securego/gosec"
29+
args: ["./..." ]
30+
31+
tags: ['cloud-builders-community']
32+
images: ['gcr.io/$PROJECT_ID/connector-zenko']
33+
tags: ['cloud-builders-community']

cmd/main_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cmd_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"os"
8+
9+
"testing"
10+
11+
"github.com/storj-thirdparty/connector-zenko/cmd"
12+
)
13+
14+
func TestZenkoStore(t *testing.T) {
15+
16+
testFlag := true
17+
18+
storjConfig := cmd.LoadStorjConfiguration("../config/storj_config_test.json")
19+
_, project := cmd.ConnectToStorj(storjConfig, false)
20+
21+
fileReader, err := os.Open("../testFile.txt")
22+
if err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
fmt.Printf("Initiating back-up.\n")
27+
cmd.UploadData(project, storjConfig, "testFile.txt", nil, fileReader, testFlag)
28+
fmt.Printf("Back-up complete.\n\n")
29+
30+
fmt.Printf("\nDeleting the test back-up.\n")
31+
ctx := context.Background()
32+
backups := project.ListObjects(ctx, storjConfig.Bucket, nil)
33+
// Loop to find the latest back-up of all the back-ups.
34+
for backups.Next() {
35+
item := backups.Item()
36+
_, err := project.DeleteObject(ctx, storjConfig.Bucket, item.Key)
37+
if err != nil {
38+
log.Fatal(err)
39+
}
40+
}
41+
fmt.Printf("Deleted the test back-up.\n")
42+
}

cmd/store.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func init() {
2828

2929
func zenkoStore(cmd *cobra.Command, args []string) {
3030

31+
testFlag := false
32+
3133
// Process arguments from the CLI.
3234
zenkoConfigfilePath, _ := cmd.Flags().GetString("zenko")
3335
fullFileNameStorj, _ := cmd.Flags().GetString("storj")
@@ -41,7 +43,7 @@ func zenkoStore(cmd *cobra.Command, args []string) {
4143
storjConfig := LoadStorjConfiguration(fullFileNameStorj)
4244

4345
// Connect to storj network using the specified credentials.
44-
access, project := ConnectToStorj(fullFileNameStorj, storjConfig, useAccessKey)
46+
access, project := ConnectToStorj(storjConfig, useAccessKey)
4547

4648
// Establish connection with Zenko and get io.Reader implementor.
4749
zenkoReader := ConnectToZenko(configZenko)
@@ -52,7 +54,7 @@ func zenkoStore(cmd *cobra.Command, args []string) {
5254
fmt.Printf("\nInitiating back-up.\n")
5355
// Fetch all backup files from Zenko instance and simultaneously store them into desired Storj bucket.
5456
for i := 0; i < len(uploadPathNames); i++ {
55-
UploadData(project, storjConfig, uploadPathNames[i], zenkoObjectReaders[i])
57+
UploadData(project, storjConfig, uploadPathNames[i], zenkoObjectReaders[i], nil, testFlag)
5658
}
5759
fmt.Printf("\nBack-up complete.\n\n")
5860

0 commit comments

Comments
 (0)