Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource? herokux_addon_manifest #201

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions api/addons/addons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package addons

import (
"fmt"
"github.com/davidji99/simpleresty"
config2 "github.com/davidji99/terraform-provider-herokux/api/pkg/config"
"time"
)

// Addons represents Heroku's Addons APIs.
type Addons struct {
http *simpleresty.Client
config *config2.Config
}

// New constructs a client to interface with the Heroku Addons APIs.
func New(config *config2.Config) *Addons {
p := &Addons{http: simpleresty.NewWithBaseURL(config.KafkaBaseURL), config: config}
p.setHeaders()

return p
}

func (a *Addons) setHeaders() {
a.http.SetHeader("Content-type", a.config.ContentTypeHeader).
SetHeader("Accept", a.config.ContentTypeHeader).
SetHeader("User-Agent", a.config.UserAgent).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", a.config.APIToken)).
SetTimeout(2 * time.Minute).
SetAllowGetMethodPayload(true)

// Set additional headers
if a.config.CustomHTTPHeaders != nil {
a.http.SetHeaders(a.config.CustomHTTPHeaders)
}
}
11 changes: 9 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"github.com/davidji99/terraform-provider-herokux/api/addons"
"github.com/davidji99/terraform-provider-herokux/api/connect"
"github.com/davidji99/terraform-provider-herokux/api/data"
"github.com/davidji99/terraform-provider-herokux/api/kafka"
Expand Down Expand Up @@ -47,6 +48,9 @@ const (
// DefaultSchedulerAPIBaseURL is the default base URL for Scheduler API.
DefaultSchedulerAPIBaseURL = "https://particleboard.heroku.com"

// DefaultAddonsAPIBaseURL is the default base URL for Scheduler API.
DefaultAddonsAPIBaseURL = "https://addons.heroku.com"

// DefaultUserAgent is the user agent used when making API calls.
DefaultUserAgent = "herokux-go"

Expand Down Expand Up @@ -79,6 +83,7 @@ type Client struct {
Redis *redis.Redis
Registry *registry.Registry
Scheduler *scheduler.Scheduler
Addons *addons.Addons
}

// New constructs a new client to interact with Heroku APIs.
Expand All @@ -94,8 +99,9 @@ func New(opts ...config2.Option) (*Client, error) {
ConnectBaseURL: DefaultConnectAPIBaseURL,
ConnectCentralBaseURL: DefaultConnectCentralBaseURL,
RegistryBaseURL: DefaultRegistryBaseURL,
KolkrabbiURL: DefaultKolkrabbiAPIBaseURL,
SchedulerURL: DefaultSchedulerAPIBaseURL,
KolkrabbiBaseURL: DefaultKolkrabbiAPIBaseURL,
SchedulerBaseURL: DefaultSchedulerAPIBaseURL,
AddonsBaseURL: DefaultAddonsAPIBaseURL,
UserAgent: DefaultUserAgent,
APIToken: "",
BasicAuth: "",
Expand All @@ -121,6 +127,7 @@ func New(opts ...config2.Option) (*Client, error) {
Registry: registry.New(config),
Kolkrabbi: kolkrabbi.New(config),
Scheduler: scheduler.New(config),
Addons: addons.New(config),
}

return client, nil
Expand Down
2 changes: 1 addition & 1 deletion api/kolkrabbi/kolkrabbi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Kolkrabbi struct {

// New constructs a client to interface with the Heroku Postgres APIs.
func New(config *config2.Config) *Kolkrabbi {
k := &Kolkrabbi{http: simpleresty.NewWithBaseURL(config.KolkrabbiURL), config: config}
k := &Kolkrabbi{http: simpleresty.NewWithBaseURL(config.KolkrabbiBaseURL), config: config}
k.setHeaders()

return k
Expand Down
11 changes: 7 additions & 4 deletions api/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ type Config struct {
// RegistryBaseURL is the base URL for the Heroku Registry.
RegistryBaseURL string

// KolkrabbiURL is the base URL for Heroku's Kolkrabbi API.
KolkrabbiURL string
// KolkrabbiBaseURL is the base URL for Heroku's Kolkrabbi API.
KolkrabbiBaseURL string

// SchedulerURL is the base URL for Heroku's Scheduler API.
SchedulerURL string
// SchedulerBaseURL is the base URL for Heroku's Scheduler API.
SchedulerBaseURL string

// AddonsBaseURL is the base URL for Heroku's Addons API.
AddonsBaseURL string

// UserAgent used when communicating with the Heroku API.
UserAgent string
Expand Down
16 changes: 14 additions & 2 deletions api/pkg/config/config_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func KolkrabbiBaseURL(url string) Option {
return err
}

c.KolkrabbiURL = url
c.KolkrabbiBaseURL = url
return nil
}
}
Expand All @@ -135,7 +135,19 @@ func SchedulerBaseURL(url string) Option {
return err
}

c.SchedulerURL = url
c.SchedulerBaseURL = url
return nil
}
}

// AddonsBaseURL allows for a custom Addons API URL.
func AddonsBaseURL(url string) Option {
return func(c *Config) error {
if err := validateBaseURLOption(url); err != nil {
return err
}

c.AddonsBaseURL = url
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Scheduler struct {

// New constructs a client to interface with the Heroku scheduler APIs.
func New(config *config.Config) *Scheduler {
s := &Scheduler{http: simpleresty.NewWithBaseURL(config.SchedulerURL), config: config}
s := &Scheduler{http: simpleresty.NewWithBaseURL(config.SchedulerBaseURL), config: config}
s.setHeaders()

return s
Expand Down