-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(models): add
validate
cmd that accepts a json model & validate…
…s it
- Loading branch information
Showing
5 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright © 2023 OpenFGA | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package models | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/openfga/openfga/pkg/typesystem" | ||
"github.com/spf13/cobra" | ||
openfgapb "go.buf.build/openfga/go/openfga/api/openfga/v1" | ||
) | ||
|
||
// validateCmd represents the get command. | ||
var validateCmd = &cobra.Command{ | ||
Use: "validate", | ||
Short: "Validates an authorization model", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
model := &openfgapb.AuthorizationModel{} | ||
err := json.Unmarshal([]byte(args[0]), &model) | ||
if err != nil { | ||
fmt.Printf("Failed to parse input due to %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
_, err = typesystem.NewAndValidate(model) | ||
|
||
if err != nil { | ||
fmt.Printf("Model is INVALID. Error = %v", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("Model is VALID.") | ||
}, | ||
} | ||
|
||
func init() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.