Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic github reverse email lookup (only first result tho and high api… #281

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ curl -X POST http://localhost:8080/person \
"name": "Discord",
"username": ""
},
"GitHub": {
"icon": "./images/mail/github.svg",
"link": "",
"name": "GitHub",
"username": ""
},
"Spotify": {
"icon": "./images/mail/spotify.png",
"link": "",
Expand Down Expand Up @@ -1190,6 +1196,12 @@ curl -X POST http://localhost:8080/person \
"name": "Discord",
"username": ""
},
"GitHub": {
"icon": "./images/mail/github.svg",
"link": "",
"name": "GitHub",
"username": ""
},
"Spotify": {
"icon": "./images/mail/spotify.png",
"link": "",
Expand Down Expand Up @@ -1278,7 +1290,7 @@ curl -X GET http://localhost:8080/people/24/markdown

```json
{
"markdown": "# Many fields\n- Age: `23`\n- Phone: `+1 318-344-2908`\n## Email\n### [email protected]\n- Mail: `[email protected]`\n- Provider: `gmail`\n#### Services\n##### Discord\n- Name: `Discord`\n- Icon: `./images/mail/discord.png`\n##### Spotify\n- Name: `Spotify`\n- Icon: `./images/mail/spotify.png`\n##### Twitter\n- Name: `Twitter`\n- Icon: `./images/mail/twitter.png`\n##### Ubuntu GPG\n- Name: `Ubuntu GPG`\n- Link: `https://keyserver.ubuntu.com/pks/[email protected]\u0026op=index`\n- Icon: `./images/mail/ubuntu.png`\n##### keys.gnupg.net\n- Name: `keys.gnupg.net`\n- Link: `https://keys.gnupg.net/pks/[email protected]\u0026op=index`\n- Icon: `./images/mail/gnupg.ico`\n\n\n"
"markdown": "# Many fields\n- Age: `23`\n- Phone: `+1 318-344-2908`\n## Email\n### [email protected]\n- Mail: `[email protected]`\n- Provider: `gmail`\n#### Services\n##### Discord\n- Name: `Discord`\n- Icon: `./images/mail/discord.png`\n##### GitHub\n- Name: `GitHub`\n- Icon: `./images/mail/github.svg`\n##### Spotify\n- Name: `Spotify`\n- Icon: `./images/mail/spotify.png`\n##### Twitter\n- Name: `Twitter`\n- Icon: `./images/mail/twitter.png`\n##### Ubuntu GPG\n- Name: `Ubuntu GPG`\n- Link: `https://keyserver.ubuntu.com/pks/[email protected]\u0026op=index`\n- Icon: `./images/mail/ubuntu.png`\n##### keys.gnupg.net\n- Name: `keys.gnupg.net`\n- Link: `https://keys.gnupg.net/pks/[email protected]\u0026op=index`\n- Icon: `./images/mail/gnupg.ico`\n\n\n"
}
```

Expand Down
5 changes: 5 additions & 0 deletions api/email_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ var DefaultMailServices = MailServices{
UserExistsFunc: TwitterMail,
Icon: "./images/mail/twitter.png",
},
MailService{
Name: "GitHub",
UserExistsFunc: GitHubEmail,
Icon: "./images/mail/github.svg",
},
MailService{
Name: "Ubuntu GPG",
UserExistsFunc: UbuntuGPGUserExists,
Expand Down
73 changes: 73 additions & 0 deletions api/github_email.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package api

import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
)

func searchGithubUsersByEmail(email, token string) ([]GithubUser, error) {
url := fmt.Sprintf("https://api.github.com/search/users?q=%s", email)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}

if token != "" {
req.Header.Set("Authorization", fmt.Sprintf("token %s", token))
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var searchResult GithubSearchResult
err = json.NewDecoder(resp.Body).Decode(&searchResult)
if err != nil {
return nil, err
}

return searchResult.Items, nil
}

type GithubUser struct {
Login string `json:"login"`
ID int `json:"id"`
AvatarURL string `json:"avatar_url"`
URL string `json:"html_url"`
}

type GithubSearchResult struct {
TotalCount int `json:"total_count"`
IncompleteResults bool `json:"incomplete_results"`
Items []GithubUser `json:"items"`
}

func GitHubEmail(mailService MailService, email string, config ApiConfig) (EmailService, error) { // FIXME multiple results
emailService := EmailService{
Name: mailService.Name,
Icon: mailService.Icon,
}
if config.Testing {
if email == "[email protected]" {
log.Println("all email testing case true")
return emailService, nil
} else if email == "[email protected]" {
return EmailService{}, errors.New("error")
}
log.Println("all email testing case false")

return EmailService{}, nil
}
githubUser, err := searchGithubUsersByEmail(email, "")
if len(githubUser) >= 1 {
emailService.Username = githubUser[0].Login
emailService.Link = githubUser[0].URL
}

return emailService, err
}
6 changes: 3 additions & 3 deletions api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var requests = Requests{
Name: "Post person with included email detecting all services",
URL: "http://localhost:8080/person",
PostData: map[string]interface{}{"accounts": interface{}(nil), "age": float64(10), "email": map[string]interface{}{"[email protected]": map[string]interface{}{"mail": "[email protected]"}}, "id": "12", "name": "Email test"},
ExpectedResponse: map[string]interface{}{"accounts": map[string]interface{}{}, "address": "", "gender": "", "age": float64(10), "bday": "", "custom": interface{}(nil), "civilstatus": "", "club": "", "education": "", "email": map[string]interface{}{"[email protected]": map[string]interface{}{"mail": "[email protected]", "provider": "gmail", "services": map[string]interface{}{"Discord": map[string]interface{}{"icon": "./images/mail/discord.png", "link": "", "name": "Discord", "username": ""}, "Spotify": map[string]interface{}{"icon": "./images/mail/spotify.png", "link": "", "name": "Spotify", "username": ""}, "Twitter": map[string]interface{}{"icon": "./images/mail/twitter.png", "link": "", "name": "Twitter", "username": ""}, "Ubuntu GPG": map[string]interface{}{"icon": "./images/mail/ubuntu.png", "link": "https://keyserver.ubuntu.com/pks/[email protected]&op=index", "name": "Ubuntu GPG", "username": ""}, "keys.gnupg.net": map[string]interface{}{"icon": "./images/mail/gnupg.ico", "link": "https://keys.gnupg.net/pks/[email protected]&op=index", "name": "keys.gnupg.net", "username": ""}}, "skipped_services": map[string]interface{}{}, "src": "", "valid": true, "value": float64(0)}}, "hobbies": "", "id": "12", "kids": "", "legal": "", "maidenname": "", "military": "", "name": "Email test", "notaccounts": interface{}(nil), "notes": "", "occupation": "", "pets": "", "phone": map[string]interface{}{}, "pictures": map[string]interface{}{}, "political": "", "prevoccupation": "", "relations": map[string]interface{}{}, "religion": "", "sources": map[string]interface{}{}, "ssn": "", "tags": []interface{}{}},
ExpectedResponse: map[string]interface{}{"accounts": map[string]interface{}{}, "address": "", "gender": "", "age": float64(10), "bday": "", "custom": interface{}(nil), "civilstatus": "", "club": "", "education": "", "email": map[string]interface{}{"[email protected]": map[string]interface{}{"mail": "[email protected]", "provider": "gmail", "services": map[string]interface{}{"Discord": map[string]interface{}{"icon": "./images/mail/discord.png", "link": "", "name": "Discord", "username": ""}, "GitHub": map[string]interface{}{"icon": "./images/mail/github.svg", "link": "", "name": "GitHub", "username": ""}, "Spotify": map[string]interface{}{"icon": "./images/mail/spotify.png", "link": "", "name": "Spotify", "username": ""}, "Twitter": map[string]interface{}{"icon": "./images/mail/twitter.png", "link": "", "name": "Twitter", "username": ""}, "Ubuntu GPG": map[string]interface{}{"icon": "./images/mail/ubuntu.png", "link": "https://keyserver.ubuntu.com/pks/[email protected]&op=index", "name": "Ubuntu GPG", "username": ""}, "keys.gnupg.net": map[string]interface{}{"icon": "./images/mail/gnupg.ico", "link": "https://keys.gnupg.net/pks/[email protected]&op=index", "name": "keys.gnupg.net", "username": ""}}, "skipped_services": map[string]interface{}{}, "src": "", "valid": true, "value": float64(0)}}, "hobbies": "", "id": "12", "kids": "", "legal": "", "maidenname": "", "military": "", "name": "Email test", "notaccounts": interface{}(nil), "notes": "", "occupation": "", "pets": "", "phone": map[string]interface{}{}, "pictures": map[string]interface{}{}, "political": "", "prevoccupation": "", "relations": map[string]interface{}{}, "religion": "", "sources": map[string]interface{}{}, "ssn": "", "tags": []interface{}{}},
StatusCode: 201,
RequiresInternetConnection: true,
},
Expand Down Expand Up @@ -225,15 +225,15 @@ var requests = Requests{
Name: "Post Person (Lot of fields)",
URL: "http://localhost:8080/person",
PostData: map[string]interface{}{"phone": map[string]interface{}{"+13183442908": map[string]interface{}{"number": "+13183442908"}}, "id": "24", "name": "Many fields", "age": float64(23), "email": map[string]interface{}{"[email protected]": map[string]interface{}{"mail": "[email protected]"}}},
ExpectedResponse: map[string]interface{}{"custom": interface{}(nil), "accounts": map[string]interface{}{}, "address": "", "age": float64(23), "bday": "", "civilstatus": "", "club": "", "education": "", "email": map[string]interface{}{"[email protected]": map[string]interface{}{"mail": "[email protected]", "provider": "gmail", "services": map[string]interface{}{"Discord": map[string]interface{}{"icon": "./images/mail/discord.png", "link": "", "name": "Discord", "username": ""}, "Spotify": map[string]interface{}{"icon": "./images/mail/spotify.png", "link": "", "name": "Spotify", "username": ""}, "Twitter": map[string]interface{}{"icon": "./images/mail/twitter.png", "link": "", "name": "Twitter", "username": ""}, "Ubuntu GPG": map[string]interface{}{"icon": "./images/mail/ubuntu.png", "link": "https://keyserver.ubuntu.com/pks/[email protected]&op=index", "name": "Ubuntu GPG", "username": ""}, "keys.gnupg.net": map[string]interface{}{"icon": "./images/mail/gnupg.ico", "link": "https://keys.gnupg.net/pks/[email protected]&op=index", "name": "keys.gnupg.net", "username": ""}}, "skipped_services": map[string]interface{}{}, "src": "", "valid": true, "value": float64(0)}}, "gender": "", "hobbies": "", "id": "24", "kids": "", "legal": "", "maidenname": "", "military": "", "name": "Many fields", "notaccounts": interface{}(nil), "notes": "", "occupation": "", "pets": "", "phone": map[string]interface{}{"+1 318-344-2908": map[string]interface{}{"national_format": "(318) 344-2908", "number": "+1 318-344-2908", "phoneinfoga": map[string]interface{}{"Carrier": "", "Country": "US", "CountryCode": float64(1), "E164": "+13183442908", "International": "13183442908", "Local": "(318) 344-2908", "RawLocal": "3183442908", "Valid": true}, "tag": "", "valid": true}}, "pictures": map[string]interface{}{}, "political": "", "prevoccupation": "", "relations": map[string]interface{}{}, "religion": "", "sources": map[string]interface{}{}, "ssn": "", "tags": []interface{}{}},
ExpectedResponse: map[string]interface{}{"custom": interface{}(nil), "accounts": map[string]interface{}{}, "address": "", "age": float64(23), "bday": "", "civilstatus": "", "club": "", "education": "", "email": map[string]interface{}{"[email protected]": map[string]interface{}{"mail": "[email protected]", "provider": "gmail", "services": map[string]interface{}{"Discord": map[string]interface{}{"icon": "./images/mail/discord.png", "link": "", "name": "Discord", "username": ""}, "GitHub": map[string]interface{}{"icon": "./images/mail/github.svg", "link": "", "name": "GitHub", "username": ""}, "Spotify": map[string]interface{}{"icon": "./images/mail/spotify.png", "link": "", "name": "Spotify", "username": ""}, "Twitter": map[string]interface{}{"icon": "./images/mail/twitter.png", "link": "", "name": "Twitter", "username": ""}, "Ubuntu GPG": map[string]interface{}{"icon": "./images/mail/ubuntu.png", "link": "https://keyserver.ubuntu.com/pks/[email protected]&op=index", "name": "Ubuntu GPG", "username": ""}, "keys.gnupg.net": map[string]interface{}{"icon": "./images/mail/gnupg.ico", "link": "https://keys.gnupg.net/pks/[email protected]&op=index", "name": "keys.gnupg.net", "username": ""}}, "skipped_services": map[string]interface{}{}, "src": "", "valid": true, "value": float64(0)}}, "gender": "", "hobbies": "", "id": "24", "kids": "", "legal": "", "maidenname": "", "military": "", "name": "Many fields", "notaccounts": interface{}(nil), "notes": "", "occupation": "", "pets": "", "phone": map[string]interface{}{"+1 318-344-2908": map[string]interface{}{"national_format": "(318) 344-2908", "number": "+1 318-344-2908", "phoneinfoga": map[string]interface{}{"Carrier": "", "Country": "US", "CountryCode": float64(1), "E164": "+13183442908", "International": "13183442908", "Local": "(318) 344-2908", "RawLocal": "3183442908", "Valid": true}, "tag": "", "valid": true}}, "pictures": map[string]interface{}{}, "political": "", "prevoccupation": "", "relations": map[string]interface{}{}, "religion": "", "sources": map[string]interface{}{}, "ssn": "", "tags": []interface{}{}},
StatusCode: 201,
},
"9o-postPerson": { // ID 24
RequestType: "GET",
Name: "GET Person Markdown",
URL: "http://localhost:8080/people/24/markdown",
PostData: nil,
ExpectedResponse: map[string]interface{}{"markdown": "# Many fields\n- Age: `23`\n- Phone: `+1 318-344-2908`\n## Email\n### [email protected]\n- Mail: `[email protected]`\n- Provider: `gmail`\n#### Services\n##### Discord\n- Name: `Discord`\n- Icon: `./images/mail/discord.png`\n##### Spotify\n- Name: `Spotify`\n- Icon: `./images/mail/spotify.png`\n##### Twitter\n- Name: `Twitter`\n- Icon: `./images/mail/twitter.png`\n##### Ubuntu GPG\n- Name: `Ubuntu GPG`\n- Link: `https://keyserver.ubuntu.com/pks/[email protected]&op=index`\n- Icon: `./images/mail/ubuntu.png`\n##### keys.gnupg.net\n- Name: `keys.gnupg.net`\n- Link: `https://keys.gnupg.net/pks/[email protected]&op=index`\n- Icon: `./images/mail/gnupg.ico`\n\n\n"},
ExpectedResponse: map[string]interface{}{"markdown": "# Many fields\n- Age: `23`\n- Phone: `+1 318-344-2908`\n## Email\n### [email protected]\n- Mail: `[email protected]`\n- Provider: `gmail`\n#### Services\n##### Discord\n- Name: `Discord`\n- Icon: `./images/mail/discord.png`\n##### GitHub\n- Name: `GitHub`\n- Icon: `./images/mail/github.svg`\n##### Spotify\n- Name: `Spotify`\n- Icon: `./images/mail/spotify.png`\n##### Twitter\n- Name: `Twitter`\n- Icon: `./images/mail/twitter.png`\n##### Ubuntu GPG\n- Name: `Ubuntu GPG`\n- Link: `https://keyserver.ubuntu.com/pks/[email protected]&op=index`\n- Icon: `./images/mail/ubuntu.png`\n##### keys.gnupg.net\n- Name: `keys.gnupg.net`\n- Link: `https://keys.gnupg.net/pks/[email protected]&op=index`\n- Icon: `./images/mail/gnupg.ico`\n\n\n"},
StatusCode: 200,
},
//"9o-Deep": { // deep
Expand Down