package activityserve import ( "encoding/json" "encoding/pem" "github.com/gologme/log" "crypto/x509" "crypto/rsa" ) type RemoteActor struct { iri, outbox, inbox, sharedInbox string url string info map[string]interface{} publicKey *rsa.PublicKey la Actor } func NewRemoteActor(a Actor,iri string) (RemoteActor, error) { info, err := get(a,iri) if err != nil { log.Info("Couldn't get remote actor information") log.Info(err) return RemoteActor{}, err } publicKeyBlock := info["publicKey"].(map[string]interface {}) publicKeyPem := publicKeyBlock["publicKeyPem"].(string) spkiBlock, _ := pem.Decode([]byte(publicKeyPem)) var spkiKey *rsa.PublicKey pubInterface, _ := x509.ParsePKIXPublicKey(spkiBlock.Bytes) spkiKey = pubInterface.(*rsa.PublicKey) outbox, _ := info["outbox"].(string) inbox, _ := info["inbox"].(string) url, _ := info["url"].(string) var endpoints map[string]interface{} var sharedInbox string if info["endpoints"] != nil { endpoints = info["endpoints"].(map[string]interface{}) if val, ok := endpoints["sharedInbox"]; ok { sharedInbox = val.(string) } } return RemoteActor{ iri: iri, outbox: outbox, inbox: inbox, sharedInbox: sharedInbox, url: url, publicKey: spkiKey, la: a, info: info, }, err } func (ra RemoteActor) GetRaw() (map[string]interface{}){ return ra.info } func (ra RemoteActor) getLatestPosts(number int) (map[string]interface{}, error) { return get(ra.la,ra.outbox) } func get(a Actor,iri string) (info map[string]interface{}, err error) { // sactor,err := GetActor("server","Internal service actor","Service") if err != nil { log.Info("Failed to get service actor") log.Info(err) return } responseData,err := a.signedHTTPGet(iri) if err != nil { log.Info("Failed to make signed http get request") log.Info(err) return } var e interface{} err = json.Unmarshal([]byte(responseData), &e) if err != nil { log.Info("something went wrong when unmarshalling the json") log.Info(err) return } info = e.(map[string]interface{}) return } // GetInbox returns the inbox url of the actor func (ra RemoteActor) GetInbox() string { return ra.inbox } // GetSharedInbox returns the inbox url of the actor func (ra RemoteActor) GetSharedInbox() string { if ra.sharedInbox == "" { return ra.inbox } return ra.sharedInbox } func (ra RemoteActor) URL() string { return ra.url }