From 1be8030dcdc5244af8db0679eed9d308162678fe Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 29 Jun 2021 15:24:44 +0300 Subject: [PATCH] [#71] Supported json file rules in authmate Signed-off-by: Denis Kirillov --- README.md | 4 ++-- cmd/authmate/main.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4c3719c..64a3f896 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ Creation of the bearer token is mandatory, and creation of the session token is optional. If you want to add the session token you need to add a parameter `create-session-token`. -Rules for bearer token can be set via param `bearer-rules`, if it is not set, +Rules for bearer token can be set via param `bearer-rules` (json-string and file path allowed), if it is not set, it will be auto-generated with values: ``` @@ -268,7 +268,7 @@ it will be auto-generated with values: } ``` -Rules for session token can be set via param `session-rules`, default value is: +Rules for session token can be set via param `session-rules` (json-string and file path allowed), default value is: ``` { "verb": "PUT", diff --git a/cmd/authmate/main.go b/cmd/authmate/main.go index d557fc24..7e46c4c4 100644 --- a/cmd/authmate/main.go +++ b/cmd/authmate/main.go @@ -246,8 +246,8 @@ func issueSecret() *cli.Command { ContainerFriendlyName: containerFriendlyName, NeoFSKey: key, GatesPublicKeys: gatesPublicKeys, - EACLRules: []byte(eaclRulesFlag), - ContextRules: []byte(contextRulesFlag), + EACLRules: getJSONRules(eaclRulesFlag), + ContextRules: getJSONRules(contextRulesFlag), SessionTkn: sessionTokenFlag, Lifetime: lifetimeFlag, } @@ -261,6 +261,14 @@ func issueSecret() *cli.Command { } } +func getJSONRules(val string) []byte { + if data, err := os.ReadFile(val); err == nil { + return data + } + + return []byte(val) +} + func obtainSecret() *cli.Command { command := &cli.Command{ Name: "obtain-secret",