diff options
| author | chrislu <chris.lu@gmail.com> | 2025-12-14 16:08:56 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2025-12-14 16:08:56 -0800 |
| commit | f734b2d4bf154b372d382283a8ef09fe1c808154 (patch) | |
| tree | 85d2e06d14257051a3e57da1d6ee773a401113fe /weed/iam/constants.go | |
| parent | f41925b60bd066048217a6de23185a6e6cfb75a7 (diff) | |
| download | seaweedfs-f734b2d4bf154b372d382283a8ef09fe1c808154.tar.xz seaweedfs-f734b2d4bf154b372d382283a8ef09fe1c808154.zip | |
Refactor: Extract common IAM logic into shared weed/iam package (#7747)
This resolves GitHub issue #7747 by extracting duplicated IAM code into
a shared package that both the embedded S3 IAM and standalone IAM use.
New shared package (weed/iam/):
- constants.go: Common constants (charsets, action strings, error messages)
- helpers.go: Shared helper functions (Hash, GenerateRandomString,
GenerateAccessKeyId, GenerateSecretAccessKey, StringSlicesEqual,
MapToStatementAction, MapToIdentitiesAction, MaskAccessKey)
- responses.go: Common IAM response structs (CommonResponse, ListUsersResponse,
CreateUserResponse, etc.)
- helpers_test.go: Unit tests for shared helpers
Updated files:
- weed/s3api/s3api_embedded_iam.go: Use type aliases and function wrappers
to the shared package, removing ~200 lines of duplicated code
- weed/iamapi/iamapi_management_handlers.go: Use shared package for constants
and helper functions, removing ~100 lines of duplicated code
- weed/iamapi/iamapi_response.go: Re-export types from shared package for
backwards compatibility
Benefits:
- Single source of truth for IAM constants and helpers
- Easier maintenance - changes only need to be made in one place
- Reduced risk of inconsistencies between embedded and standalone IAM
- Better test coverage through shared test suite
Diffstat (limited to 'weed/iam/constants.go')
| -rw-r--r-- | weed/iam/constants.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/weed/iam/constants.go b/weed/iam/constants.go new file mode 100644 index 000000000..0b857a896 --- /dev/null +++ b/weed/iam/constants.go @@ -0,0 +1,32 @@ +package iam + +// Character sets for credential generation +const ( + CharsetUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + Charset = CharsetUpper + "abcdefghijklmnopqrstuvwxyz/" +) + +// Policy document version +const PolicyDocumentVersion = "2012-10-17" + +// Error message templates +const UserDoesNotExist = "the user with name %s cannot be found." + +// Statement action constants - these map to IAM policy actions +const ( + StatementActionAdmin = "*" + StatementActionWrite = "Put*" + StatementActionWriteAcp = "PutBucketAcl" + StatementActionRead = "Get*" + StatementActionReadAcp = "GetBucketAcl" + StatementActionList = "List*" + StatementActionTagging = "Tagging*" + StatementActionDelete = "DeleteBucket*" +) + +// Access key lengths +const ( + AccessKeyIdLength = 21 + SecretAccessKeyLength = 42 +) + |
