betterlog 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88d9cdea20addad7d2cb055ccf12042e72b17bb83fbd541054169b3de83294f4
4
- data.tar.gz: def90b48552d18eafdadea5eb099b12562341d77e3a9f5b83040bc38deb3d9f2
3
+ metadata.gz: 57cf408499489e3a2a0f7bf2fc51667688ee816e7797984fe4c27ab3393d486a
4
+ data.tar.gz: a330c835cf6452a13e3b36727f5d296480a22c8b22e12e887df542ff594db450
5
5
  SHA512:
6
- metadata.gz: 9906c03fe9cc1eddebcdb27b081e504dd812d7e2cf2eeb9fc80661e52364b799a7146a4aab6d8e9118b202882f201f950e90c0f7d89817b491b577340a1796c8
7
- data.tar.gz: e57eb4408a119c556f89de5cdac7823fb4cc220be1b0a31faa79988989703cfd2d63e8d6e8a9e46bfc82761052e8789139dcb51611129af825338cdc8a700fe7
6
+ metadata.gz: eb3d0ce4c94f68b40c704dbe9cb6de03d25cd422b358039536197ebbc0d5f34b53c6c6f39679fae71a3390d5b619acbe2348d826fdf9534407809c5818db09bf
7
+ data.tar.gz: 0236ab4073d2293e01f1cdc6dbf0157c5d0cb481c2ba1db5069000592ea7d21cdca58f998b04dd505d34ad5718dbbb1020a56b9a77eaceac6ebfdc0a9ecd9fe2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -0,0 +1,11 @@
1
+ package betterlog
2
+
3
+ type Config struct {
4
+ PORT int `default:"5514"`
5
+ HEALTHZ_PORT int `default:"5513"`
6
+ HTTP_REALM string `default:"betterlog"`
7
+ HTTP_AUTH string
8
+ SSL bool
9
+ REDIS_PREFIX string
10
+ REDIS_URL string `default:"redis://localhost:6379"`
11
+ }
data/betterlog/healthz.go CHANGED
@@ -1,4 +1,4 @@
1
- package bime
1
+ package betterlog
2
2
 
3
3
  import (
4
4
  "fmt"
@@ -0,0 +1,83 @@
1
+ package betterlog
2
+
3
+ import (
4
+ "context"
5
+ "strings"
6
+
7
+ "github.com/go-redis/redis"
8
+ "golang.org/x/crypto/acme/autocert"
9
+ )
10
+
11
+ type RedisCertCache struct {
12
+ Redis *redis.Client
13
+ PREFIX string
14
+ }
15
+
16
+ // Get reads certificate data from the specified key name.
17
+ func (cache RedisCertCache) Get(ctx context.Context, name string) ([]byte, error) {
18
+ name = strings.Join([]string{cache.PREFIX, name}, "/")
19
+ done := make(chan struct{})
20
+ var (
21
+ err error
22
+ data string
23
+ )
24
+ go func() {
25
+ defer close(done)
26
+ result := cache.Redis.Get(name)
27
+ err = result.Err()
28
+ if err == nil {
29
+ data, err = result.Result()
30
+ }
31
+ }()
32
+ select {
33
+ case <-ctx.Done():
34
+ return nil, ctx.Err()
35
+ case <-done:
36
+ }
37
+ if err == redis.Nil {
38
+ return nil, autocert.ErrCacheMiss
39
+ }
40
+ return []byte(data), err
41
+ }
42
+
43
+ // Put writes the certificate data to the specified redis key name.
44
+ func (cache RedisCertCache) Put(ctx context.Context, name string, data []byte) error {
45
+ name = strings.Join([]string{cache.PREFIX, name}, "/")
46
+ done := make(chan struct{})
47
+ var err error
48
+ go func() {
49
+ defer close(done)
50
+ select {
51
+ case <-ctx.Done():
52
+ // Don't overwrite the key if the context was canceled.
53
+ default:
54
+ result := cache.Redis.Set(name, string(data), 0)
55
+ err = result.Err()
56
+ }
57
+ }()
58
+ select {
59
+ case <-ctx.Done():
60
+ return ctx.Err()
61
+ case <-done:
62
+ }
63
+ return err
64
+ }
65
+
66
+ // Delete removes the specified key name.
67
+ func (cache RedisCertCache) Delete(ctx context.Context, name string) error {
68
+ name = strings.Join([]string{cache.PREFIX, name}, "/")
69
+ var (
70
+ err error
71
+ done = make(chan struct{})
72
+ )
73
+ go func() {
74
+ defer close(done)
75
+ err = cache.Redis.Del(name).Err()
76
+ }()
77
+ select {
78
+ case <-ctx.Done():
79
+ return ctx.Err()
80
+ case <-done:
81
+ }
82
+ return err
83
+ }
data/betterlog.gemspec CHANGED
@@ -1,19 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.2.1 ruby lib
2
+ # stub: betterlog 0.2.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.2.1"
6
+ s.version = "0.2.2"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["betterplace Developers".freeze]
11
- s.date = "2019-06-27"
11
+ s.date = "2019-07-04"
12
12
  s.description = "This library provides structure json logging for our rails projects".freeze
13
13
  s.email = "developers@betterplace.org".freeze
14
14
  s.executables = ["betterlog".freeze, "betterlog_pusher".freeze]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze]
