Update Actor name.
This commit is contained in:
16
cli/cli.go
16
cli/cli.go
@ -9,10 +9,14 @@ import (
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
activitypub "github.com/yukimochi/Activity-Relay/ActivityPub"
|
||||
keyloader "github.com/yukimochi/Activity-Relay/KeyLoader"
|
||||
state "github.com/yukimochi/Activity-Relay/State"
|
||||
)
|
||||
|
||||
// Actor : Relay's Actor
|
||||
var Actor activitypub.Actor
|
||||
|
||||
var hostname *url.URL
|
||||
var hostkey *rsa.PrivateKey
|
||||
var macServer *machinery.Server
|
||||
@ -21,9 +25,16 @@ var relayState state.RelayState
|
||||
func initConfig() {
|
||||
viper.BindEnv("actor_pem")
|
||||
viper.BindEnv("relay_domain")
|
||||
viper.BindEnv("relay_servicename")
|
||||
viper.BindEnv("redis_url")
|
||||
hostkey, _ = keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
|
||||
hostname, _ = url.Parse("https://" + viper.GetString("relay_domain"))
|
||||
hostkey, err := keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hostname, err = url.Parse("https://" + viper.GetString("relay_domain"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
redOption, err := redis.ParseURL(viper.GetString("redis_url"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -40,6 +51,7 @@ func initConfig() {
|
||||
panic(err)
|
||||
}
|
||||
relayState = state.NewState(redClient)
|
||||
Actor.GenerateSelfKey(hostname, viper.GetString("relay_servicename"), &hostkey.PublicKey)
|
||||
}
|
||||
|
||||
func buildNewCmd() *cobra.Command {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
viper.Set("actor_pem", "misc/testKey.pem")
|
||||
viper.Set("actor_pem", "../misc/testKey.pem")
|
||||
viper.Set("relay_domain", "relay.yukimochi.example.org")
|
||||
initConfig()
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/RichardKnop/machinery/v1/tasks"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"github.com/spf13/cobra"
|
||||
activitypub "github.com/yukimochi/Activity-Relay/ActivityPub"
|
||||
state "github.com/yukimochi/Activity-Relay/State"
|
||||
@ -45,6 +46,14 @@ func followCmdInit() *cobra.Command {
|
||||
}
|
||||
follow.AddCommand(followReject)
|
||||
|
||||
var updateActor = &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update actor object",
|
||||
Long: "Update actor object for whole subscribers.",
|
||||
RunE: updateActor,
|
||||
}
|
||||
follow.AddCommand(updateActor)
|
||||
|
||||
return follow
|
||||
}
|
||||
|
||||
@ -85,7 +94,10 @@ func createFollowRequestResponse(domain string, response string) error {
|
||||
}
|
||||
|
||||
resp := activity.GenerateResponse(hostname, response)
|
||||
jsonData, _ := json.Marshal(&resp)
|
||||
jsonData, err := json.Marshal(&resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pushRegistorJob(data["inbox_url"], jsonData)
|
||||
relayState.RedisClient.Del("relay:pending:" + domain)
|
||||
if response == "Accept" {
|
||||
@ -100,6 +112,25 @@ func createFollowRequestResponse(domain string, response string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func createUpdateActorActivity(subscription state.Subscription) error {
|
||||
activity := activitypub.Activity{
|
||||
Context: []string{"https://www.w3.org/ns/activitystreams"},
|
||||
ID: hostname.String() + "/activities/" + uuid.NewV4().String(),
|
||||
Actor: hostname.String() + "/actor",
|
||||
Type: "Update",
|
||||
To: []string{"https://www.w3.org/ns/activitystreams#Public"},
|
||||
Object: Actor,
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(&activity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pushRegistorJob(subscription.InboxURL, jsonData)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func listFollows(cmd *cobra.Command, args []string) error {
|
||||
var domains []string
|
||||
cmd.Println(" - Follow request :")
|
||||
@ -165,3 +196,13 @@ func rejectFollow(cmd *cobra.Command, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateActor(cmd *cobra.Command, args []string) error {
|
||||
for _, subscription := range relayState.Subscriptions {
|
||||
err := createUpdateActorActivity(subscription)
|
||||
if err != nil {
|
||||
cmd.Println("Failed Update Actor for " + subscription.Domain)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -127,3 +127,16 @@ func TestInvalidRejectFollow(t *testing.T) {
|
||||
relayState.RedisClient.FlushAll().Result()
|
||||
relayState.Load()
|
||||
}
|
||||
|
||||
func TestCreateUpdateActorActivity(t *testing.T) {
|
||||
app := buildNewCmd()
|
||||
|
||||
app.SetArgs([]string{"config", "import", "--json", "../misc/exampleConfig.json"})
|
||||
app.Execute()
|
||||
|
||||
app.SetArgs([]string{"follow", "update"})
|
||||
app.Execute()
|
||||
|
||||
relayState.RedisClient.FlushAll().Result()
|
||||
relayState.Load()
|
||||
}
|
||||
|
Reference in New Issue
Block a user