This repository was archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Handling Cloudfront deletion #309
Open
HTTP500
wants to merge
6
commits into
rename_schema_for_clarity
Choose a base branch
from
cinq_next_cfdel
base: rename_schema_for_clarity
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,6 +461,51 @@ func (r *queryResolver) ElasticbeanstalkByEndpoint(ctx context.Context, endpoint | |
| return &beanstalk, err | ||
| } | ||
|
|
||
| func (r *queryResolver) GetCloudFrontUpstreamHijack(ctx context.Context, domains []string) ([]*model.HijackableResource, error) { | ||
| hijackChain := []*model.HijackableResource{} | ||
|
|
||
| // 1. check origins | ||
| for _, domain := range domains { | ||
| origins, err := r.Query().PointedAtByOrigin(ctx, domain) | ||
| if err != nil { | ||
| log.Errorf("error looking up domain %s", domain) | ||
| continue | ||
| } | ||
|
|
||
| for _, origin := range origins { | ||
| completeOrigin, err := r.Query().Origin(ctx, origin.OriginID) | ||
| if err != nil { | ||
| log.Errorf("error looking up origin with id %v", origin.OriginID) | ||
| continue | ||
| } | ||
|
|
||
| var account model.Account | ||
| err = r.DB.First(&account, origin.OriginID).Error | ||
| if err != nil { | ||
| log.Errorf("unable to get account for origin %#v", *completeOrigin) | ||
| continue | ||
| } | ||
| hijackChain = append(hijackChain, &model.HijackableResource{ | ||
| ID: completeOrigin.OriginID, | ||
| Type: model.TypeDistribution, | ||
| Account: account.AccountID, | ||
| Value: &model.Value{ | ||
| ValueID: completeOrigin.Domain, | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| if log.GetLevel() == log.DebugLevel { | ||
| log.Debugf("found hijack chain for endpoints: %#v", domains) | ||
| for idx, chainElement := range hijackChain { | ||
| log.Debugf("%v: %#v", idx, *chainElement) | ||
| } | ||
| } | ||
|
|
||
| return hijackChain, nil | ||
| } | ||
|
|
||
| func (r *queryResolver) GetElasticbeanstalkUpstreamHijack(ctx context.Context, endpoints []string) ([]*model.HijackableResource, error) { | ||
| // elasticbeanstalks are endpoints are only fronted by other resources | ||
| hijackChain := []*model.HijackableResource{} | ||
|
|
@@ -554,6 +599,40 @@ func (r *queryResolver) GetElasticbeanstalkUpstreamHijack(ctx context.Context, e | |
|
|
||
| func (r *queryResolver) HijackChainByDomain(ctx context.Context, id string, domains []string, typeArg model.Type) (*model.HijackableResourceChain, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should have its params changed. |
||
| switch typeArg { | ||
| case model.TypeDistribution: | ||
| cf, err := r.Query().Distribution(ctx, id) | ||
| if err != nil { | ||
| log.Errorf("error getting cloudfront: %v", err.Error()) | ||
| return nil, err | ||
| } | ||
|
|
||
| var account *model.Account = nil | ||
| err = r.DB.Find(account, cf.AccountID).Error | ||
| if err != nil { | ||
| log.Errorf("unable to find account for cloudfront distribution: %#v", *cf) | ||
| return nil, err | ||
| } | ||
|
|
||
| chain, err := r.Query().GetCloudFrontUpstreamHijack(ctx, domains) | ||
| if err != nil { | ||
| log.Errorf("recieved error when querying for cloudfront distribution hijacks: %v", err.Error()) | ||
| return nil, err | ||
| } | ||
|
|
||
| return &model.HijackableResourceChain{ | ||
| ID: id, | ||
| Resource: &model.HijackableResource{ | ||
| ID: id, | ||
| Account: account.AccountID, | ||
| Type: model.TypeElasticbeanstalk, | ||
| Value: &model.Value{ | ||
| ValueID: cf.Domain, | ||
| }, | ||
| }, | ||
| Upstream: chain, | ||
| Downstream: []*model.HijackableResource{}, | ||
| }, err | ||
|
|
||
| case model.TypeElasticbeanstalk: | ||
| /* | ||
| ID string `json:"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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| ], | ||
| "eventName": [ | ||
| "CreateDistribution", | ||
| "DeleteDistribution", | ||
| "UpdateDistribution" | ||
| ] | ||
| } | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a check here to see if its possible to create a cloud front distribution with an origin that points to a resource that doesnt exist. If this is possible, we need to check for this.
Need to check here to see if it is possible to create a distro that point to a resource that exists but we dont own.
Both cases need to have analysis code.
This may just need to be its own ticket.