Skip to content

Commit

Permalink
chore: move alby api URLs to the alby oauth service
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Sep 12, 2024
1 parent 60128af commit e9823dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 18 additions & 12 deletions alby/alby_oauth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const (
lightningAddressKey = "AlbyLightningAddress"
)

const (
albyOAuthAPIURL = "https://api.getalby.com"
albyInternalAPIURL = "https://getalby.com/api"
albyOAuthAuthUrl = "https://getalby.com/oauth"
)

const ALBY_ACCOUNT_APP_NAME = "getalby.com"

func NewAlbyOAuthService(db *gorm.DB, cfg config.Config, keys keys.Keys, eventPublisher events.EventPublisher) *albyOAuthService {
Expand All @@ -57,8 +63,8 @@ func NewAlbyOAuthService(db *gorm.DB, cfg config.Config, keys keys.Keys, eventPu
ClientSecret: cfg.GetEnv().AlbyClientSecret,
Scopes: []string{"account:read", "balance:read", "payments:send"},
Endpoint: oauth2.Endpoint{
TokenURL: cfg.GetEnv().AlbyAPIURL + "/oauth/token",
AuthURL: cfg.GetEnv().AlbyOAuthAuthUrl,
TokenURL: albyOAuthAPIURL + "/oauth/token",
AuthURL: albyOAuthAuthUrl,
AuthStyle: 2, // use HTTP Basic Authorization https://pkg.go.dev/golang.org/x/oauth2#AuthStyle
},
}
Expand Down Expand Up @@ -215,7 +221,7 @@ func (svc *albyOAuthService) fetchUserToken(ctx context.Context) (*oauth2.Token,
func (svc *albyOAuthService) GetInfo(ctx context.Context) (*AlbyInfo, error) {
client := &http.Client{Timeout: 10 * time.Second}

req, err := http.NewRequest("GET", "https://getalby.com/api/internal/info", nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/info", albyInternalAPIURL), nil)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request to alby info endpoint")
return nil, err
Expand Down Expand Up @@ -263,7 +269,7 @@ func (svc *albyOAuthService) GetMe(ctx context.Context) (*AlbyMe, error) {

client := svc.oauthConf.Client(ctx, token)

req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/users", svc.cfg.GetEnv().AlbyAPIURL), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/users", albyOAuthAPIURL), nil)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request /me")
return nil, err
Expand Down Expand Up @@ -300,7 +306,7 @@ func (svc *albyOAuthService) GetBalance(ctx context.Context) (*AlbyBalance, erro

client := svc.oauthConf.Client(ctx, token)

req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/lndhub/balance", svc.cfg.GetEnv().AlbyAPIURL), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/lndhub/balance", albyOAuthAPIURL), nil)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request to balance endpoint")
return nil, err
Expand Down Expand Up @@ -384,7 +390,7 @@ func (svc *albyOAuthService) SendPayment(ctx context.Context, invoice string) er
return err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/internal/lndhub/bolt11", svc.cfg.GetEnv().AlbyAPIURL), body)
req, err := http.NewRequest("POST", fmt.Sprintf("%s/internal/lndhub/bolt11", albyOAuthAPIURL), body)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request bolt11 endpoint")
return err
Expand Down Expand Up @@ -657,7 +663,7 @@ func (svc *albyOAuthService) ConsumeEvent(ctx context.Context, event *events.Eve
return
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/events", svc.cfg.GetEnv().AlbyAPIURL), body)
req, err := http.NewRequest("POST", fmt.Sprintf("%s/events", albyOAuthAPIURL), body)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request /events")
return
Expand Down Expand Up @@ -726,7 +732,7 @@ func (svc *albyOAuthService) backupChannels(ctx context.Context, event *events.E
return fmt.Errorf("failed to encode channels backup request payload: %w", err)
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/internal/backups", svc.cfg.GetEnv().AlbyAPIURL), body)
req, err := http.NewRequest("POST", fmt.Sprintf("%s/internal/backups", albyOAuthAPIURL), body)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
Expand Down Expand Up @@ -769,7 +775,7 @@ func (svc *albyOAuthService) createAlbyAccountNWCNode(ctx context.Context) (stri
return "", err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/internal/nwcs", svc.cfg.GetEnv().AlbyAPIURL), body)
req, err := http.NewRequest("POST", fmt.Sprintf("%s/internal/nwcs", albyOAuthAPIURL), body)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request /internal/nwcs")
return "", err
Expand Down Expand Up @@ -819,7 +825,7 @@ func (svc *albyOAuthService) destroyAlbyAccountNWCNode(ctx context.Context) erro

client := svc.oauthConf.Client(ctx, token)

req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/internal/nwcs", svc.cfg.GetEnv().AlbyAPIURL), nil)
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/internal/nwcs", albyOAuthAPIURL), nil)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request /internal/nwcs")
return err
Expand Down Expand Up @@ -853,7 +859,7 @@ func (svc *albyOAuthService) activateAlbyAccountNWCNode(ctx context.Context) err

client := svc.oauthConf.Client(ctx, token)

req, err := http.NewRequest("PUT", fmt.Sprintf("%s/internal/nwcs/activate", svc.cfg.GetEnv().AlbyAPIURL), nil)
req, err := http.NewRequest("PUT", fmt.Sprintf("%s/internal/nwcs/activate", albyOAuthAPIURL), nil)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request /internal/nwcs/activate")
return err
Expand Down Expand Up @@ -883,7 +889,7 @@ func (svc *albyOAuthService) GetChannelPeerSuggestions(ctx context.Context) ([]C

client := &http.Client{Timeout: 10 * time.Second}

req, err := http.NewRequest("GET", "https://getalby.com/api/internal/channel_suggestions", nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/internal/channel_suggestions", albyInternalAPIURL), nil)
if err != nil {
logger.Logger.WithError(err).Error("Error creating request to channel_suggestions endpoint")
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions config/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ type AppConfig struct {
LDKGossipSource string `envconfig:"LDK_GOSSIP_SOURCE"`
LDKLogLevel string `envconfig:"LDK_LOG_LEVEL" default:"3"`
MempoolApi string `envconfig:"MEMPOOL_API" default:"https://mempool.space/api"`
AlbyAPIURL string `envconfig:"ALBY_API_URL" default:"https://api.getalby.com"`
AlbyClientId string `envconfig:"ALBY_OAUTH_CLIENT_ID" default:"J2PbXS1yOf"`
AlbyClientSecret string `envconfig:"ALBY_OAUTH_CLIENT_SECRET" default:"rABK2n16IWjLTZ9M1uKU"`
AlbyOAuthAuthUrl string `envconfig:"ALBY_OAUTH_AUTH_URL" default:"https://getalby.com/oauth"`
BaseUrl string `envconfig:"BASE_URL"`
FrontendUrl string `envconfig:"FRONTEND_URL"`
LogEvents bool `envconfig:"LOG_EVENTS" default:"true"`
Expand Down

0 comments on commit e9823dc

Please sign in to comment.