Skip to content

Commit

Permalink
Merge pull request #34 from ARGOeu/devel
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
themiszamani authored Oct 8, 2021
2 parents ca4fc15 + 907d630 commit 8272a41
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 100 deletions.
3 changes: 0 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ pipeline {
}
success {
script{
if ( env.BRANCH_NAME == 'devel' ) {
build job: '/ARGO-utils/argo-swagger-docs', propagate: false
}
if ( env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel' ) {
slackSend( message: ":rocket: New version for <$BUILD_URL|$PROJECT_DIR>:$BRANCH_NAME Job: $JOB_NAME !")
}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Before you start, you need to issue a valid certificate.
"trust_unknown_cas": false,
"log_level": "INFO",
"skip_subs_load": false,
"acl": ["OU=my.local,O=mkcert development certificate"]
"acl": ["OU=my.local,O=mkcert development certificate"],
"syslog_enabled": false
}
```
- `service_port:` The port that the service will bind to.
Expand Down Expand Up @@ -101,6 +102,8 @@ Before you start, you need to issue a valid certificate.
`ams_token`). You can control this behavior and decide whether or not to pre-load any already active subscriptions.

- `acl`: List of certificate DNs which are allowed to access the service.

- `syslog_enabled`: Direct logging of the service to the syslog socket

You can find the configuration template at `conf/ams-push-server-config.template`.
## Managing the protocol buffers and gRPC definitions
Expand Down
4 changes: 3 additions & 1 deletion ams-push-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Name: ams-push-server
Summary: ARGO Ams Push Server.
Version: 1.0.0
Version: 1.0.1
Release: 1%{?dist}
License: ASL 2.0
Buildroot: %{_tmppath}/%{name}-buildroot
Expand Down Expand Up @@ -57,5 +57,7 @@ go clean
%attr(0644,root,root) /usr/lib/systemd/system/ams-push-server.service

%changelog
* Tue Oct 5 2021 Agelos Tsalapatis <agelos.tsal@gmail.com> 1.0.1-1%{?dist}
- Release of ams-push-server 1.0.1
* Wed May 27 2020 Agelos Tsalapatis <agelos.tsal@gmail.com> 1.0.0-1%{?dist}
- Release of ams-push-server 1.0.0
79 changes: 45 additions & 34 deletions api/v1/grpc/proto/ams.pb.go

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

2 changes: 2 additions & 0 deletions api/v1/grpc/proto/ams.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ message PushConfig {
int64 max_messages = 3;
// Required. Retry policy.
RetryPolicy retry_policy = 2;
// Required. Authorization header that the sent messages should include into the request
string authorization_header = 4;
}

// RetryPolicy holds information regarding the retry policy.
Expand Down
22 changes: 15 additions & 7 deletions api/v1/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func NewPushService(cfg *config.Config) *PushService {
// build the client
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !ps.Cfg.VerifySSL},
InsecureSkipVerify: !ps.Cfg.VerifySSL,
},
}

client := &http.Client{
Expand Down Expand Up @@ -144,7 +145,7 @@ func (ps *PushService) ActivateSubscription(ctx context.Context, r *amsPb.Activa
c, _ := consumers.New(consumers.AmsHttpConsumerType, r.Subscription.FullName, ps.Cfg, ps.Client)

// choose a sender
s, _ := senders.New(senders.HttpSenderType, r.Subscription.PushConfig.PushEndpoint, ps.Client)
s, _ := senders.New(senders.HttpSenderType, *r.Subscription.PushConfig, ps.Client)

worker, err := push.New(r.Subscription, c, s, ps.deactivateChan)
if err != nil {
Expand Down Expand Up @@ -298,8 +299,9 @@ func (ps *PushService) loadSubscriptions() {
FullName: sub.FullName,
FullTopic: sub.FullTopic,
PushConfig: &amsPb.PushConfig{
PushEndpoint: sub.PushCfg.Pend,
MaxMessages: sub.PushCfg.MaxMessages,
PushEndpoint: sub.PushCfg.Pend,
AuthorizationHeader: sub.PushCfg.AuthorizationHeader.Value,
MaxMessages: sub.PushCfg.MaxMessages,
RetryPolicy: &amsPb.RetryPolicy{
Period: sub.PushCfg.RetPol.Period,
Type: sub.PushCfg.RetPol.PolicyType,
Expand Down Expand Up @@ -436,9 +438,15 @@ type Subscription struct {

// PushConfig holds optional configuration for push operations
type PushConfig struct {
Pend string `json:"pushEndpoint"`
MaxMessages int64 `json:"maxMessages"`
RetPol RetryPolicy `json:"retryPolicy"`
Pend string `json:"pushEndpoint"`
AuthorizationHeader AuthorizationHeader `json:"authorization_header"`
MaxMessages int64 `json:"maxMessages"`
RetPol RetryPolicy `json:"retryPolicy"`
}

// AuthorizationHeader holds an optional value to be supplied as an Authorization header to push requests
type AuthorizationHeader struct {
Value string `json:"value"`
}

// RetryPolicy holds information on retry policies
Expand Down
17 changes: 13 additions & 4 deletions api/v1/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,14 @@ func (suite *ServerTestSuite) TestGetSubscription() {
Period: 300,
}

authz := AuthorizationHeader{
Value: "auth-header-1",
}

pc := PushConfig{
Pend: "example.com:9999",
RetPol: rp,
Pend: "example.com:9999",
AuthorizationHeader: authz,
RetPol: rp,
}

expectedSub := Subscription{
Expand Down Expand Up @@ -397,10 +402,14 @@ func (m *MockRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
PolicyType: "linear",
Period: 300,
}
authz := AuthorizationHeader{
Value: "auth-header-1",
}

pc := PushConfig{
Pend: "example.com:9999",
RetPol: rp,
Pend: "example.com:9999",
AuthorizationHeader: authz,
RetPol: rp,
}

s := Subscription{
Expand Down
3 changes: 2 additions & 1 deletion conf/ams-push-server-config.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"trust_unknown_cas": false,
"log_level": "INFO",
"skip_subs_load": false,
"acl": ["OU=my.local,O=mkcert development certificate"]
"acl": ["OU=my.local,O=mkcert development certificate"],
"syslog_enabled": false
}
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"encoding/json"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
"io"
"io/ioutil"
"log/syslog"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -44,6 +46,8 @@ type Config struct {
tlsConfig *tls.Config
// list of certificate DNs that should be allowed to access the service
ACL []string `json:"acl"`
// Enable direct logging of the service to the syslog facility
SyslogEnabled bool `json:"syslog_enabled"`
}

var logLevels = map[string]log.Level{
Expand Down Expand Up @@ -109,6 +113,13 @@ func (cfg *Config) LoadFromJson(from io.Reader) error {
continue
}

if cfg.SyslogEnabled {
hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
if err == nil {
log.AddHook(hook)
}
}

log.WithFields(
log.Fields{
"type": "service_log",
Expand Down
5 changes: 4 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (suite *ConfigTestSuite) TestValidateRequired() {
LogLevel: "INFO",
SkipSubsLoad: true,
ACL: []string{"OU=my.local,O=mkcert development certificate"},
SyslogEnabled: true,
}

// test the case where where everything is set properly
Expand All @@ -59,7 +60,8 @@ func (suite *ConfigTestSuite) TestLoadFromJson() {
"trust_unknown_cas": true,
"log_level": "INFO",
"skip_subs_load": true,
"acl": ["OU=my.local,O=mkcert development certificate"]
"acl": ["OU=my.local,O=mkcert development certificate"],
"syslog_enabled": true
}
`
cfg := new(Config)
Expand All @@ -79,6 +81,7 @@ func (suite *ConfigTestSuite) TestLoadFromJson() {
suite.Equal("INFO", cfg.LogLevel)
suite.Equal(true, cfg.SkipSubsLoad)
suite.Equal([]string{"OU=my.local,O=mkcert development certificate"}, cfg.ACL)
suite.Equal(true, cfg.SyslogEnabled)

suite.Nil(e1)

Expand Down
9 changes: 0 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@ import (
amsgRPC "github.com/ARGOeu/ams-push-server/api/v1/grpc"
"github.com/ARGOeu/ams-push-server/config"
log "github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
"io/ioutil"
"log/syslog"
"net"
)

func init() {

fmter := &log.TextFormatter{FullTimestamp: true, DisableColors: true}
hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_DEBUG, "")

log.SetFormatter(fmter)

if err == nil {
log.AddHook(hook)
}
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion push/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type WorkerTestSuite struct {
func (suite *WorkerTestSuite) TestNew() {

c := consumers.NewAmsHttpConsumer("", "", "", &http.Client{})
s := senders.NewHttpSender("", &http.Client{})
s := senders.NewHttpSender("", "", &http.Client{})
sub := &amsPb.Subscription{
PushConfig: &amsPb.PushConfig{
MaxMessages: 1,
Expand Down
11 changes: 8 additions & 3 deletions senders/httpsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const ApplicationJson = "application/json"

// HttpSender delivers data to any http endpoint
type HttpSender struct {
client *http.Client
endpoint string
client *http.Client
endpoint string
authZHeader string
}

// NewHttpSender initialises and returns a new http sender
func NewHttpSender(endpoint string, client *http.Client) *HttpSender {
func NewHttpSender(endpoint, authz string, client *http.Client) *HttpSender {
s := new(HttpSender)
s.client = client
s.endpoint = endpoint
s.authZHeader = authz
return s
}

Expand Down Expand Up @@ -50,6 +52,9 @@ func (s *HttpSender) Send(ctx context.Context, msgs PushMsgs, format pushMessage
}

req.Header.Set("Content-Type", ApplicationJson)
if s.authZHeader != "" {
req.Header.Set("Authorization", s.authZHeader)
}

log.WithFields(
log.Fields{
Expand Down
Loading

0 comments on commit 8272a41

Please sign in to comment.