{"id":18396812,"url":"https://github.com/bartventer/casbin-go-cloud-adapter","last_synced_at":"2025-04-07T04:32:46.238Z","repository":{"id":211903333,"uuid":"730222448","full_name":"bartventer/casbin-go-cloud-adapter","owner":"bartventer","description":"Casbin adapter for Go Cloud Development Kit usage","archived":false,"fork":false,"pushed_at":"2024-12-02T17:55:23.000Z","size":305,"stargazers_count":3,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T13:23:11.998Z","etag":null,"topics":["adapter","aws","azure","casbin","cosmos-db","dynamodb","firestore","go","go-cloud","google-cloud","mongodb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bartventer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-11T13:13:44.000Z","updated_at":"2024-10-14T09:45:00.000Z","dependencies_parsed_at":"2023-12-16T00:13:29.744Z","dependency_job_id":"e5ac33b9-e291-4d3f-ad2b-3157a2958be4","html_url":"https://github.com/bartventer/casbin-go-cloud-adapter","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.125,"last_synced_commit":"ac19084a8c98f19d3d5509a11ddd0fa9de7a2939"},"previous_names":["bartventer/casbin-go-cloud-adapter"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fcasbin-go-cloud-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fcasbin-go-cloud-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fcasbin-go-cloud-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fcasbin-go-cloud-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bartventer","download_url":"https://codeload.github.com/bartventer/casbin-go-cloud-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595083,"owners_count":20963939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adapter","aws","azure","casbin","cosmos-db","dynamodb","firestore","go","go-cloud","google-cloud","mongodb"],"created_at":"2024-11-06T02:14:56.955Z","updated_at":"2025-04-07T04:32:45.821Z","avatar_url":"https://github.com/bartventer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Casbin Go Cloud Development kit based Adapter\n[![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/casbin-go-cloud-adapter.svg)](https://pkg.go.dev/github.com/bartventer/casbin-go-cloud-adapter)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bartventer/casbin-go-cloud-adapter)](https://goreportcard.com/report/github.com/bartventer/casbin-go-cloud-adapter)\n[![Coverage Status](https://coveralls.io/repos/github/bartventer/casbin-go-cloud-adapter/badge.svg?branch=master)](https://coveralls.io/github/bartventer/casbin-go-cloud-adapter?branch=master)\n[![CI](https://github.com/bartventer/casbin-go-cloud-adapter/actions/workflows/default.yml/badge.svg)](https://github.com/bartventer/casbin-go-cloud-adapter/actions/workflows/default.yml)\n[![Release](https://img.shields.io/github/release/bartventer/casbin-go-cloud-adapter.svg)](https://github.com/bartventer/casbin-go-cloud-adapter/releases/latest)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fbartventer%2Fcasbin-go-cloud-adapter.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fbartventer%2Fcasbin-go-cloud-adapter?ref=badge_shield)\n\n[Casbin](https://github.com/casbin/casbin) Adapter built on top of [gocloud.dev](https://gocloud.dev/).\n\n## Installation\n\n```\ngo get github.com/bartventer/casbin-go-cloud-adapter\n```\n\n## Usage\n\nConfiguration is slightly different for each provider as it needs to get different settings from environment. You can read more about URLs and configuration here: https://gocloud.dev/concepts/urls/.\n\nSupported providers:\n- [Google Cloud Firestore](https://cloud.google.com/firestore/)\n- [Amazon DynamoDB](https://aws.amazon.com/dynamodb/)\n- [Azure Cosmos DB](https://learn.microsoft.com/en-us/azure/cosmos-db/)\n- [MongoDB](https://mongodb.org/)\n- In-Memory Document Store (useful for local testing and single node installs)\n\nYou can view provider configuration examples here: https://github.com/google/go-cloud/tree/master/docstore.\n\n### Google Cloud Firestore\n\nFirestore URLs provide the project and collection, as well as the field that holds the document name (e.g. `firestore://projects/my-project/databases/(default)/documents/my-collection?name_field=userID`).\n\n`casbin-go-cloud-adapter` will use Application Default Credentials; if you have authenticated via [gcloud auth application-default login](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login), it will use those credentials. See [Application Default Credentials](https://cloud.google.com/docs/authentication#service-accounts) to learn about authentication alternatives, including using environment variables.\n\n```go\nimport (\n\t\"context\"\n\tcloudadapter \"github.com/bartventer/casbin-go-cloud-adapter\"\n\t// Enable Firestore driver\n\t_ \"github.com/bartventer/casbin-go-cloud-adapter/drivers/gcpfirestore\"\n\t\n\t\"github.com/casbin/casbin/v2\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\turl := \"firestore://projects/casbin-project/databases/(default)/documents/casbin_rule?name_field=id\"\n\ta, err := cloudadapter.New(ctx, url)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\te, err := casbin.NewEnforcer(\"model.conf\", a)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Load the policy from DB.\n\te.LoadPolicy()\n\n\t// Check the permission.\n\te.Enforce(\"alice\", \"data1\", \"read\")\n\n\t// Modify the policy.\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\n\t// Save the policy back to DB.\n\te.SavePolicy()\n}\n```\n\n### Amazon DynamoDB\n\nDynamoDB URLs provide the table, partition key field and optionally the sort key field for the collection (e.g. `dynamodb://my-table?partition_key=name`).\n\n`casbin-go-cloud-adapter` will create a default AWS Session with the SharedConfigEnable option enabled; if you have authenticated with the AWS CLI, it will use those credentials. See [AWS Session](https://docs.aws.amazon.com/sdk-for-go/api/aws/session/) to learn about authentication alternatives, including using environment variables.\n\n```go\nimport (\n\t\"context\"\n\tcloudadapter \"github.com/bartventer/casbin-go-cloud-adapter\"\n\t// Enable DynamoDB driver\n\t_ \"github.com/bartventer/casbin-go-cloud-adapter/drivers/awsdynamodb\"\n\t\n\t\"github.com/casbin/casbin/v2\"\n)\t\n\nfunc main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\turl := \"dynamodb://casbin_test?partition_key=id\"\n\ta, err := cloudadapter.New(ctx, url)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\te, err := casbin.NewEnforcer(\"model.conf\", a)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Load the policy from DB.\n\te.LoadPolicy()\n\n\t// Check the permission.\n\te.Enforce(\"alice\", \"data1\", \"read\")\n\n\t// Modify the policy.\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\n\t// Save the policy back to DB.\n\te.SavePolicy()\n}\n```\n\n### Azure Cosmos DB\n\nAzure Cosmos DB is compatible with the MongoDB API. You can use the `mongodocstore` package to connect to Cosmos DB. You must create an Azure Cosmos account and get the MongoDB connection string.\n\nWhen you use MongoDB URLs to connect to Cosmos DB, specify the Mongo server URL by setting the `MONGO_SERVER_URL` environment variable to the connection string. See the [MongoDB section](#mongodb) for more details and examples on how to use the package.\n\n\n### MongoDB\n\nMongoDB URLs provide the database and collection, and optionally the field that holds the document ID (e.g. `mongo://my-db/my-collection?id_field=userID`). Specify the Mongo server URL by setting the `MONGO_SERVER_URL` environment variable.\n\n```go\nimport (\n\t\"context\"\n\tcloudadapter \"github.com/bartventer/casbin-go-cloud-adapter\"\n\t// Enable MongoDB driver\n\t_ \"github.com/bartventer/casbin-go-cloud-adapter/drivers/mongodocstore\"\n\t\n\t\"github.com/casbin/casbin/v2\"\n)\n\nfunc main() {\n\t// Set the MONGO_SERVER_URL environment variable to the MongoDB connection string.\n\tos.Setenv(\"MONGO_SERVER_URL\", \"mongodb://localhost:27017\")\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\turl := \"mongo://casbin_test/casbin_rule?id_field=id\"\n\ta, err := cloudadapter.New(ctx, url)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\te, err := casbin.NewEnforcer(\"model.conf\", a)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Load the policy from DB.\n\te.LoadPolicy()\n\n\t// Check the permission.\n\te.Enforce(\"alice\", \"data1\", \"read\")\n\n\t// Modify the policy.\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\n\t// Save the policy back to DB.\n\te.SavePolicy()\n}\n```\n\n### In Memory\n\nURLs for the in-memory store have a mem: scheme. The URL host is used as the the collection name, and the URL path is used as the name of the document field to use as a primary key (e.g. `mem://collection/keyField`).\n\n```go\nimport (\n\t\"context\"\n\tcloudadapter \"github.com/bartventer/casbin-go-cloud-adapter\"\n\t// Enable in-memory driver\n\t_ \"github.com/bartventer/casbin-go-cloud-adapter/drivers/memdocstore\"\n\t\n\t\"github.com/casbin/casbin/v2\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\turl := \"mem://casbin_rule/id\"\n\ta, err := cloudadapter.New(ctx, url)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\te, err := casbin.NewEnforcer(\"model.conf\", a)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Load the policy from DB.\n\te.LoadPolicy()\n\n\t// Check the permission.\n\te.Enforce(\"alice\", \"data1\", \"read\")\n\n\t// Modify the policy.\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\n\t// Save the policy back to DB.\n\te.SavePolicy()\n}\n```\n\n\n## About Go Cloud Dev\n\nPortable Cloud APIs in Go. Strives to implement these APIs for the leading Cloud providers: AWS, GCP and Azure, as well as provide a local (on-prem) implementation such as MongoDB, In-Memory, etc.\n\nUsing the Go CDK you can write your application code once using these idiomatic APIs, test locally using the local versions, and then deploy to a cloud provider with only minimal setup-time changes.\n\n## Further Reading\n\n- [Go CDK](https://gocloud.dev/): For more information on the Go CDK\n- [Go CDK Docstore](https://gocloud.dev/howto/docstore/): For more information on the Go CDK Docstore package\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fbartventer%2Fcasbin-go-cloud-adapter.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fbartventer%2Fcasbin-go-cloud-adapter?ref=badge_large)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartventer%2Fcasbin-go-cloud-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbartventer%2Fcasbin-go-cloud-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartventer%2Fcasbin-go-cloud-adapter/lists"}