forked from bluesky-social/indigo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cc12fb
commit 4bad54c
Showing
14 changed files
with
1,935 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cliutil | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
"github.com/whyrusleeping/gosky/api" | ||
"github.com/whyrusleeping/gosky/xrpc" | ||
) | ||
|
||
func GetPLCClient(cctx *cli.Context) *api.PLCServer { | ||
h := "https://plc.staging.bsky.dev" | ||
|
||
if envh := os.Getenv("BSK_PLC_URL"); envh != "" { | ||
h = envh | ||
} | ||
|
||
return &api.PLCServer{ | ||
Host: h, | ||
} | ||
} | ||
|
||
func GetATPClient(cctx *cli.Context, authreq bool) (*api.ATProto, error) { | ||
h := "https://pds.staging.bsky.dev" | ||
if envh := os.Getenv("BSKY_PDS_URL"); envh != "" { | ||
h = envh | ||
} | ||
|
||
auth, err := loadAuthFromEnv(authreq) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &api.ATProto{ | ||
C: &xrpc.Client{ | ||
Host: h, | ||
Auth: auth, | ||
}, | ||
}, nil | ||
} | ||
|
||
func loadAuthFromEnv(req bool) (*xrpc.AuthInfo, error) { | ||
val := os.Getenv("BSKY_AUTH") | ||
if val == "" { | ||
if req { | ||
return nil, fmt.Errorf("no auth env present, BSKY_AUTH not set") | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
var auth xrpc.AuthInfo | ||
if err := json.Unmarshal([]byte(val), &auth); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &auth, nil | ||
} |
Oops, something went wrong.