16
- s.files = [".gitignore".freeze, ".travis.yml".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/healthz.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
+ s.files = [".gitignore".freeze, ".travis.yml".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/config.go".freeze, "betterlog/healthz.go".freeze, "betterlog/redis_cert_cache.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "http://github.com/betterplace/betterlog".freeze
18
18
  s.rdoc_options = ["--title".freeze, "Betterlog".freeze, "--main".freeze, "README.md".freeze]
19
19
  s.rubygems_version = "3.0.3".freeze
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.specification_version = 4
25
25
 
26
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.10.0"])
28
28
  s.add_development_dependency(%q<rake>.freeze, [">= 0"])
29
29
  s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
30
30
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency(%q<redis>.freeze, [">= 2.4"])
37
37
  s.add_runtime_dependency(%q<excon>.freeze, [">= 0"])
38
38
  else
39
- s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
39
+ s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.10.0"])
40
40
  s.add_dependency(%q<rake>.freeze, [">= 0"])
41
41
  s.add_dependency(%q<rspec>.freeze, [">= 0"])
42
42
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  s.add_dependency(%q<excon>.freeze, [">= 0"])
50
50
  end
51
51
  else
52
- s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
52
+ s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.10.0"])
53
53
  s.add_dependency(%q<rake>.freeze, [">= 0"])
54
54
  s.add_dependency(%q<rspec>.freeze, [">= 0"])
55
55
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
@@ -1,7 +1,6 @@
1
1
  package main
2
2
 
3
3
  import (
4
- "context"
5
4
  "fmt"
6
5
  "io/ioutil"
7
6
  "log"
@@ -14,93 +13,8 @@ import (
14
13
  "github.com/kelseyhightower/envconfig"
15
14
  "github.com/labstack/echo"
16
15
  "github.com/labstack/echo/middleware"
17
- "golang.org/x/crypto/acme/autocert"
18
16
  )
19
17
 
20
- type Config struct {
21
- PORT int `default:"5514"`
22
- HEALTHZ_PORT int `default:"5513"`
23
- HTTP_REALM string `default:"betterlog"`
24
- HTTP_AUTH string
25
- SSL bool
26
- REDIS_PREFIX string
27
- REDIS_URL string `default:"redis://localhost:6379"`
28
- }
29
-
30
- type RedisCertCache struct {
31
- Redis *redis.Client
32
- PREFIX string
33
- }
34
-
35
- // Get reads certificate data from the specified key name.
36
- func (cache RedisCertCache) Get(ctx context.Context, name string) ([]byte, error) {
37
- name = strings.Join([]string{cache.PREFIX, name}, "/")
38
- done := make(chan struct{})
39
- var (
40
- err error
41
- data string
42
- )
43
- go func() {
44
- defer close(done)
45
- result := cache.Redis.Get(name)
46
- err = result.Err()
47
- if err == nil {
48
- data, err = result.Result()
49
- }
50
- }()
51
- select {
52
- case <-ctx.Done():
53
- return nil, ctx.Err()
54
- case <-done:
55
- }
56
- if err == redis.Nil {
57
- return nil, autocert.ErrCacheMiss
58
- }
59
- return []byte(data), err
60
- }
61
-
62
- // Put writes the certificate data to the specified redis key name.
63
- func (cache RedisCertCache) Put(ctx context.Context, name string, data []byte) error {
64
- name = strings.Join([]string{cache.PREFIX, name}, "/")
65
- done := make(chan struct{})
66
- var err error
67
- go func() {
68
- defer close(done)
69
- select {
70
- case <-ctx.Done():
71
- // Don't overwrite the key if the context was canceled.
72
- default:
73
- result := cache.Redis.Set(name, string(data), 0)
74
- err = result.Err()
75
- }
76
- }()
77
- select {
78
- case <-ctx.Done():
79
- return ctx.Err()
80
- case <-done:
81
- }
82
- return err
83
- }
84
-
85
- // Delete removes the specified key name.
86
- func (cache RedisCertCache) Delete(ctx context.Context, name string) error {
87
- name = strings.Join([]string{cache.PREFIX, name}, "/")
88
- var (
89
- err error
90
- done = make(chan struct{})
91
- )
92
- go func() {
93
- defer close(done)
94
- err = cache.Redis.Del(name).Err()
95
- }()
96
- select {
97
- case <-ctx.Done():
98
- return ctx.Err()
99
- case <-done:
100
- }
101
- return err
102
- }
103
-
104
18
  func postLogHandler(c echo.Context) error {
105
19
  body := c.Request().Body
106
20
  data, err := ioutil.ReadAll(body)
@@ -113,7 +27,7 @@ func postLogHandler(c echo.Context) error {
113
27
  }
114
28
  }
115
29
 
116
- func basicAuthConfig(config Config) middleware.BasicAuthConfig {
30
+ func basicAuthConfig(config betterlog.Config) middleware.BasicAuthConfig {
117
31
  return middleware.BasicAuthConfig{
118
32
  Realm: config.HTTP_REALM,
119
33
  Validator: func(username, password string, c echo.Context) (bool, error) {
@@ -126,7 +40,7 @@ func basicAuthConfig(config Config) middleware.BasicAuthConfig {
126
40
  }
127
41
  }
128
42
 
129
- func initializeRedis(config Config) *redis.Client {
43
+ func initializeRedis(config betterlog.Config) *redis.Client {
130
44
  options, err := redis.ParseURL(config.REDIS_URL)
131
45
  if err != nil {
132
46
  log.Panic(err)
@@ -136,12 +50,16 @@ func initializeRedis(config Config) *redis.Client {
136
50
  }
137
51
 
138
52
  func main() {
139
- var config Config
53
+ var config betterlog.Config
140
54
  err := envconfig.Process("", &config)
141
55
  if err != nil {
142
56
  log.Fatal(err)
143
57
  }
144
58
  e := echo.New()
59
+
60
+ if !config.SSL {
61
+ e.Use(betterlog.Health{}.ZPage)
62
+ }
145
63
  if config.HTTP_AUTH != "" {
146
64
  fmt.Println("info: Configuring HTTP Auth access control")
147
65
  e.Use(middleware.BasicAuthWithConfig(basicAuthConfig(config)))
@@ -150,7 +68,7 @@ func main() {
150
68
  if config.SSL {
151
69
  log.Println("Starting SSL AutoTLS service.")
152
70
  redis := initializeRedis(config)
153
- e.AutoTLSManager.Cache = RedisCertCache{
71
+ e.AutoTLSManager.Cache = betterlog.RedisCertCache{
154
72
  Redis: redis,
155
73
  PREFIX: config.REDIS_PREFIX,
156
74
  }
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.1
19
+ version: 1.10.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.9.1
26
+ version: 1.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +201,9 @@ files:
201
201
  - TODO.md
202
202
  - VERSION
203
203
  - betterlog.gemspec
204
+ - betterlog/config.go
204
205
  - betterlog/healthz.go
206
+ - betterlog/redis_cert_cache.go
205
207
  - bin/betterlog
206
208
  - bin/betterlog_pusher
207
209
  - cmd/betterlog-server/LICENSE