Skip to content

Commit

Permalink
Merge pull request #1 from bosch-io/init-contrib
Browse files Browse the repository at this point in the history
Eclipse Kanto File Upload initial contribution
  • Loading branch information
konstantina-gramatova authored Feb 11, 2022
2 parents d9c499d + f5452b4 commit a264566
Show file tree
Hide file tree
Showing 30 changed files with 4,187 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.go text eol=lf
45 changes: 45 additions & 0 deletions .github/workflows/validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Validation

on:
pull_request:
branches:
- main
paths-ignore:
- "**/*.md"
push:
branches:
- main
paths-ignore:
- "**/*.md"

jobs:
validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.17.2'
- name: Setup
run: |
go mod download
go install golang.org/x/lint/golint@latest
go get -t ./...
- name: Format
run: |
unformatted_code=$(gofmt -l .)
if [ -n "$unformatted_code" ]; then
echo "Improperly formatted code:"
echo "$unformatted_code"
exit 1
fi
- name: Lint
run: |
golint -set_exit_status ./...
- name: Vet
run: |
go vet ./...
- name: Test
run: |
go test ./... -coverprofile coverage.out -covermode count
go tool cover -func coverage.out
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/log/
.idea/
.vscode/
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# How to Contribute to Eclipse Kanto - File Upload

First of all, thanks for considering to contribute to Eclipse Kanto - File Upload. We really
appreciate the time and effort you want to spend helping to improve things around here.

In order to get you started as fast as possible we need to go through some organizational issues first, though.

## Eclipse Contributor Agreement

Before your contribution can be accepted by the project team contributors must
electronically sign the Eclipse Contributor Agreement (ECA).

* http://www.eclipse.org/legal/ECA.php

Commits that are provided by non-committers must have a Signed-off-by field in
the footer indicating that the author is aware of the terms by which the
contribution has been provided to the project. The non-committer must
additionally have an Eclipse Foundation account and must have a signed Eclipse
Contributor Agreement (ECA) on file.

For more information, please see the Eclipse Committer Handbook:
https://www.eclipse.org/projects/handbook/#resources-commit

## Code Style Guide

* Keep the code well-formatted through: `gofmt`
* Keep the code error-free through: `go vet` and `golint`
* Avoid common mistakes and pitfalls following: [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)

## Making Your Changes

* Fork the repository on GitHub.
* Create a new branch for your changes.
* Make your changes following the code style guide (see Code Style Guide section above).
* When you create new files make sure you include a proper license header at the top of the file (see License Header section below).
* Make sure you include test cases for non-trivial features.
* Make sure test cases provide sufficient code coverage (see GitHub actions for minimal accepted coverage).
* Make sure the test suite passes after your changes.
* Commit your changes into that branch.
* Use descriptive and meaningful commit messages. Start the first line of the commit message with the issue number and titile e.g. `[#9865] Add token based authentication`.
* Squash multiple commits that are related to each other semantically into a single one.
* Make sure you use the `-s` flag when committing as explained above.
* Push your changes to your branch in your forked repository.

## License Header

Please make sure any file you newly create contains a proper license header like this:

Adjusted for Go files:
```go
// Copyright (c) <year> Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0
```

## Submitting the Changes

Submit a pull request via the normal GitHub UI.

## After Submitting

* Do not use your branch for any other development, otherwise further changes that you make will be visible in the PR.
163 changes: 163 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Notices for Eclipse Kanto - File Upload

This content is produced and maintained by the Eclipse Kanto project.

* Project home: https://eclipse.org/kanto

## Trademarks

Eclipse Kanto, and the Eclipse Kanto Logo are trademarks of the Eclipse Foundation.
Eclipse, and the Eclipse Logo are registered trademarks of the Eclipse Foundation.

## Copyright

All content is the property of the respective authors or their employers.
For more information regarding authorship of content, please consult the
listed source code repository logs.

## Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License v2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

## Source Code

The project maintains all source code repositories in the following GitHub organization:

* https://github.com/eclipse-kanto

## Third-party Content

This project makes use of the follow third party projects.

eclipse/paho.mqtt.golang (1.3.5)

* License: Eclipse Distribution License v1.0
* Project: https://github.com/eclipse/paho.mqtt.golang
* Source: https://github.com/eclipse/paho.mqtt.golang/releases/tag/v1.3.5

eclipse/ditto-clients-golang (v0.0.0-20211126080253-3e1c6149fede)

* License: Eclipse Public License v2.0
* Project: https://github.com/eclipse/ditto-clients-golang
* Source: https://github.com/eclipse/ditto-clients-golang/tree/3e1c6149fedef558ee14270fec671abc77e36d7c

