Update build step.

This commit is contained in:
Naoki Kosaka
2019-06-02 21:08:40 +09:00
parent 99c2525419
commit 6ca6c9aad0
7 changed files with 78 additions and 62 deletions

View File

@ -11,6 +11,7 @@ import (
"time"
httpdate "github.com/Songmu/go-httpdate"
"github.com/spf13/viper"
"github.com/yukimochi/httpsig"
)
@ -35,7 +36,7 @@ func appendSignature(request *http.Request, body *[]byte, KeyID string, publicKe
func sendActivity(inboxURL string, KeyID string, body []byte, publicKey *rsa.PrivateKey) error {
req, _ := http.NewRequest("POST", inboxURL, bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/activity+json")
req.Header.Set("User-Agent", uaString)
req.Header.Set("User-Agent", fmt.Sprintf("%s (golang net/http; Activity-Relay %s; %s)", viper.GetString("relay_servicename"), version, hostURL.Host))
req.Header.Set("Date", httpdate.Time2Str(time.Now()))
appendSignature(req, &body, KeyID, publicKey)
client := &http.Client{Timeout: time.Duration(5) * time.Second}

View File

@ -17,14 +17,17 @@ import (
keyloader "github.com/yukimochi/Activity-Relay/KeyLoader"
)
// Actor : Relay's Actor
var Actor activitypub.Actor
var (
version string
var hostURL *url.URL
var hostPrivatekey *rsa.PrivateKey
var machineryServer *machinery.Server
var redisClient *redis.Client
var uaString string
// Actor : Relay's Actor
Actor activitypub.Actor
hostURL *url.URL
hostPrivatekey *rsa.PrivateKey
redisClient *redis.Client
machineryServer *machinery.Server
)
func relayActivity(args ...string) error {
inboxURL := args[0]
@ -54,14 +57,14 @@ func initConfig() {
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")
viper.BindEnv("relay_bind")
viper.BindEnv("relay_domain")
viper.BindEnv("relay_servicename")
} else {
Actor.Summary = viper.GetString("relay_summary")
Actor.Icon = activitypub.Image{viper.GetString("relay_icon")}
Actor.Image = activitypub.Image{viper.GetString("relay_image")}
Actor.Icon = activitypub.Image{URL: viper.GetString("relay_icon")}
Actor.Image = activitypub.Image{URL: viper.GetString("relay_image")}
}
Actor.Name = viper.GetString("relay_servicename")
@ -82,12 +85,13 @@ func initConfig() {
if err != nil {
panic(err)
}
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
newNullLogger := NewNullLogger()
log.DEBUG = newNullLogger
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.3; " + hostURL.Host + ")"
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
fmt.Println("Welcome to YUKIMOCHI Activity-Relay [Worker]\n - Configrations")
fmt.Println("Welcome to YUKIMOCHI Activity-Relay [Worker]", version)
fmt.Println(" - Configrations")
fmt.Println("RELAY DOMAIN : ", hostURL.Host)
fmt.Println("REDIS URL : ", viper.GetString("redis_url"))
}