github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/externals/proof_service_github.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package externals 5 6 import ( 7 "regexp" 8 "strings" 9 10 libkb "github.com/keybase/client/go/libkb" 11 keybase1 "github.com/keybase/client/go/protocol/keybase1" 12 jsonw "github.com/keybase/go-jsonw" 13 ) 14 15 // ============================================================================= 16 // Github 17 // 18 19 type GithubChecker struct { 20 proof libkb.RemoteProofChainLink 21 } 22 23 var _ libkb.ProofChecker = (*GithubChecker)(nil) 24 25 func NewGithubChecker(p libkb.RemoteProofChainLink) (*GithubChecker, libkb.ProofError) { 26 return &GithubChecker{p}, nil 27 } 28 29 func (rc *GithubChecker) GetTorError() libkb.ProofError { return nil } 30 31 func (rc *GithubChecker) CheckStatus(mctx libkb.MetaContext, h libkb.SigHint, _ libkb.ProofCheckerMode, 32 pvlU keybase1.MerkleStoreEntry) (*libkb.SigHint, libkb.ProofError) { 33 // TODO CORE-8951 see if we can populate verifiedHint with anything useful. 34 return nil, CheckProofPvl(mctx, keybase1.ProofType_GITHUB, rc.proof, h, pvlU) 35 } 36 37 // 38 // ============================================================================= 39 40 type GithubServiceType struct{ libkb.BaseServiceType } 41 42 func (t *GithubServiceType) Key() string { return t.GetTypeName() } 43 44 var githubUsernameRegexp = regexp.MustCompile(`^(?i:[a-z0-9][a-z0-9-]{0,38})$`) 45 46 func (t *GithubServiceType) NormalizeUsername(s string) (string, error) { 47 if !githubUsernameRegexp.MatchString(s) { 48 return "", libkb.NewBadUsernameError(s) 49 } 50 return strings.ToLower(s), nil 51 } 52 53 func (t *GithubServiceType) NormalizeRemoteName(mctx libkb.MetaContext, s string) (ret string, err error) { 54 // Allow a leading '@'. 55 s = strings.TrimPrefix(s, "@") 56 return t.NormalizeUsername(s) 57 } 58 59 func (t *GithubServiceType) GetPrompt() string { 60 return "Your username on Github" 61 } 62 63 func (t *GithubServiceType) ToServiceJSON(un string) *jsonw.Wrapper { 64 return t.BaseToServiceJSON(t, un) 65 } 66 67 func (t *GithubServiceType) PostInstructions(un string) *libkb.Markup { 68 return libkb.FmtMarkup(`Please <strong>publicly</strong> post the following Gist, 69 and name it <strong><color name="red">keybase.md</color></strong>`) 70 } 71 72 func (t *GithubServiceType) DisplayName() string { return "GitHub" } 73 func (t *GithubServiceType) GetTypeName() string { return "github" } 74 func (t *GithubServiceType) PickerSubtext() string { return "github.com" } 75 76 func (t *GithubServiceType) RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, _ string) (warning *libkb.Markup, err error) { 77 if status == keybase1.ProofStatus_PERMISSION_DENIED { 78 warning = libkb.FmtMarkup("Permission denied! Make sure your gist is <strong>public</strong>.") 79 } else { 80 warning, err = t.BaseRecheckProofPosting(tryNumber, status) 81 } 82 return 83 } 84 func (t *GithubServiceType) GetProofType() string { return t.BaseGetProofType(t) } 85 86 func (t *GithubServiceType) CheckProofText(text string, id keybase1.SigID, sig string) (err error) { 87 return t.BaseCheckProofTextFull(text, id, sig) 88 } 89 90 func (t *GithubServiceType) MakeProofChecker(l libkb.RemoteProofChainLink) libkb.ProofChecker { 91 return &GithubChecker{l} 92 }