forked from opensearch-project/opensearch-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins/security: add actiongroups functions
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
- Loading branch information
Showing
6 changed files
with
470 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
|
||
package security | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v3" | ||
) | ||
|
||
// ActionGroupsDeleteReq represents possible options for the actiongroups delete request | ||
type ActionGroupsDeleteReq struct { | ||
ActionGroup string | ||
|
||
Header http.Header | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r ActionGroupsDeleteReq) GetRequest() (*http.Request, error) { | ||
return opensearch.BuildRequest( | ||
"DELETE", | ||
fmt.Sprintf("/_plugins/_security/api/actiongroups/%s", r.ActionGroup), | ||
nil, | ||
make(map[string]string), | ||
r.Header, | ||
) | ||
} | ||
|
||
// ActionGroupsDeleteResp represents the returned struct of the actiongroups delete response | ||
type ActionGroupsDeleteResp struct { | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r ActionGroupsDeleteResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} |
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,60 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
|
||
package security | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/opensearch-project/opensearch-go/v3" | ||
) | ||
|
||
// ActionGroupsGetReq represents possible options for the actiongroups get request | ||
type ActionGroupsGetReq struct { | ||
Header http.Header | ||
ActionGroup string | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r ActionGroupsGetReq) GetRequest() (*http.Request, error) { | ||
var path strings.Builder | ||
path.Grow(len("/_plugins/_security/api/actiongroups/") + len(r.ActionGroup)) | ||
path.WriteString("/_plugins/_security/api/actiongroups") | ||
if len(r.ActionGroup) > 0 { | ||
path.WriteString("/") | ||
path.WriteString(r.ActionGroup) | ||
} | ||
|
||
return opensearch.BuildRequest( | ||
"GET", | ||
path.String(), | ||
nil, | ||
make(map[string]string), | ||
r.Header, | ||
) | ||
} | ||
|
||
// ActionGroupsGetResp represents the returned struct of the actiongroups get response | ||
type ActionGroupsGetResp struct { | ||
Groups map[string]ActionGroupsGet | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r ActionGroupsGetResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} | ||
|
||
// ActionGroupsGet is a sub type of ActionGroupsGetResp represeting information about an action group | ||
type ActionGroupsGet struct { | ||
Reserved bool `json:"reserved"` | ||
Hidden bool `json:"hidden"` | ||
AllowedActions []string `json:"allowed_actions"` | ||
Static bool `json:"static"` | ||
Description string `json:"description,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
} |
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,70 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
|
||
package security | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/opensearch-project/opensearch-go/v3" | ||
) | ||
|
||
// ActionGroupsPatchReq represents possible options for the actiongroups patch request | ||
type ActionGroupsPatchReq struct { | ||
ActionGroup string | ||
Body ActionGroupsPatchBody | ||
|
||
Header http.Header | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r ActionGroupsPatchReq) GetRequest() (*http.Request, error) { | ||
body, err := json.Marshal(r.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var path strings.Builder | ||
path.Grow(len("/_plugins/_security/api/actiongroups/") + len(r.ActionGroup)) | ||
path.WriteString("/_plugins/_security/api/actiongroups") | ||
if len(r.ActionGroup) > 0 { | ||
path.WriteString("/") | ||
path.WriteString(r.ActionGroup) | ||
} | ||
|
||
return opensearch.BuildRequest( | ||
"PATCH", | ||
path.String(), | ||
bytes.NewReader(body), | ||
make(map[string]string), | ||
r.Header, | ||
) | ||
} | ||
|
||
// ActionGroupsPatchResp represents the returned struct of the actiongroups patch response | ||
type ActionGroupsPatchResp struct { | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r ActionGroupsPatchResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} | ||
|
||
// ActionGroupsPatchBody represents the request body for the action groups patch request | ||
type ActionGroupsPatchBody []ActionGroupsPatchBodyItem | ||
|
||
// ActionGroupsPatchBodyItem is a sub type of ActionGroupsPatchBody represeting an action group | ||
type ActionGroupsPatchBodyItem struct { | ||
OP string `json:"op"` | ||
Path string `json:"path"` | ||
Value any `json:"value,omitempty"` | ||
} |
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,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
|
||
package security | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v3" | ||
) | ||
|
||
// ActionGroupsPutReq represents possible options for the actiongroups put request | ||
type ActionGroupsPutReq struct { | ||
ActionGroup string | ||
Body ActionGroupsPutBody | ||
|
||
Header http.Header | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r ActionGroupsPutReq) GetRequest() (*http.Request, error) { | ||
body, err := json.Marshal(r.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return opensearch.BuildRequest( | ||
"PUT", | ||
fmt.Sprintf("/_plugins/_security/api/actiongroups/%s", r.ActionGroup), | ||
bytes.NewReader(body), | ||
make(map[string]string), | ||
r.Header, | ||
) | ||
} | ||
|
||
// ActionGroupsPutResp represents the returned struct of the actiongroups put response | ||
type ActionGroupsPutResp struct { | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r ActionGroupsPutResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} | ||
|
||
// ActionGroupsPutBody represents the request body for the action groups put request | ||
type ActionGroupsPutBody struct { | ||
AllowedActions []string `json:"allowed_actions"` | ||
Type *string `json:"type,omitempty"` | ||
Description *string `json:"description,omitempty"` | ||
} |
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,71 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
|
||
package security | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type actiongroupsClient struct { | ||
apiClient *Client | ||
} | ||
|
||
// Get executes a get actiongroups request with the optional ActionGroupsGetReq | ||
func (c actiongroupsClient) Get(ctx context.Context, req *ActionGroupsGetReq) (ActionGroupsGetResp, error) { | ||
if req == nil { | ||
req = &ActionGroupsGetReq{} | ||
} | ||
|
||
var ( | ||
data ActionGroupsGetResp | ||
err error | ||
) | ||
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { | ||
return data, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
// Put executes a put actiongroups request with the required ActionGroupsPutReq | ||
func (c actiongroupsClient) Put(ctx context.Context, req ActionGroupsPutReq) (ActionGroupsPutResp, error) { | ||
var ( | ||
data ActionGroupsPutResp | ||
err error | ||
) | ||
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { | ||
return data, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
// Delete executes a delete actiongroups request with the required ActionGroupsDeleteReq | ||
func (c actiongroupsClient) Delete(ctx context.Context, req ActionGroupsDeleteReq) (ActionGroupsDeleteResp, error) { | ||
var ( | ||
data ActionGroupsDeleteResp | ||
err error | ||
) | ||
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { | ||
return data, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
// Patch executes a patch actiongroups request with the required ActionGroupsPatchReq | ||
func (c actiongroupsClient) Patch(ctx context.Context, req ActionGroupsPatchReq) (ActionGroupsPatchResp, error) { | ||
var ( | ||
data ActionGroupsPatchResp | ||
err error | ||
) | ||
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { | ||
return data, err | ||
} | ||
|
||
return data, nil | ||
} |
Oops, something went wrong.