Skip to content

Commit

Permalink
Merge branch 'release/1.22.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantony committed Jul 26, 2019
2 parents c1433ef + 8cb18f9 commit 0b2a76d
Show file tree
Hide file tree
Showing 262 changed files with 4,171 additions and 1,307 deletions.
6 changes: 0 additions & 6 deletions .github/ISSUE_TEMPLATE/Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,18 @@ Also, be sure to check our FAQ and documentation first: https://portainer.readth
-->

**Bug description**

A clear and concise description of what the bug is.

**Expected behavior**
A clear and concise description of what you expected to happen.

Briefly describe what you were expecting.

**Steps to reproduce the issue:**

Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Technical details:**

* Portainer version:
* Docker version (managed by Portainer):
* Platform (windows/linux):
Expand Down
54 changes: 54 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Config for Stalebot, limited to only `issues`
only: issues

# Issues config
issues:
daysUntilStale: 60
daysUntilClose: 7

# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30

# Issues with these labels will never be considered stale
exemptLabels:
- kind/enhancement
- kind/feature
- kind/question
- kind/style
- bug/need-confirmation
- bug/confirmed
- status/discuss

# Only issues with all of these labels are checked if stale. Defaults to `[]` (disabled)
onlyLabels: []

# Set to true to ignore issues in a project (defaults to false)
exemptProjects: true
# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: true
# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees: true

# Label to use when marking an issue as stale
staleLabel: status/stale

# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been marked as stale as it has not had recent activity,
it will be closed if no further activity occurs in the next 7 days.
If you believe that it has been incorrectly labelled as stale,
leave a comment and the label will be removed.
# Comment to post when removing the stale label.
# unmarkComment: >
# Your comment here.

# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
Since no further activity has appeared on this issue it will be closed.
If you believe that it has been incorrectly closed, leave a comment
and mention @itsconquest. One of our staff will then review the issue.
Note - If it is an old bug report, make sure that it is reproduceable in the
latest version of Portainer as it may have already been fixed.
9 changes: 9 additions & 0 deletions api/bolt/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path"
"time"

"github.com/portainer/portainer/api/bolt/tunnelserver"

