file config, avator, header image. (#18)
This commit is contained in:
parent
d3d03544fa
commit
97f4655e9c
@ -12,6 +12,7 @@ jobs:
|
||||
name: build
|
||||
command: |
|
||||
go version
|
||||
rm config.yaml
|
||||
go test -coverprofile=coverage.txt -covermode=atomic -p 1 . ./worker ./cli ./State
|
||||
bash <(curl -s https://codecov.io/bash)
|
||||
docker:
|
||||
|
@ -26,6 +26,11 @@ type Endpoints struct {
|
||||
SharedInbox string `json:"sharedInbox"`
|
||||
}
|
||||
|
||||
// Image : Image Object.
|
||||
type Image struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// Actor : ActivityPub Actor.
|
||||
type Actor struct {
|
||||
Context interface{} `json:"@context"`
|
||||
@ -33,18 +38,20 @@ type Actor struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
PreferredUsername string `json:"preferredUsername"`
|
||||
Summary string `json:"summary"`
|
||||
Inbox string `json:"inbox"`
|
||||
Endpoints *Endpoints `json:"endpoints"`
|
||||
PublicKey PublicKey `json:"publicKey"`
|
||||
Icon Image `json:"icon"`
|
||||
Image Image `json:"image"`
|
||||
}
|
||||
|
||||
// GenerateSelfKey : Generate relay Actor from Publickey.
|
||||
func (actor *Actor) GenerateSelfKey(hostname *url.URL, username string, publickey *rsa.PublicKey) {
|
||||
func (actor *Actor) GenerateSelfKey(hostname *url.URL, publickey *rsa.PublicKey) {
|
||||
actor.Context = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}
|
||||
actor.ID = hostname.String() + "/actor"
|
||||
actor.Type = "Service"
|
||||
actor.PreferredUsername = "relay"
|
||||
actor.Name = username
|
||||
actor.Inbox = hostname.String() + "/inbox"
|
||||
actor.PublicKey = PublicKey{
|
||||
hostname.String() + "/actor#main-key",
|
||||
|
@ -1,6 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -11,7 +12,13 @@ import (
|
||||
var redisClient *redis.Client
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
viper.BindEnv("redis_url")
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(".")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("Config file is not exists. Use environment variables.")
|
||||
viper.BindEnv("redis_url")
|
||||
}
|
||||
redisOption, err := redis.ParseURL(viper.GetString("redis_url"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
24
cli/cli.go
24
cli/cli.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/RichardKnop/machinery/v1"
|
||||
@ -23,10 +24,23 @@ var macServer *machinery.Server
|
||||
var relayState state.RelayState
|
||||
|
||||
func initConfig() {
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(".")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("Config file is not exists. Use environment variables.")
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_bind")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
} else {
|
||||
Actor.Summary = viper.GetString("relay_summary")
|
||||
Actor.Icon = activitypub.Image{viper.GetString("relay_icon")}
|
||||
Actor.Image = activitypub.Image{viper.GetString("relay_image")}
|
||||
}
|
||||
Actor.Name = viper.GetString("relay_servicename")
|
||||
|
||||
hostkey, err := keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -51,7 +65,7 @@ func initConfig() {
|
||||
panic(err)
|
||||
}
|
||||
relayState = state.NewState(redClient)
|
||||
Actor.GenerateSelfKey(hostname, viper.GetString("relay_servicename"), &hostkey.PublicKey)
|
||||
Actor.GenerateSelfKey(hostname, &hostkey.PublicKey)
|
||||
}
|
||||
|
||||
func buildNewCmd() *cobra.Command {
|
||||
|
10
config.yaml
Normal file
10
config.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
actor_pem: /actor.pem
|
||||
redis_url: redis://redis:6379
|
||||
|
||||
relay_bind: 0.0.0.0:8080
|
||||
relay_domain: relay.toot.yukimochi.jp
|
||||
relay_servicename: YUKIMOCHI Toot Relay Service
|
||||
# relay_summary: |
|
||||
|
||||
# relay_icon: https://
|
||||
# relay_image: https://
|
@ -17,6 +17,7 @@ services:
|
||||
- "REDIS_URL=redis://redis:6379"
|
||||
volumes:
|
||||
- "./actor.pem:/actor.pem"
|
||||
# - "./config.yaml:/Activity-Relay/config.yaml"
|
||||
|
||||
server:
|
||||
build: .
|
||||
@ -32,3 +33,4 @@ services:
|
||||
- "REDIS_URL=redis://redis:6379"
|
||||
volumes:
|
||||
- "./actor.pem:/actor.pem"
|
||||
# - "./config.yaml:/Activity-Relay/config.yaml"
|
||||
|
24
main.go
24
main.go
@ -31,11 +31,23 @@ var relayState state.RelayState
|
||||
var uaString string
|
||||
|
||||
func initConfig() {
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_bind")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(".")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("Config file is not exists. Use environment variables.")
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_bind")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
} else {
|
||||
Actor.Summary = viper.GetString("relay_summary")
|
||||
Actor.Icon = activitypub.Image{viper.GetString("relay_icon")}
|
||||
Actor.Image = activitypub.Image{viper.GetString("relay_image")}
|
||||
}
|
||||
Actor.Name = viper.GetString("relay_servicename")
|
||||
|
||||
hostURL, _ = url.Parse("https://" + viper.GetString("relay_domain"))
|
||||
hostPrivatekey, _ = keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
|
||||
redisOption, err := redis.ParseURL(viper.GetString("redis_url"))
|
||||
@ -56,7 +68,7 @@ func initConfig() {
|
||||
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.2; " + hostURL.Host + ")"
|
||||
relayState = state.NewState(redisClient)
|
||||
actorCache = cache.New(5*time.Minute, 10*time.Minute)
|
||||
Actor.GenerateSelfKey(hostURL, viper.GetString("relay_servicename"), &hostPrivatekey.PublicKey)
|
||||
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
|
||||
WebfingerResource.GenerateFromActor(hostURL, &Actor)
|
||||
|
||||
fmt.Println("Welcome to YUKIMOCHI Activity-Relay [Server]\n - Configrations")
|
||||
|
@ -48,10 +48,23 @@ func registorActivity(args ...string) error {
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(".")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("Config file is not exists. Use environment variables.")
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_bind")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
} else {
|
||||
Actor.Summary = viper.GetString("relay_summary")
|
||||
Actor.Icon = activitypub.Image{viper.GetString("relay_icon")}
|
||||
Actor.Image = activitypub.Image{viper.GetString("relay_image")}
|
||||
}
|
||||
Actor.Name = viper.GetString("relay_servicename")
|
||||
|
||||
hostURL, _ = url.Parse("https://" + viper.GetString("relay_domain"))
|
||||
hostPrivatekey, _ = keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
|
||||
redisOption, err := redis.ParseURL(viper.GetString("redis_url"))
|
||||
@ -72,7 +85,7 @@ func initConfig() {
|
||||
newNullLogger := NewNullLogger()
|
||||
log.DEBUG = newNullLogger
|
||||
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.2; " + hostURL.Host + ")"
|
||||
Actor.GenerateSelfKey(hostURL, viper.GetString("relay_servicename"), &hostPrivatekey.PublicKey)
|
||||
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
|
||||
|
||||
fmt.Println("Welcome to YUKIMOCHI Activity-Relay [Worker]\n - Configrations")
|
||||
fmt.Println("RELAY DOMAIN : ", hostURL.Host)
|
||||
|
Loading…
x
Reference in New Issue
Block a user