Skip to content
Open
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
24 changes: 24 additions & 0 deletions internal/clients/cf/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,30 @@ func (c *API) ListAccessApplicationsByName(ctx context.Context, name string) (*A
return nil, fmt.Errorf("access application not found: %s", name)
}

// ListAccessApplicationsByDomain finds an Access Application by domain.
func (c *API) ListAccessApplicationsByDomain(ctx context.Context, domain string) (*AccessApplicationResult, error) {
if _, err := c.GetAccountId(ctx); err != nil {
c.Log.Error(err, "error getting account ID")
return nil, err
}

rc := cloudflare.AccountIdentifier(c.ValidAccountId)

apps, _, err := c.CloudflareClient.ListAccessApplications(ctx, rc, cloudflare.ListAccessApplicationsParams{})
if err != nil {
c.Log.Error(err, "error listing access applications")
return nil, err
}

for _, app := range apps {
if app.Domain == domain {
return convertAccessApplicationToResult(app, c.ValidAccountId), nil
}
}

return nil, fmt.Errorf("access application not found: %s", domain)
}

// ============================================================================
// Conversion helper functions for AccessApplication
// ============================================================================
Expand Down
1 change: 1 addition & 0 deletions internal/clients/cf/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type CloudflareClient interface {
UpdateAccessApplication(ctx context.Context, applicationID string, params AccessApplicationParams) (*AccessApplicationResult, error)
DeleteAccessApplication(ctx context.Context, applicationID string) error
ListAccessApplicationsByName(ctx context.Context, name string) (*AccessApplicationResult, error)
ListAccessApplicationsByDomain(ctx context.Context, domain string) (*AccessApplicationResult, error)

// Access Policy operations
CreateAccessPolicy(ctx context.Context, params AccessPolicyParams) (*AccessPolicyResult, error)
Expand Down
45 changes: 30 additions & 15 deletions internal/clients/cf/mock/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/controller/accessapplication/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ func (r *Reconciler) reconcileApplication(
"applicationID", existing.ID)
}
} else {
// Try to find existing by name first
existing, err := apiResult.API.ListAccessApplicationsByName(ctx, appName)
// Try to find existing by domain first
existing, err := apiResult.API.ListAccessApplicationsByDomain(ctx, params.Domain)
if err == nil && existing != nil {
// Found existing, adopt it
logger.Info("Found existing AccessApplication in Cloudflare, adopting",
Expand Down