aws/aws-sdk-go-v2 (1.5.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2
* Source: https://github.com/aws/aws-sdk-go-v2/releases/tag/v1.5.0

aws/aws-sdk-go-v2/config (1.2.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/config
* Source: https://github.com/aws/aws-sdk-go-v2/tree/config/v1.2.0/config

aws/aws-sdk-go-v2/credentials (1.2.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/credentials
* Source: https://github.com/aws/aws-sdk-go-v2/tree/credentials/v1.2.0/credentials

aws/aws-sdk-go-v2/feature/ec2/imds (1.1.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/feature/ec2/imds
* Source: https://github.com/aws/aws-sdk-go-v2/tree/feature/ec2/imds/v1.1.0/feature/ec2/imds

aws/aws-sdk-go-v2/feature/s3/manager (1.2.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/feature/s3/manager
* Source: https://github.com/aws/aws-sdk-go-v2/tree/feature/s3/manager/v1.2.0/feature/s3/manager

aws/aws-sdk-go-v2/service/internal/accept-encoding (1.1.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/service/internal/accept-encoding
* Source: https://github.com/aws/aws-sdk-go-v2/tree/service/internal/accept-encoding/v1.2.0/service/internal/accept-encoding

aws/aws-sdk-go-v2/service/internal/presigned-url (1.1.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/service/internal/presigned-url
* Source: https://github.com/aws/aws-sdk-go-v2/tree/service/internal/presigned-url/v1.1.0/service/internal/presigned-url

aws/aws-sdk-go-v2/service/internal/s3shared (1.3.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/service/internal/s3shared
* Source: https://github.com/aws/aws-sdk-go-v2/tree/service/internal/s3shared/v1.3.0/service/internal/s3shared

aws/aws-sdk-go-v2/service/s3 (1.7.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/service/s3
* Source: https://github.com/aws/aws-sdk-go-v2/tree/service/s3/v1.7.0/service/s3

aws/aws-sdk-go-v2/service/sso (1.2.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/service/sso
* Source: https://github.com/aws/aws-sdk-go-v2/tree/service/sso/v1.2.0/service/sso

aws/aws-sdk-go-v2/service/sts (1.4.0)

* License: Apache License v2.0
* Project: https://github.com/aws/aws-sdk-go-v2/tree/main/service/sts
* Source: https://github.com/aws/aws-sdk-go-v2/tree/service/sts/v1.4.0/service/sts

aws/smithy-go (1.4.0)

* License: Apache License v2.0
* Project: https://github.com/aws/smithy-go
* Source: https://github.com/aws/smithy-go/tree/v1.4.0

jmespath/go-jmespath (v0.4.0)

* License: Apache License v2.0
* Project: https://github.com/jmespath/go-jmespath
* Source: https://github.com/jmespath/go-jmespath/tree/v0.4.0

natefinch/lumberjack (2.0.0)

* License: MIT License
* Project: https://gopkg.in/natefinch/lumberjack
* Source: https://github.com/natefinch/lumberjack/releases/tag/v2.0.0

google/uuid (1.3.0)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/google/uuid
* Source: https://github.com/google/uuid/releases/tag/v1.3.0

gorilla/websocket (1.4.2)

* License: BSD 2-Clause "Simplified" License
* Project: https://github.com/gorilla/websocket
* Source: https://github.com/gorilla/websocket/releases/tag/v1.4.2

golang/go (1.17.2)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/golang/go
* Source: https://github.com/golang/go/releases/tag/go1.17.2

golang.org/x/net (v0.0.0-20211123203042-d83791d6bcd9)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://pkg.go.dev/golang.org/x/net
* Source: https://github.com/golang/net/tree/d83791d6bcd9ec2bdaacd08f4da4718370382c74

## Cryptography

Content may contain encryption software. The country in which you are currently
may have restrictions on the import, possession, and use, and/or re-export to
another country, of encryption software. BEFORE using any encryption software,
please check the country's laws, regulations and policies concerning the import,
possession, or use, and re-export of encryption software, to see if this is
permitted.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
![Kanto logo](https://github.com/eclipse-kanto/kanto/raw/master/logo/kanto.svg)

# Eclipse Kanto - File Upload

## Overview

File upload between the edge and the cloud backend can enable a variety of use cases related to edge diagnostics and monitoring, as well as system backup and restore.

The file upload functionality gives the ability to configure the edge from the backend to send files periodically, or for the backend to explicitly trigger file upload from the device.

Files can be uploaded to different storage providers, currently including AWS and standard HTTP upload.

File Upload implements the [AutoUploadable](https://github.com/eclipse/vorto/tree/development/models/com.bosch.iot.suite.manager.upload-AutoUploadable-1.0.0.fbmodel) Vorto model.

### Capabilities include:

* HTTP upload - HTTP file upload, using backend provided pre-signed URL and authentications headers.
* AWS upload - upload through AWS SDK, using backend provided AWS temporary credentials.
* Periodic uploads - periodically trigger uploads at specified intervals.
* Activity period - schedule periodic uploads for specified time frame.
* Files filter - select files to be uploaded using glob pattern.
* Delete uploaded - delete locally files which were successfully uploaded.

## Community

* [GitHub Issues](https://github.com/eclipse-kanto/file-upload/issues)
* [Mailing List](https://accounts.eclipse.org/mailing-list/kanto-dev)
55 changes: 55 additions & 0 deletions client/duration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2021 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0

package client

import (
"encoding/json"
"errors"
"time"
)

//Duration is custom type of type time.Duration in order to add json unmarshall support
type Duration time.Duration

//UnmarshalJSON unmarshal duration type
func (d *Duration) UnmarshalJSON(b []byte) error {
var v interface{}
if err := json.Unmarshal(b, &v); err != nil {
return err
}
switch value := v.(type) {

case string:
duration, err := time.ParseDuration(value)
if err != nil {
return err
}
*d = Duration(duration)
default:
return errors.New("invalid duration")
}
return nil
}

//Set duration set from string, used for flag set
func (d *Duration) Set(s string) error {
v, err := time.ParseDuration(s)
if err != nil {
err = errors.New("parse error")
}
*d = Duration(v)
return err
}

func (d Duration) String() string {
return time.Duration(d).String()
}
Loading

0 comments on commit a264566

Please sign in to comment.