From 8027cc454e0fd571de69d496f1de13c51d2ab6e7 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Fri, 24 May 2019 16:55:12 +0100 Subject: [PATCH] Move api to pkg/requests --- api/api.go => pkg/requests/requests.go | 2 +- api/api_test.go => pkg/requests/requests_test.go | 2 +- providers/azure.go | 4 ++-- providers/facebook.go | 4 ++-- providers/gitlab.go | 4 ++-- providers/internal_util.go | 4 ++-- providers/linkedin.go | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) rename api/api.go => pkg/requests/requests.go (98%) rename api/api_test.go => pkg/requests/requests_test.go (99%) diff --git a/api/api.go b/pkg/requests/requests.go similarity index 98% rename from api/api.go rename to pkg/requests/requests.go index c5d5623..aac22e4 100644 --- a/api/api.go +++ b/pkg/requests/requests.go @@ -1,4 +1,4 @@ -package api +package requests import ( "encoding/json" diff --git a/api/api_test.go b/pkg/requests/requests_test.go similarity index 99% rename from api/api_test.go rename to pkg/requests/requests_test.go index 7bdf1b7..99a4c3b 100644 --- a/api/api_test.go +++ b/pkg/requests/requests_test.go @@ -1,4 +1,4 @@ -package api +package requests import ( "io/ioutil" diff --git a/providers/azure.go b/providers/azure.go index a7961d2..3154432 100644 --- a/providers/azure.go +++ b/providers/azure.go @@ -7,9 +7,9 @@ import ( "net/url" "github.com/bitly/go-simplejson" - "github.com/pusher/oauth2_proxy/api" "github.com/pusher/oauth2_proxy/logger" "github.com/pusher/oauth2_proxy/pkg/apis/sessions" + "github.com/pusher/oauth2_proxy/pkg/requests" ) // AzureProvider represents an Azure based Identity Provider @@ -102,7 +102,7 @@ func (p *AzureProvider) GetEmailAddress(s *sessions.SessionState) (string, error } req.Header = getAzureHeader(s.AccessToken) - json, err := api.Request(req) + json, err := requests.Request(req) if err != nil { return "", err diff --git a/providers/facebook.go b/providers/facebook.go index 9897a1b..abd5382 100644 --- a/providers/facebook.go +++ b/providers/facebook.go @@ -6,8 +6,8 @@ import ( "net/http" "net/url" - "github.com/pusher/oauth2_proxy/api" "github.com/pusher/oauth2_proxy/pkg/apis/sessions" + "github.com/pusher/oauth2_proxy/pkg/requests" ) // FacebookProvider represents an Facebook based Identity Provider @@ -69,7 +69,7 @@ func (p *FacebookProvider) GetEmailAddress(s *sessions.SessionState) (string, er Email string } var r result - err = api.RequestJSON(req, &r) + err = requests.RequestJSON(req, &r) if err != nil { return "", err } diff --git a/providers/gitlab.go b/providers/gitlab.go index af956c4..c9a4a1f 100644 --- a/providers/gitlab.go +++ b/providers/gitlab.go @@ -4,9 +4,9 @@ import ( "net/http" "net/url" - "github.com/pusher/oauth2_proxy/api" "github.com/pusher/oauth2_proxy/logger" "github.com/pusher/oauth2_proxy/pkg/apis/sessions" + "github.com/pusher/oauth2_proxy/pkg/requests" ) // GitLabProvider represents an GitLab based Identity Provider @@ -53,7 +53,7 @@ func (p *GitLabProvider) GetEmailAddress(s *sessions.SessionState) (string, erro logger.Printf("failed building request %s", err) return "", err } - json, err := api.Request(req) + json, err := requests.Request(req) if err != nil { logger.Printf("failed making request %s", err) return "", err diff --git a/providers/internal_util.go b/providers/internal_util.go index 7144dee..bb5f4f5 100644 --- a/providers/internal_util.go +++ b/providers/internal_util.go @@ -5,8 +5,8 @@ import ( "net/http" "net/url" - "github.com/pusher/oauth2_proxy/api" "github.com/pusher/oauth2_proxy/logger" + "github.com/pusher/oauth2_proxy/pkg/requests" ) // stripToken is a helper function to obfuscate "access_token" @@ -55,7 +55,7 @@ func validateToken(p Provider, accessToken string, header http.Header) bool { params := url.Values{"access_token": {accessToken}} endpoint = endpoint + "?" + params.Encode() } - resp, err := api.RequestUnparsedResponse(endpoint, header) + resp, err := requests.RequestUnparsedResponse(endpoint, header) if err != nil { logger.Printf("GET %s", stripToken(endpoint)) logger.Printf("token validation request failed: %s", err) diff --git a/providers/linkedin.go b/providers/linkedin.go index a31b4a1..bca2936 100644 --- a/providers/linkedin.go +++ b/providers/linkedin.go @@ -6,8 +6,8 @@ import ( "net/http" "net/url" - "github.com/pusher/oauth2_proxy/api" "github.com/pusher/oauth2_proxy/pkg/apis/sessions" + "github.com/pusher/oauth2_proxy/pkg/requests" ) // LinkedInProvider represents an LinkedIn based Identity Provider @@ -61,7 +61,7 @@ func (p *LinkedInProvider) GetEmailAddress(s *sessions.SessionState) (string, er } req.Header = getLinkedInHeader(s.AccessToken) - json, err := api.Request(req) + json, err := requests.Request(req) if err != nil { return "", err }