Added FederationInfo Create function

This commit is contained in:
Clemens 2024-01-12 17:27:52 +01:00 committed by Michael Jerger
parent 380d3db0bf
commit 1f989f2ecd
3 changed files with 19 additions and 16 deletions

View file

@ -42,3 +42,11 @@ func FindFederationInfoByHostFqdn(ctx context.Context, fqdn string) (*Federation
} }
return info, nil return info, nil
} }
func CreateFederationInfo(ctx context.Context, info FederationInfo) error {
if res, err := validation.IsValid(info); !res {
return fmt.Errorf("FederationInfo is not valid: %v", err)
}
_, err := db.GetEngine(ctx).Insert(info)
return err
}

View file

@ -106,7 +106,7 @@ func RepositoryInbox(ctx *context.APIContext) {
return return
} }
federationInfo = &result federationInfo = &result
log.Info("RepositoryInbox: nodeInfo validated: %v", federationInfo) log.Info("RepositoryInbox: federationInfo validated: %v", federationInfo)
} }
actorID, err := forgefed.NewPersonID(actorUri, string(federationInfo.NodeInfo.Source)) actorID, err := forgefed.NewPersonID(actorUri, string(federationInfo.NodeInfo.Source))
@ -222,6 +222,10 @@ func createFederationInfo(ctx *context.APIContext, actorID forgefed.ActorID) (fo
HostFqdn: actorID.Host, HostFqdn: actorID.Host,
NodeInfo: nodeInfo, NodeInfo: nodeInfo,
} }
err = forgefed.CreateFederationInfo(ctx, result)
if err != nil {
return forgefed.FederationInfo{}, err
}
return result, nil return result, nil
} }

View file

@ -71,7 +71,7 @@
"name": "body", "name": "body",
"in": "body", "in": "body",
"schema": { "schema": {
"$ref": "#/definitions/Star" "$ref": "#/definitions/ForgeLike"
} }
} }
], ],
@ -20480,6 +20480,11 @@
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"
}, },
"ForgeLike": {
"description": "ForgeLike activity data type",
"type": "object",
"x-go-package": "code.gitea.io/gitea/models/forgefed"
},
"GPGKey": { "GPGKey": {
"description": "GPGKey a user GPG key to sign commit and tag in repository", "description": "GPGKey a user GPG key to sign commit and tag in repository",
"type": "object", "type": "object",
@ -23178,20 +23183,6 @@
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"
}, },
"SourceType": {
"type": "string",
"x-go-package": "code.gitea.io/gitea/models/forgefed"
},
"Star": {
"description": "Star activity data type",
"type": "object",
"properties": {
"Source": {
"$ref": "#/definitions/SourceType"
}
},
"x-go-package": "code.gitea.io/gitea/models/forgefed"
},
"StateType": { "StateType": {
"description": "StateType issue state type", "description": "StateType issue state type",
"type": "string", "type": "string",