generated from davidji99/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement new resource: asana_project * add env variables to tests.yml * generate accessors
- Loading branch information
Showing
23 changed files
with
1,196 additions
and
148 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
package api | ||
|
||
// InputOutputOpts represents the options available for POST or PUT request | ||
// or when the `application/json` content type. | ||
type InputOutputOpts struct { | ||
// Provides “pretty” output. | ||
Pretty bool `json:"opt_pretty"` | ||
|
||
// Defines fields to return. | ||
Fields []string `json:"opt_fields"` | ||
} |
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,28 @@ | ||
package api | ||
|
||
// InputOutputParams specify query parameters to control how your request is interpreted and how the response is generated. | ||
// This struct is used for any GET requests or any PUT/POST requests that use the | ||
// `application/x-www-form-urlencoded` content type. | ||
// | ||
// Reference: https://developers.asana.com/docs/input-output-options | ||
type InputOutputParams struct { | ||
// Provides the response in "pretty" output. In the case of JSON this means doing proper line breaking | ||
// and indentation to make it readable. This will take extra time and increase the response size | ||
// so it is advisable only to use this during debugging. | ||
Pretty bool `url:"opt_pretty"` | ||
|
||
// Some requests return compact representations of objects, to conserve resources and complete | ||
// the request more efficiently. Other times requests return more information than you may need. | ||
// This option allows you to list the exact set of fields that the API should be sure to return for the objects. | ||
// The field names should be provided as paths, described below. | ||
Fields []string `url:"opt_fields"` | ||
} | ||
|
||
// ListParams represents the query parameters available to most (if not all) list methods. | ||
type ListParams struct { | ||
// Results per page. | ||
Limit int `url:"opt_fields"` | ||
|
||
// Offset token. | ||
Offset string `url:"offset"` | ||
} |
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,58 @@ | ||
package asana | ||
|
||
import ( | ||
"fmt" | ||
"github.com/davidji99/terraform-provider-asana/api" | ||
"github.com/davidji99/terraform-provider-asana/version" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"log" | ||
) | ||
|
||
var ( | ||
UserAgent = fmt.Sprintf("terraform-provider-herokux/v%s", version.ProviderVersion) | ||
) | ||
|
||
type Config struct { | ||
API *api.Client | ||
Headers map[string]string | ||
acessToken string | ||
baseURL string | ||
} | ||
|
||
func NewConfig() *Config { | ||
return &Config{} | ||
} | ||
|
||
func (c *Config) initializeAPI() error { | ||
// Initialize the custom API client for non Heroku Platform APIs | ||
api, clientInitErr := api.New( | ||
api.AccessToken(c.acessToken), api.CustomHTTPHeaders(c.Headers), | ||
api.UserAgent(UserAgent), api.BaseURL(c.baseURL)) | ||
if clientInitErr != nil { | ||
return clientInitErr | ||
} | ||
c.API = api | ||
|
||
log.Printf("[INFO] Asana Client configured") | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) applySchema(d *schema.ResourceData) (err error) { | ||
if v, ok := d.GetOk("headers"); ok { | ||
headersRaw := v.(map[string]interface{}) | ||
h := make(map[string]string) | ||
|
||
for k, v := range headersRaw { | ||
h[k] = fmt.Sprintf("%v", v) | ||
} | ||
|
||
c.Headers = h | ||
} | ||
|
||
if v, ok := d.GetOk("url"); ok { | ||
c.baseURL = v.(string) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.