BuildSchemeData builds the scheme data for the given scheme and method expr.
(s *expr.SchemeExpr, m *expr.MethodExpr)
| 1672 | |
| 1673 | // BuildSchemeData builds the scheme data for the given scheme and method expr. |
| 1674 | func BuildSchemeData(s *expr.SchemeExpr, m *expr.MethodExpr) *SchemeData { |
| 1675 | if !expr.IsObject(m.Payload.Type) { |
| 1676 | return nil |
| 1677 | } |
| 1678 | switch s.Kind { |
| 1679 | case expr.BasicAuthKind: |
| 1680 | userAtt := expr.TaggedAttribute(m.Payload, "security:username") |
| 1681 | user := codegen.Goify(userAtt, true) |
| 1682 | passAtt := expr.TaggedAttribute(m.Payload, "security:password") |
| 1683 | pass := codegen.Goify(passAtt, true) |
| 1684 | var scopes []string |
| 1685 | if len(s.Scopes) > 0 { |
| 1686 | scopes = make([]string, len(s.Scopes)) |
| 1687 | for i, s := range s.Scopes { |
| 1688 | scopes[i] = s.Name |
| 1689 | } |
| 1690 | } |
| 1691 | return &SchemeData{ |
| 1692 | Type: s.Kind.String(), |
| 1693 | SchemeName: s.SchemeName, |
| 1694 | UsernameAttr: userAtt, |
| 1695 | UsernameField: user, |
| 1696 | UsernamePointer: m.Payload.IsPrimitivePointer(userAtt, true), |
| 1697 | UsernameRequired: m.Payload.IsRequired(userAtt), |
| 1698 | PasswordAttr: passAtt, |
| 1699 | PasswordField: pass, |
| 1700 | PasswordPointer: m.Payload.IsPrimitivePointer(passAtt, true), |
| 1701 | PasswordRequired: m.Payload.IsRequired(passAtt), |
| 1702 | Scopes: scopes, |
| 1703 | } |
| 1704 | case expr.APIKeyKind: |
| 1705 | if keyAtt := expr.TaggedAttribute(m.Payload, "security:apikey:"+s.SchemeName); keyAtt != "" { |
| 1706 | key := codegen.Goify(keyAtt, true) |
| 1707 | var scopes []string |
| 1708 | if len(s.Scopes) > 0 { |
| 1709 | scopes = make([]string, len(s.Scopes)) |
| 1710 | for i, s := range s.Scopes { |
| 1711 | scopes[i] = s.Name |
| 1712 | } |
| 1713 | } |
| 1714 | return &SchemeData{ |
| 1715 | Type: s.Kind.String(), |
| 1716 | Name: s.Name, |
| 1717 | SchemeName: s.SchemeName, |
| 1718 | CredField: key, |
| 1719 | CredPointer: m.Payload.IsPrimitivePointer(keyAtt, true), |
| 1720 | CredRequired: m.Payload.IsRequired(keyAtt), |
| 1721 | KeyAttr: keyAtt, |
| 1722 | Scopes: scopes, |
| 1723 | In: s.In, |
| 1724 | } |
| 1725 | } |
| 1726 | case expr.BearerKind: |
| 1727 | if keyAtt := expr.TaggedAttribute(m.Payload, "security:bearer"); keyAtt != "" { |
| 1728 | key := codegen.Goify(keyAtt, true) |
| 1729 | var scopes []string |
| 1730 | if len(s.Scopes) > 0 { |
| 1731 | scopes = make([]string, len(s.Scopes)) |
no test coverage detected