diff --git a/clients/qms.go b/clients/qms.go deleted file mode 100644 index 478716a..0000000 --- a/clients/qms.go +++ /dev/null @@ -1,79 +0,0 @@ -package clients - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "strings" - - "github.com/pkg/errors" -) - -// QMSAPI represents an instance of a QMS API client. -type QMSAPI struct { - baseURL *url.URL -} - -// QMSAPIClient returns a new QMSAPI instance. -func QMSAPIClient(baseURL string) (*QMSAPI, error) { - - // Parse the raw base URL. - url, err := url.Parse(baseURL) - if err != nil { - return nil, err - } - - // Ensure that the base URL path doesn't end with a slash. - url.Path = strings.TrimSuffix(url.Path, "/") - - return &QMSAPI{baseURL: url}, nil -} - -type SubscriptionResult struct { - Result Subscription `json:"result"` -} - -// qmsURL returns a URL that can be used to connect to QMS. The URL path is determined by the base URL and the path -// components in the argument list. -func (c QMSAPI) qmsURL(components ...string) *url.URL { - return BuildURL(c.baseURL, components...) -} - -// GetSubscription retrieves the subscription information for the given user. -func (c *QMSAPI) GetSubscription(ctx context.Context, username string) (*Subscription, error) { - var upr SubscriptionResult - - // Build the request. - requestURL := c.qmsURL("v1", "users", StripUsernameSuffix(username), "plan") - req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestURL.String(), nil) - if err != nil { - return &upr.Result, errors.Wrapf(err, "unable to build the request for %s", requestURL) - } - - // Get the response. - resp, err := client.Do(req) - if err != nil { - return &upr.Result, errors.Wrapf(err, "unable to send the request to %s", requestURL) - } - defer resp.Body.Close() - if resp.StatusCode < 200 || resp.StatusCode > 299 { - return &upr.Result, NewHTTPError(resp.StatusCode, fmt.Sprintf("%s returned %d", requestURL, resp.StatusCode)) - } - - // Read the response body. - body, err := io.ReadAll(resp.Body) - if err != nil { - return &upr.Result, errors.Wrapf(err, "unable to read the response from %s", requestURL) - } - - // Unmarshal the response body. - err = json.Unmarshal(body, &upr) - if err != nil { - return &upr.Result, errors.Wrapf(err, "unable to parse the response from %s", requestURL) - } - - return &upr.Result, nil -} diff --git a/internal/internal.go b/internal/internal.go index f41d152..3e48b9b 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -26,7 +26,6 @@ type App struct { amqpClient *amqp.AMQP natsClient *nats.EncodedConn amqpUsageRoutingKey string - qmsClient *clients.QMSAPI qmsEnabled bool subscriptionsBaseURI string } @@ -40,7 +39,6 @@ type AppConfiguration struct { NATSClient *nats.EncodedConn AMQPUsageRoutingKey string QMSEnabled bool - QMSBaseURL string SubscriptionsBaseURI string } @@ -63,10 +61,6 @@ func New(db *sqlx.DB, config *AppConfiguration) (*App, error) { if err != nil { return nil, errors.Wrap(err, "unable to create the data-usage-api client") } - qmsClient, err := clients.QMSAPIClient(config.QMSBaseURL) - if err != nil { - return nil, errors.Wrap(err, "unable to create the QMS client") - } // Create the app instance. app := &App{ @@ -77,7 +71,6 @@ func New(db *sqlx.DB, config *AppConfiguration) (*App, error) { amqpClient: config.AMQPClient, natsClient: config.NATSClient, amqpUsageRoutingKey: config.AMQPUsageRoutingKey, - qmsClient: qmsClient, qmsEnabled: config.QMSEnabled, subscriptionsBaseURI: config.SubscriptionsBaseURI, } diff --git a/main.go b/main.go index e50193f..55b7431 100644 --- a/main.go +++ b/main.go @@ -133,13 +133,6 @@ func main() { } qmsEnabled := config.Bool("qms.enabled") - qmsBaseURL := config.String("qms.base") - - if qmsEnabled { - if qmsBaseURL == "" { - log.Fatal("qms.base must be set in the configuration file if qms.enabled is true") - } - } natsCluster := config.String("nats.cluster") if natsCluster == "" { @@ -224,7 +217,6 @@ func main() { NATSClient: natsClient, AMQPUsageRoutingKey: *usageRoutingKey, QMSEnabled: qmsEnabled, - QMSBaseURL: qmsBaseURL, SubscriptionsBaseURI: *subscriptionsBase, }