Compare commits
	
		
			No commits in common. "main" and "v0.1.1" have entirely different histories.
		
	
	
		|  | @ -1,7 +1,7 @@ | ||||||
| ## | ## | ||||||
| # Compile application | # Compile application | ||||||
| ## | ## | ||||||
| FROM docker.io/library/golang:alpine AS build-env | FROM golang:alpine AS build-env | ||||||
| WORKDIR /app | WORKDIR /app | ||||||
| COPY . . | COPY . . | ||||||
| # ge dependencies | # ge dependencies | ||||||
|  | @ -14,7 +14,7 @@ This Exporter use the REST-API of OvenMediaEngine, to setting it up, that a look | ||||||
| 
 | 
 | ||||||
| Install https://golang.org/doc/install[golang]. | Install https://golang.org/doc/install[golang]. | ||||||
| 
 | 
 | ||||||
| Run: `go install -v codeberg.org/Mediathek/oven-exporter@latest` | Run: `go install -v dev.sum7.eu/genofire/oven-exporter@latest` | ||||||
| 
 | 
 | ||||||
| ==== Configuration | ==== Configuration | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| name: oven-exporter | name: oven-exporter | ||||||
| title: Oven Exporter | title: Oven Exporer | ||||||
| # use from git tag | # use from git tag | ||||||
| version: | version: | ||||||
|   v(?<version>+({0..9}).+({0..9}).+({0..9})): $<version> |   v(?<version>+({0..9}).+({0..9})).*: $<version> | ||||||
|   main: latest |   main: latest | ||||||
| 
 | 
 | ||||||
| nav: | nav: | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										21
									
								
								go.mod
								
								
								
								
							|  | @ -1,16 +1,19 @@ | ||||||
| module codeberg.org/Mediathek/oven-exporter | module dev.sum7.eu/genofire/oven-exporter | ||||||
| 
 | 
 | ||||||
| go 1.16 | go 1.16 | ||||||
| 
 | 
 | ||||||