"github.com/boltdb/bolt"
"github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/bolt/dockerhub"
Expand Down Expand Up @@ -51,6 +53,7 @@ type Store struct {
TeamMembershipService *teammembership.Service
TeamService *team.Service
TemplateService *template.Service
TunnelServerService *tunnelserver.Service
UserService *user.Service
VersionService *version.Service
WebhookService *webhook.Service
Expand Down Expand Up @@ -220,6 +223,12 @@ func (store *Store) initServices() error {
}
store.TemplateService = templateService

tunnelServerService, err := tunnelserver.NewService(store.db)
if err != nil {
return err
}
store.TunnelServerService = tunnelServerService

userService, err := user.NewService(store.db)
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions api/bolt/endpoint/endpoint.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package endpoint

import (
"github.com/boltdb/bolt"
"github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/bolt/internal"

"github.com/boltdb/bolt"
)

const (
Expand Down Expand Up @@ -64,7 +63,7 @@ func (service *Service) Endpoints() ([]portainer.Endpoint, error) {
cursor := bucket.Cursor()
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
var endpoint portainer.Endpoint
err := internal.UnmarshalObject(v, &endpoint)
err := internal.UnmarshalObjectWithJsoniter(v, &endpoint)
if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions api/bolt/internal/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package internal

import (
"encoding/json"

jsoniter "github.com/json-iterator/go"
)

// MarshalObject encodes an object to binary format
Expand All @@ -13,3 +15,11 @@ func MarshalObject(object interface{}) ([]byte, error) {
func UnmarshalObject(data []byte, object interface{}) error {
return json.Unmarshal(data, object)
}

// UnmarshalObjectWithJsoniter decodes an object from binary data
// using the jsoniter library. It is mainly used to accelerate endpoint
// decoding at the moment.
func UnmarshalObjectWithJsoniter(data []byte, object interface{}) error {
var jsoni = jsoniter.ConfigCompatibleWithStandardLibrary
return jsoni.Unmarshal(data, &object)
}
16 changes: 16 additions & 0 deletions api/bolt/migrator/migrate_dbversion18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package migrator

import portainer "github.com/portainer/portainer/api"

func (m *Migrator) updateSettingsToDBVersion19() error {
legacySettings, err := m.settingsService.Settings()
if err != nil {
return err
}

if legacySettings.EdgeAgentCheckinInterval == 0 {
legacySettings.EdgeAgentCheckinInterval = portainer.DefaultEdgeAgentCheckinIntervalInSeconds
}

return m.settingsService.UpdateSettings(legacySettings)
}
8 changes: 8 additions & 0 deletions api/bolt/migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,13 @@ func (m *Migrator) Migrate() error {
}
}

// Portainer 1.22.0
if m.currentDBVersion < 19 {
err := m.updateSettingsToDBVersion19()
if err != nil {
return err
}
}

return m.versionService.StoreDBVersion(portainer.DBVersion)
}
48 changes: 48 additions & 0 deletions api/bolt/tunnelserver/tunnelserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tunnelserver

import (
"github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/bolt/internal"

"github.com/boltdb/bolt"
)

const (
// BucketName represents the name of the bucket where this service stores data.
BucketName = "tunnel_server"
infoKey = "INFO"
)

// Service represents a service for managing endpoint data.
type Service struct {
db *bolt.DB
}

// NewService creates a new instance of a service.
func NewService(db *bolt.DB) (*Service, error) {
err := internal.CreateBucket(db, BucketName)
if err != nil {
return nil, err
}

return &Service{
db: db,
}, nil
}

// Info retrieve the TunnelServerInfo object.
func (service *Service) Info() (*portainer.TunnelServerInfo, error) {
var info portainer.TunnelServerInfo

err := internal.GetObject(service.db, BucketName, []byte(infoKey), &info)
if err != nil {
return nil, err
}

return &info, nil
}

// UpdateInfo persists a TunnelServerInfo object.
func (service *Service) UpdateInfo(settings *portainer.TunnelServerInfo) error {
return internal.UpdateObject(service.db, BucketName, []byte(infoKey), settings)
}
24 changes: 24 additions & 0 deletions api/chisel/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package chisel

import (
"encoding/base64"
"fmt"
"strconv"
"strings"
)

// GenerateEdgeKey will generate a key that can be used by an Edge agent to register with a Portainer instance.
// The key represents the following data in this particular format:
// portainer_instance_url|tunnel_server_addr|tunnel_server_fingerprint|endpoint_ID
// The key returned by this function is a base64 encoded version of the data.
func (service *Service) GenerateEdgeKey(url, host string, endpointIdentifier int) string {
keyInformation := []string{
url,
fmt.Sprintf("%s:%s", host, service.serverPort),
service.serverFingerprint,
strconv.Itoa(endpointIdentifier),
}

key := strings.Join(keyInformation, "|")
return base64.RawStdEncoding.EncodeToString([]byte(key))
}
47 changes: 47 additions & 0 deletions api/chisel/schedules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package chisel

import (
"strconv"

portainer "github.com/portainer/portainer/api"
)

// AddSchedule register a schedule inside the tunnel details associated to an endpoint.
func (service *Service) AddSchedule(endpointID portainer.EndpointID, schedule *portainer.EdgeSchedule) {
tunnel := service.GetTunnelDetails(endpointID)

existingScheduleIndex := -1
for idx, existingSchedule := range tunnel.Schedules {
if existingSchedule.ID == schedule.ID {
existingScheduleIndex = idx
break
}
}

if existingScheduleIndex == -1 {
tunnel.Schedules = append(tunnel.Schedules, *schedule)
} else {
tunnel.Schedules[existingScheduleIndex] = *schedule
}

key := strconv.Itoa(int(endpointID))
service.tunnelDetailsMap.Set(key, tunnel)
}

// RemoveSchedule will remove the specified schedule from each tunnel it was registered with.
func (service *Service) RemoveSchedule(scheduleID portainer.ScheduleID) {
for item := range service.tunnelDetailsMap.IterBuffered() {
tunnelDetails := item.Val.(*portainer.TunnelDetails)

updatedSchedules := make([]portainer.EdgeSchedule, 0)
for _, schedule := range tunnelDetails.Schedules {
if schedule.ID == scheduleID {
continue
}
updatedSchedules = append(updatedSchedules, schedule)
}

tunnelDetails.Schedules = updatedSchedules
service.tunnelDetailsMap.Set(item.Key, tunnelDetails)
}
}
Loading

0 comments on commit 0b2a76d

Please sign in to comment.