-
Notifications
You must be signed in to change notification settings - Fork 52
feat(zone): add Zone resource for Secure #609
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
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
16f8e08
add Zone resource for Secure
vojindj b03759d
Merge branch 'master' into SP-4514
vojindj 9025bc7
remove ZoneWrapper | change Scopes schema
vojindj a55d033
fix acceptance test
vojindj 2cbb077
add documentation
vojindj f532bcb
convert `last_updated` to date (string) from timestamp
vojindj 989112d
upgrade actions/cache v2 -> v4
vojindj ce36a85
fix acc test
vojindj 5f159e2
add Importer to resource schema
vojindj b2e0c9e
refactor: rename method
vojindj d98d67f
Merge branch 'master' of github.com:sysdiglabs/terraform-provider-sys…
vojindj a0d3b26
refactor: rename variables
vojindj d9d8142
make `scopes` required in terraform config and add `id` field to `scope`
vojindj 8ef00e4
simplify zone TF schema: remove `scopes` field
vojindj 8b0d812
add all computed fields to documentation
vojindj 2fa35ef
set scopes properly when updating the state
vojindj 14bb324
Merge branch 'master' of github.com:sysdiglabs/terraform-provider-sys…
vojindj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,121 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
ZonesPath = "%s/platform/v1/zones" | ||
ZonePath = "%s/platform/v1/zones/%d" | ||
) | ||
|
||
type ZoneInterface interface { | ||
Base | ||
GetZones(ctx context.Context) ([]Zone, error) | ||
GetZoneById(ctx context.Context, id int) (*Zone, error) | ||
CreateZone(ctx context.Context, zone *ZoneRequest) (*Zone, error) | ||
UpdateZone(ctx context.Context, zone *ZoneRequest) (*Zone, error) | ||
DeleteZone(ctx context.Context, id int) error | ||
} | ||
|
||
func (client *Client) GetZones(ctx context.Context) ([]Zone, error) { | ||
response, err := client.requester.Request(ctx, http.MethodGet, client.getZonesURL(), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
wrapper, err := Unmarshal[ZonesWrapper](response.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return wrapper.Zones, nil | ||
} | ||
|
||
func (client *Client) GetZoneById(ctx context.Context, id int) (*Zone, error) { | ||
response, err := client.requester.Request(ctx, http.MethodGet, client.getZoneURL(id), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
zone, err := Unmarshal[Zone](response.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &zone, nil | ||
} | ||
|
||
func (client *Client) CreateZone(ctx context.Context, zone *ZoneRequest) (*Zone, error) { | ||
payload, err := Marshal(zone) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := client.requester.Request(ctx, http.MethodPost, client.getZonesURL(), payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { | ||
return nil, client.ErrorFromResponse(response) | ||
} | ||
|
||
createdZone, err := Unmarshal[Zone](response.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &createdZone, nil | ||
} | ||
|
||
func (client *Client) UpdateZone(ctx context.Context, zone *ZoneRequest) (*Zone, error) { | ||
payload, err := Marshal(zone) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := client.requester.Request(ctx, http.MethodPut, client.getZoneURL(zone.ID), payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { | ||
return nil, client.ErrorFromResponse(response) | ||
} | ||
|
||
updatedZone, err := Unmarshal[Zone](response.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &updatedZone, nil | ||
} | ||
|
||
func (client *Client) DeleteZone(ctx context.Context, id int) error { | ||
response, err := client.requester.Request(ctx, http.MethodDelete, client.getZoneURL(id), nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusNoContent && response.StatusCode != http.StatusOK && response.StatusCode != http.StatusNotFound { | ||
return client.ErrorFromResponse(response) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (client *Client) getZonesURL() string { | ||
return fmt.Sprintf(ZonesPath, client.config.url) | ||
} | ||
|
||
func (client *Client) getZoneURL(id int) string { | ||
return fmt.Sprintf(ZonePath, client.config.url, id) | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.