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

Policy REST API #3302

Merged
merged 16 commits into from
Sep 15, 2021
Merged

Policy REST API #3302

merged 16 commits into from
Sep 15, 2021

Conversation

joshblakeley
Copy link
Member

Description

This PR creates a way to manage policies in Tyk CE using a REST API instead of the single file approach currently. It makes policies act in very much the same way as API when using CE. A directory is specified in the Tyk config in the new policies.policy_path field. Policies are then stored in that folder with their ID as a filename i.e. default-policy.json. CRUD operations can be carried out by calling {GATEWAYHOST}:{PORT}/tyk/policies endpoint with the policy ID passed in the last part of Path.

Related Issue

Fixes #2379

Motivation and Context

Means simpler way of managing policies - also unblocks development of Kubernetes Operator for the OSS Gateway.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
    • If new config option added, ensure that it can be set via ENV variable
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • When updating library version must provide reason/explanation for this update.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

Copy link
Contributor

@gernest gernest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I left a few comments. After they are addressed I will take another look.

gateway/api.go Outdated Show resolved Hide resolved
gateway/api.go Show resolved Hide resolved
gateway/api.go Outdated Show resolved Hide resolved
gateway/api.go Show resolved Hide resolved
gateway/api.go Outdated Show resolved Hide resolved
gateway/api.go Outdated Show resolved Hide resolved
gateway/policy.go Outdated Show resolved Hide resolved
@joshblakeley
Copy link
Member Author

Thanks for the review @gernest. Have made suggested changes.

Copy link
Contributor

@gernest gernest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left another comment. We also need tests to cover all the cases.

gateway/server.go Outdated Show resolved Hide resolved
Copy link
Member

@buger buger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix Linter and CI in general and looks solid 👍🏻

@TykTechnologies TykTechnologies deleted a comment from github-actions bot Sep 9, 2021
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Sep 9, 2021
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Sep 10, 2021
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Sep 13, 2021
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Sep 13, 2021
@@ -85,7 +85,8 @@ type PoliciesConfig struct {
// If you set this value to `true`, then the id parameter in a stored policy (or imported policy using the Dashboard API), will be used instead of the internal ID.
//
// This option should only be used when moving an installation to a new database.
AllowExplicitPolicyID bool `json:"allow_explicit_policy_id"`
AllowExplicitPolicyID bool `json:"allow_explicit_policy_id"`
PolicyPath string `json:"policy_path"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not forget adding a comment to all fields, since it will be used to auto-generate docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh didn't know that, adding it

Copy link
Member

@buger buger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment for PolicyPath option, otherwise looks good!

@vaske vaske merged commit bc5243e into master Sep 15, 2021
@vaske vaske deleted the policy-restapi branch September 15, 2021 07:50
vaske added a commit that referenced this pull request Jan 18, 2022
* REST API for policies

* amend logs in policy loader

* handler for path param

* fix path load

* resolve review issues

* tests for handler and cleanup - actually add policy to map when creating

* update mutex

Co-authored-by: Geofrey Ernest <geofreyernest@live.com>

* Fixed retrieving a single Policy (#3315)

Fixes retrieving single policy

* fixed issues after rebase

* fixed test lint issues

* ts.run checked

* code cleanup

* fixed schema model

* fixed failing tests for policies

* added comments for docs

Co-authored-by: Geofrey Ernest <geofreyernest@live.com>
Co-authored-by: Sedky Abou-Shamalah <sedkyaboushamalah@gmail.com>
Co-authored-by: Milan Vasic <milan.vasic.su@gmail.com>
# Conflicts:
#	gateway/api.go
@vaske
Copy link
Contributor

vaske commented Jan 18, 2022

merged manually to release-4-lts

furkansenharputlu added a commit that referenced this pull request Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TT-2392] - Extend the REST API to provide policy management
5 participants