| require ( | require ( | ||||||
| 	github.com/fsnotify/fsnotify v1.7.0 // indirect | 	github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||||||
|  | 	github.com/fsnotify/fsnotify v1.6.0 // indirect | ||||||
|  | 	github.com/go-kit/kit v0.10.0 // indirect | ||||||
| 	github.com/knadh/koanf v1.5.0 | 	github.com/knadh/koanf v1.5.0 | ||||||
| 	github.com/pelletier/go-toml v1.9.5 // indirect | 	github.com/pelletier/go-toml v1.9.5 // indirect | ||||||
| 	github.com/prometheus/client_golang v1.17.0 | 	github.com/prometheus/client_golang v1.14.0 | ||||||
| 	github.com/prometheus/client_model v0.5.0 // indirect | 	github.com/prometheus/common v0.40.0 // indirect | ||||||
| 	github.com/prometheus/common v0.45.0 // indirect | 	github.com/prometheus/procfs v0.9.0 // indirect | ||||||
| 	github.com/prometheus/procfs v0.12.0 // indirect | 	go.uber.org/atomic v1.10.0 // indirect | ||||||
| 	github.com/stretchr/testify v1.8.4 | 	go.uber.org/multierr v1.9.0 // indirect | ||||||
| 	go.uber.org/multierr v1.11.0 // indirect | 	go.uber.org/zap v1.24.0 | ||||||
| 	go.uber.org/zap v1.26.0 | 	golang.org/x/tools v0.6.0 // indirect | ||||||
|  | 	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | @ -1,63 +0,0 @@ | ||||||
| package helper |  | ||||||
| 
 |  | ||||||
| import ( |  | ||||||
| 	"crypto/hmac" |  | ||||||
| 	"crypto/sha1" |  | ||||||
| 	"encoding/base64" |  | ||||||
| 	"encoding/json" |  | ||||||
| 	"net/url" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| type Policy struct { |  | ||||||
| 	URLExpire    int64  `json:"url_expire"` |  | ||||||
| 	URLActivate  int64  `json:"url_activate,omitempty"` |  | ||||||
| 	StreamExpire int64  `json:"stream_expire,omitempty"` |  | ||||||
| 	AllowIP      string `json:"allow_ip,omitempty"` |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (p Policy) Encode() (string, error) { |  | ||||||
| 	str, err := json.Marshal(p) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return "", err |  | ||||||
| 	} |  | ||||||
| 	return base64.RawStdEncoding.EncodeToString(str), nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func SignEncodedPolicy(u *url.URL, secretKey string) string { |  | ||||||
| 	hasher := hmac.New(sha1.New, []byte(secretKey)) |  | ||||||
| 	hasher.Write([]byte(u.String())) |  | ||||||
| 	return base64.RawURLEncoding.EncodeToString(hasher.Sum(nil)) |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (p Policy) SignWithQuery(u *url.URL, secretKey, encodeQuery string) (string, error) { |  | ||||||
| 	encode, err := p.Encode() |  | ||||||
| 	if err != nil { |  | ||||||
| 		return "", nil |  | ||||||
| 	} |  | ||||||
| 	query := u.Query() |  | ||||||
| 	query.Add(encodeQuery, encode) |  | ||||||
| 	u.RawQuery = query.Encode() |  | ||||||
| 	return SignEncodedPolicy(u, secretKey), nil |  | ||||||
| } |  | ||||||
| func (p Policy) Sign(u *url.URL, secretKey string) (string, error) { |  | ||||||
| 	return p.SignWithQuery(u, secretKey, "policy") |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (p Policy) SignURLWithQuery(u *url.URL, secretKey, encodeQuery, signatureQuery string) error { |  | ||||||
| 	encode, err := p.Encode() |  | ||||||
| 	if err != nil { |  | ||||||
| 		return err |  | ||||||
| 	} |  | ||||||
| 	query := u.Query() |  | ||||||
| 	query.Add(encodeQuery, encode) |  | ||||||
| 	u.RawQuery = query.Encode() |  | ||||||
| 
 |  | ||||||
| 	signature := SignEncodedPolicy(u, secretKey) |  | ||||||
| 	query.Add(signatureQuery, signature) |  | ||||||
| 	u.RawQuery = query.Encode() |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| func (p Policy) SignURL(u *url.URL, secretKey string) error { |  | ||||||
| 	return p.SignURLWithQuery(u, secretKey, "policy", "signature") |  | ||||||
| } |  | ||||||
|  | @ -1,57 +0,0 @@ | ||||||
| // https://airensoft.gitbook.io/ovenmediaengine/access-control/signedpolicy
 |  | ||||||
| package helper |  | ||||||
| 
 |  | ||||||
| import ( |  | ||||||
| 	"net/url" |  | ||||||
| 	"testing" |  | ||||||
| 
 |  | ||||||
| 	"github.com/stretchr/testify/assert" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| const ( |  | ||||||
| 	examplePolicyEncode              = "eyJ1cmxfZXhwaXJlIjoxMzk5NzIxNTgxfQ" |  | ||||||
| 	exampleSecretKey                 = "1kU^b6" |  | ||||||
| 	exampleURL                       = "ws://192.168.0.100:3333/app/stream" |  | ||||||
| 	exampleSignature                 = "dvVdBpoxAeCPl94Kt5RoiqLI0YE" |  | ||||||
| 	exampleURLWithSignatureAndPolicy = "ws://192.168.0.100/app/stream?policy=eyJ1cmxfZXhwaXJlIjoxMzk5NzIxNTgxfQ&signature=dvVdBpoxAeCPl94Kt5RoiqLI0YE" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| var ( |  | ||||||
| 	examplePolicy = Policy{ |  | ||||||
| 		URLExpire: 1399721581, |  | ||||||
| 	} |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| func TestPolicyEncode(t *testing.T) { |  | ||||||
| 	assert := assert.New(t) |  | ||||||
| 
 |  | ||||||
| 	encode, err := examplePolicy.Encode() |  | ||||||
| 	assert.NoError(err) |  | ||||||
| 	assert.Equal(examplePolicyEncode, encode) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestPolicySign(t *testing.T) { |  | ||||||
| 	assert := assert.New(t) |  | ||||||
| 
 |  | ||||||
| 	u, err := url.Parse(exampleURL) |  | ||||||
| 	assert.NoError(err) |  | ||||||
| 
 |  | ||||||
| 	sign, err := examplePolicy.Sign(u, exampleSecretKey) |  | ||||||
| 	assert.NoError(err) |  | ||||||
| 	assert.Equal(exampleSignature, sign) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestPolicySignURL(t *testing.T) { |  | ||||||
| 	assert := assert.New(t) |  | ||||||
| 
 |  | ||||||
| 	u, err := url.Parse(exampleURL) |  | ||||||
| 	assert.NoError(err) |  | ||||||
| 
 |  | ||||||
| 	err = examplePolicy.SignURL(u, exampleSecretKey) |  | ||||||
| 	assert.NoError(err) |  | ||||||
| 
 |  | ||||||
| 	// drop port -> is not part of example
 |  | ||||||
| 	u.Host = u.Hostname() |  | ||||||
| 
 |  | ||||||
| 	assert.Equal(exampleURLWithSignatureAndPolicy, u.String()) |  | ||||||
| } |  | ||||||
							
								
								
									
										2
									
								
								main.go
								
								
								
								
							
							
						
						
									
										2
									
								
								main.go
								
								
								
								
							|  | @ -16,7 +16,7 @@ import ( | ||||||
| 	"github.com/prometheus/client_golang/prometheus/promhttp" | 	"github.com/prometheus/client_golang/prometheus/promhttp" | ||||||
| 	"go.uber.org/zap" | 	"go.uber.org/zap" | ||||||
| 
 | 
 | ||||||
| 	"codeberg.org/Mediathek/oven-exporter/api" | 	"dev.sum7.eu/genofire/oven-exporter/api" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var configExtParser = map[string]koanf.Parser{ | var configExtParser = map[string]koanf.Parser{ | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"codeberg.org/Mediathek/oven-exporter/api" | 	"dev.sum7.eu/genofire/oven-exporter/api" | ||||||
| 	"github.com/prometheus/client_golang/prometheus" | 	"github.com/prometheus/client_golang/prometheus" | ||||||
| 	"go.uber.org/zap" | 	"go.uber.org/zap" | ||||||
| ) | ) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue