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

feat: add p/demo/access (administrable contracts) #880

Closed
wants to merge 27 commits into from

Conversation

moul
Copy link
Member

@moul moul commented Jun 8, 2023

A library designed to streamline the implementation of this prevalent pattern.

Exposes a privileged API (administrable.Set) that can be fully controlled by the calling contract, and an unprivileged API designed to be exported and available to other contract directly.

$ gno doc gno.land/p/demo/access
package access // import "gno.land/p/demo/access"

Package access provides a simple access control library for managing authorized
addresses and controlling resource access.

Features: authorized address management, access verification.

Note: This package is suitable for basic access control in simple use cases.
Consider specialized libraries or frameworks for advanced access control and
permission management.

TYPES

type Set struct {
	// Has unexported fields.
}
    Set is an object containing the configuration and allowing the application
    of filters. It is suited to be used as a contract-side global variable or
    can be embedded in another Go object.

func New() Set
    New returns a Set object initialized with the caller as the unique
    authorized address. It is recommended to use this function in the `init()`
    function of the calling realm.

func NewWithAddress(addr std.Address) Set
    NewWithAddress returns a Set object initialized with the provided address as
    authorized.

func (s *Set) Add(addr std.Address)
    Add adds an address to the list of authorized addresses. It requires the
    caller or prevRealm to be authorized, otherwise, it panics.

func (s *Set) AssertCurrentHasAccess()
    AssertCurrentHasAccess checks whether the std.GetOrigCaller or std.PrevRealm
    is whitelisted as authorized. If not, it panics indicating restricted
    access.

func (s *Set) CurrentHasAccess() bool
    CurrentHasAccess checks if the caller or prevRealm is authorized.

func (s *Set) Del(addr std.Address) (success bool)
    Del removes an address from the list of authorized addresses. It requires
    the caller or prevRealm to be authorized, otherwise, it panics.

func (s *Set) ForceDel(addr std.Address) (success bool)
    ForceDel removes an address from the list of authorized addresses. It won't
    panic if there is only one address. It requires the caller or prevRealm to
    be authorized, otherwise, it panics.

func (s *Set) HasAccess(addr std.Address) bool
    HasAccess checks if the provided address is in the list of authorized ones.

func (s *Set) List() []std.Address
    List returns a slice containing all the authorized addresses.

func (s *Set) ReplaceAll(addr std.Address)
    ReplaceAll removes all existing authorized addresses and replaces them with
    a new one. It requires the caller or prevRealm to be authorized, otherwise,
    it panics.

func (s Set) Unprivileged() UnprivilegedSet
    Unprivileged returns an unprivileged structure that can be securely exposed
    as object.

type UnprivilegedSet struct {
	Set
}

func (u *UnprivilegedSet) Add(addr std.Address)

func (u *UnprivilegedSet) Del(addr std.Address)

func (u *UnprivilegedSet) ForceDel(addr std.Address)

func (u *UnprivilegedSet) ReplaceAll(addr std.Address)

Related with #289

Contributors Checklist

  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests

Maintainers Checklist

  • Checked that the author followed the guidelines in CONTRIBUTING.md
  • Checked the conventional-commit (especially PR title and verb, presence of BREAKING CHANGE: in the body)
  • Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jun 8, 2023
moul added 3 commits June 8, 2023 18:22
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@moul moul mentioned this pull request Jun 8, 2023
9 tasks
moul added 6 commits June 8, 2023 20:38
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@moul moul changed the title feat: add p/demo/administrable feat: add p/demo/access Jun 8, 2023
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@moul moul marked this pull request as ready for review June 8, 2023 12:24
@moul moul requested a review from a team as a code owner June 8, 2023 12:24
moul added 2 commits June 8, 2023 21:37
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@github-actions github-actions bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Jun 8, 2023
@moul moul changed the title feat: add p/demo/access feat: add p/demo/access (administrable contracts) Jun 9, 2023
@github-actions github-actions bot removed the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Jun 20, 2023
@moul
Copy link
Member Author

moul commented Sep 26, 2023

Can someone continue this PR, please?

@moul moul marked this pull request as ready for review September 26, 2023 21:52
moul and others added 6 commits October 20, 2023 12:03
Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>
Co-authored-by: Hariom Verma <hariom18599@gmail.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7339bdc) 55.83% compared to head (57c4a1c) 48.08%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #880      +/-   ##
==========================================
- Coverage   55.83%   48.08%   -7.75%     
==========================================
  Files         435      381      -54     
  Lines       66036    64497    -1539     
==========================================
- Hits        36869    31013    -5856     
- Misses      26292    31004    +4712     
+ Partials     2875     2480     -395     
Flag Coverage Δ
go-1.21.x ∅ <ø> (∅)
misc ∅ <ø> (∅)
misc-_test.genstd ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

… imports containing an init() func

Signed-off-by: moul <94029+moul@users.noreply.github.com>
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Oct 20, 2023
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@thehowl
Copy link
Member

thehowl commented Dec 7, 2023

Can someone continue this PR, please?

@leohhhn this looks like something you might be interested in working on :)

thehowl added a commit that referenced this pull request May 9, 2024
…1965)

Cherry-picked from
8fe571f
(#880).

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: Morgan Bazalgette <morgan@morganbaz.com>
@moul moul marked this pull request as draft June 12, 2024 17:05
moul added 3 commits June 12, 2024 19:09
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul moul added the 🗺️good first issue🗺️ Ideal for newcomer contributors label Jun 12, 2024
@leohhhn leohhhn mentioned this pull request Aug 28, 2024
7 tasks
@leohhhn
Copy link
Contributor

leohhhn commented Aug 28, 2024

Continued in #2741

@leohhhn
Copy link
Contributor

leohhhn commented Sep 3, 2024

Superseded by #2741

@leohhhn leohhhn closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗺️good first issue🗺️ Ideal for newcomer contributors 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: ✅ Done
Status: 🌟 Wanted for Launch
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants