| 1 | package kongscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.12 context/" |
| 5 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/" |
| 6 | ) |
| 7 | |
| 8 | // MTLSAuthService handles MTLS credentials in Kong. |
| 9 | type MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService# servicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service# |
| 10 | |
| 11 | // Create creates an MTLS credential in Kong |
| 12 | // If an ID is specified, it will be used to |
| 13 | // create a MTLS in Kong, otherwise an ID |
| 14 | // is auto-generated. |
| 15 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) Createscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#Create().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#, |
| 16 | consumerUsernameOrID *string, mtlsAuth *MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#) (*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#, error) { |
| 17 | |
| 18 | cred, err := s.clientscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service#client..credentialsscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/Client#credentials..Createscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/credentialService#Create().(ctx, "mtls-auth", |
| 19 | consumerUsernameOrID, mtlsAuth) |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | |
| 24 | var createdMTLS MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 25 | err = jsonscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/Unmarshal().(cred, &createdMTLS) |
| 26 | if err != nil { |
| 27 | return nil, err |
| 28 | } |
| 29 | |
| 30 | return &createdMTLS, nil |
| 31 | } |
| 32 | |
| 33 | // Get fetches an MTLS credential from Kong. |
| 34 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) Getscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#Get().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#, |
| 35 | consumerUsernameOrID, keyOrID *string) (*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#, error) { |
| 36 | |
| 37 | cred, err := s.clientscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service#client..credentialsscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/Client#credentials..Getscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/credentialService#Get().(ctx, "mtls-auth", |
| 38 | consumerUsernameOrID, keyOrID) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | var mtlsAuth MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 44 | err = jsonscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/Unmarshal().(cred, &mtlsAuth) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | |
| 49 | return &mtlsAuth, nil |
| 50 | } |
| 51 | |
| 52 | // Update updates an MTLS credential in Kong |
| 53 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) Updatescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#Update().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#, |
| 54 | consumerUsernameOrID *string, mtlsAuth *MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#) (*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#, error) { |
| 55 | |
| 56 | cred, err := s.clientscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service#client..credentialsscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/Client#credentials..Updatescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/credentialService#Update().(ctx, "mtls-auth", |
| 57 | consumerUsernameOrID, mtlsAuth) |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | |
| 62 | var updatedMTLS MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 63 | err = jsonscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/Unmarshal().(cred, &updatedMTLS) |
| 64 | if err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | |
| 68 | return &updatedMTLS, nil |
| 69 | } |
| 70 | |
| 71 | // Delete deletes an MTLS credential in Kong |
| 72 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) Deletescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#Delete().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#, |
| 73 | consumerUsernameOrID, keyOrID *string) error { |
| 74 | return s.clientscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service#client..credentialsscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/Client#credentials..Deletescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/credentialService#Delete().(ctx, "mtls-auth", |
| 75 | consumerUsernameOrID, keyOrID) |
| 76 | } |
| 77 | |
| 78 | // List fetches a list of MTLS credentials in Kong. |
| 79 | // opt can be used to control pagination. |
| 80 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) Listscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#List().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#, |
| 81 | opt *ListOptscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ListOpt#) ([]*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#, *ListOptscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ListOpt#, error) { |
| 82 | data, next, err := s.clientscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service#client..listscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/Client#list().(ctx, "/mtls-auths", opt) |
| 83 | if err != nil { |
| 84 | return nil, nil, err |
| 85 | } |
| 86 | var mtlss []*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 87 | for _, object := range data { |
| 88 | b, err := object.MarshalJSONscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/RawMessage#MarshalJSON().() |
| 89 | if err != nil { |
| 90 | return nil, nil, err |
| 91 | } |
| 92 | var mtlsAuth MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 93 | err = jsonscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/Unmarshal().(b, &mtlsAuth) |
| 94 | if err != nil { |
| 95 | return nil, nil, err |
| 96 | } |
| 97 | mtlss = append(mtlss, &mtlsAuth) |
| 98 | } |
| 99 | |
| 100 | return mtlss, next, nil |
| 101 | } |
| 102 | |
| 103 | // ListAll fetches all MTLS credentials in Kong. |
| 104 | // This method can take a while if there |
| 105 | // a lot of MTLS credentials present. |
| 106 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) ListAllscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#ListAll().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#) ([]*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#, error) { |
| 107 | var mtlss, data []*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 108 | var err error |
| 109 | opt := &ListOptscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ListOpt#{Sizescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ListOpt#Size.: pageSizescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/pageSize.} |
| 110 | |
| 111 | for opt != nil { |
| 112 | data, opt, err = s.Listscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#List().(ctx, opt) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | mtlss = append(mtlss, data...) |
| 117 | } |
| 118 | return mtlss, nil |
| 119 | } |
| 120 | |
| 121 | // ListForConsumer fetches a list of mtls credentials |
| 122 | // in Kong associated with a specific consumer. |
| 123 | // opt can be used to control pagination. |
| 124 | func (s *MTLSAuthServicescip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#) ListForConsumerscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuthService#ListForConsumer().(ctx contextscip-go gomod github.com/golang/go/src go1.12 context/.Contextscip-go gomod github.com/golang/go/src go1.12 context/Context#, |
| 125 | consumerUsernameOrID *string, opt *ListOptscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ListOpt#) ([]*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth#, *ListOptscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/ListOpt#, error) { |
| 126 | data, next, err := s.clientscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/service#client..listscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/Client#list().(ctx, |
| 127 | "/consumers/"+*consumerUsernameOrID+"/mtls-auth", opt) |
| 128 | if err != nil { |
| 129 | return nil, nil, err |
| 130 | } |
| 131 | var mtlss []*MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 132 | for _, object := range data { |
| 133 | b, err := object.MarshalJSONscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/RawMessage#MarshalJSON().() |
| 134 | if err != nil { |
| 135 | return nil, nil, err |
| 136 | } |
| 137 | var mtlsAuth MTLSAuthscip-go gomod github.com/kong/go-kong . `github.com/kong/go-kong/kong`/MTLSAuth# |
| 138 | err = jsonscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.12 `encoding/json`/Unmarshal().(b, &mtlsAuth) |
| 139 | if err != nil { |
| 140 | return nil, nil, err |
| 141 | } |
| 142 | mtlss = append(mtlss, &mtlsAuth) |
| 143 | } |
| 144 | |
| 145 | return mtlss, next, nil |
| 146 | } |