MCPcopy
hub / github.com/dgraph-io/dgraph / validate

Method validate

graphql/authorization/auth.go:65–107  ·  view source on GitHub ↗

Validate required fields.

()

Source from the content-addressed store, hash-verified

63
64// Validate required fields.
65func (a *AuthMeta) validate() error {
66 var fields string
67
68 // If JWKUrl/JWKUrls is provided, we don't expect (VerificationKey, Algo),
69 // they are needed only if JWKUrl/JWKUrls is not present there.
70 if len(a.JWKUrls) != 0 || a.JWKUrl != "" {
71
72 // User cannot provide both JWKUrl and JWKUrls.
73 if len(a.JWKUrls) != 0 && a.JWKUrl != "" {
74 return fmt.Errorf("expecting either JWKUrl or JWKUrls, both were given")
75 }
76
77 if a.VerificationKey != "" || a.Algo != "" {
78 return fmt.Errorf("expecting either JWKUrl/JWKUrls or (VerificationKey, Algo), both were given")
79 }
80
81 // Audience should be a required field if JWKUrl is provided.
82 if len(a.Audience) == 0 {
83 fields = " `Audience` "
84 }
85 } else {
86 if a.VerificationKey == "" {
87 fields = " `Verification key`/`JWKUrl`/`JWKUrls`"
88 }
89
90 if a.Algo == "" {
91 fields += " `Algo`"
92 }
93 }
94
95 if a.Header == "" {
96 fields += " `Header`"
97 }
98
99 if a.Namespace == "" {
100 fields += " `Namespace`"
101 }
102
103 if len(fields) > 0 {
104 return fmt.Errorf("required field missing in Dgraph.Authorization:%s", fields)
105 }
106 return nil
107}
108
109func Parse(schema string) (*AuthMeta, error) {
110 var meta AuthMeta

Callers 1

ParseFunction · 0.95

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected