createapikey

package
v9.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Create an API key.

Create an API key for access without requiring basic authentication.

IMPORTANT: If the credential that is used to authenticate this request is an API key, the derived API key cannot have any privileges. If you specify privileges, the API returns an error.

A successful request returns a JSON structure that contains the API key, its unique id, and its name. If applicable, it also returns expiration information for the API key in milliseconds.

NOTE: By default, API keys never expire. You can specify expiration information when you create the API keys.

The API keys are created by the Elasticsearch API key service, which is automatically enabled. To configure or turn off the API key service, refer to API key service setting documentation.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildPath = errors.New("cannot build path, check for missing path parameters")

ErrBuildPath is returned in case of missing parameters within the build of the request.

Functions

This section is empty.

Types

type CreateApiKey

type CreateApiKey struct {
	// contains filtered or unexported fields
}

func New

Create an API key.

Create an API key for access without requiring basic authentication.

IMPORTANT: If the credential that is used to authenticate this request is an API key, the derived API key cannot have any privileges. If you specify privileges, the API returns an error.

A successful request returns a JSON structure that contains the API key, its unique id, and its name. If applicable, it also returns expiration information for the API key in milliseconds.

NOTE: By default, API keys never expire. You can specify expiration information when you create the API keys.

The API keys are created by the Elasticsearch API key service, which is automatically enabled. To configure or turn off the API key service, refer to API key service setting documentation.

https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-security-create-api-key

func (*CreateApiKey) AddRoleDescriptor

func (r *CreateApiKey) AddRoleDescriptor(key string, value types.RoleDescriptorVariant) *CreateApiKey

func (CreateApiKey) Do

func (r CreateApiKey) Do(providedCtx context.Context) (*Response, error)

Do runs the request through the transport, handle the response and returns a createapikey.Response

func (*CreateApiKey) ErrorTrace

func (r *CreateApiKey) ErrorTrace(errortrace bool) *CreateApiKey

ErrorTrace When set to `true` Elasticsearch will include the full stack trace of errors when they occur. API name: error_trace

func (*CreateApiKey) Expiration

func (r *CreateApiKey) Expiration(duration types.DurationVariant) *CreateApiKey

The expiration time for the API key. By default, API keys never expire. API name: expiration

func (*CreateApiKey) FilterPath

func (r *CreateApiKey) FilterPath(filterpaths ...string) *CreateApiKey

FilterPath Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch. API name: filter_path

func (*CreateApiKey) Header

func (r *CreateApiKey) Header(key, value string) *CreateApiKey

Header set a key, value pair in the CreateApiKey headers map.

func (*CreateApiKey) HttpRequest

func (r *CreateApiKey) HttpRequest(ctx context.Context) (*http.Request, error)

HttpRequest returns the http.Request object built from the given parameters.

func (*CreateApiKey) Human

func (r *CreateApiKey) Human(human bool) *CreateApiKey

Human When set to `true` will return statistics in a format suitable for humans. For example `"exists_time": "1h"` for humans and `"eixsts_time_in_millis": 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines. API name: human

func (*CreateApiKey) Metadata

func (r *CreateApiKey) Metadata(metadata types.MetadataVariant) *CreateApiKey

Arbitrary metadata that you want to associate with the API key. It supports nested data structure. Within the metadata object, keys beginning with `_` are reserved for system usage. API name: metadata

func (*CreateApiKey) Name

func (r *CreateApiKey) Name(name string) *CreateApiKey

A name for the API key. API name: name

func (CreateApiKey) Perform

func (r CreateApiKey) Perform(providedCtx context.Context) (*http.Response, error)

Perform runs the http.Request through the provided transport and returns an http.Response.

func (*CreateApiKey) Pretty

func (r *CreateApiKey) Pretty(pretty bool) *CreateApiKey

Pretty If set to `true` the returned JSON will be "pretty-formatted". Only use this option for debugging only. API name: pretty

func (*CreateApiKey) Raw

func (r *CreateApiKey) Raw(raw io.Reader) *CreateApiKey

Raw takes a json payload as input which is then passed to the http.Request If specified Raw takes precedence on Request method.

func (*CreateApiKey) Refresh

func (r *CreateApiKey) Refresh(refresh refresh.Refresh) *CreateApiKey

Refresh If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. API name: refresh

func (*CreateApiKey) Request

func (r *CreateApiKey) Request(req *Request) *CreateApiKey

Request allows to set the request property with the appropriate payload.

func (*CreateApiKey) RoleDescriptors

func (r *CreateApiKey) RoleDescriptors(roledescriptors map[string]types.RoleDescriptor) *CreateApiKey

An array of role descriptors for this API key. When it is not specified or it is an empty array, the API key will have a point in time snapshot of permissions of the authenticated user. If you supply role descriptors, the resultant permissions are an intersection of API keys permissions and the authenticated user's permissions thereby limiting the access scope for API keys. The structure of role descriptor is the same as the request for the create role API. For more details, refer to the create or update roles API.

NOTE: Due to the way in which this permission intersection is calculated, it is not possible to create an API key that is a child of another API key, unless the derived key is created without any privileges. In this case, you must explicitly specify a role descriptor with no privileges. The derived API key can be used for authentication; it will not have authority to call Elasticsearch APIs. API name: role_descriptors

type NewCreateApiKey

type NewCreateApiKey func() *CreateApiKey

NewCreateApiKey type alias for index.

func NewCreateApiKeyFunc

func NewCreateApiKeyFunc(tp elastictransport.Interface) NewCreateApiKey

NewCreateApiKeyFunc returns a new instance of CreateApiKey with the provided transport. Used in the index of the library this allows to retrieve every apis in once place.

type Request

type Request struct {

	// Expiration The expiration time for the API key.
	// By default, API keys never expire.
	Expiration types.Duration `json:"expiration,omitempty"`
	// Metadata Arbitrary metadata that you want to associate with the API key. It supports
	// nested data structure. Within the metadata object, keys beginning with `_`
	// are reserved for system usage.
	Metadata types.Metadata `json:"metadata,omitempty"`
	// Name A name for the API key.
	Name *string `json:"name,omitempty"`
	// RoleDescriptors An array of role descriptors for this API key.
	// When it is not specified or it is an empty array, the API key will have a
	// point in time snapshot of permissions of the authenticated user.
	// If you supply role descriptors, the resultant permissions are an intersection
	// of API keys permissions and the authenticated user's permissions thereby
	// limiting the access scope for API keys.
	// The structure of role descriptor is the same as the request for the create
	// role API.
	// For more details, refer to the create or update roles API.
	//
	// NOTE: Due to the way in which this permission intersection is calculated, it
	// is not possible to create an API key that is a child of another API key,
	// unless the derived key is created without any privileges.
	// In this case, you must explicitly specify a role descriptor with no
	// privileges.
	// The derived API key can be used for authentication; it will not have
	// authority to call Elasticsearch APIs.
	RoleDescriptors map[string]types.RoleDescriptor `json:"role_descriptors,omitempty"`
}

Request holds the request body struct for the package createapikey

https://github.com/elastic/elasticsearch-specification/blob/52c473efb1fb5320a5bac12572d0b285882862fb/specification/security/create_api_key/SecurityCreateApiKeyRequest.ts#L26-L86

func NewRequest

func NewRequest() *Request

NewRequest returns a Request

func (*Request) FromJSON

func (r *Request) FromJSON(data string) (*Request, error)

FromJSON allows to load an arbitrary json into the request structure

func (*Request) UnmarshalJSON

func (s *Request) UnmarshalJSON(data []byte) error

type Response

type Response struct {

	// ApiKey Generated API key.
	ApiKey string `json:"api_key"`
	// Encoded API key credentials which is the base64-encoding of
	// the UTF-8 representation of `id` and `api_key` joined
	// by a colon (`:`).
	Encoded string `json:"encoded"`
	// Expiration Expiration in milliseconds for the API key.
	Expiration *int64 `json:"expiration,omitempty"`
	// Id Unique ID for this API key.
	Id string `json:"id"`
	// Name Specifies the name for this API key.
	Name string `json:"name"`
}

Response holds the response body struct for the package createapikey

https://github.com/elastic/elasticsearch-specification/blob/52c473efb1fb5320a5bac12572d0b285882862fb/specification/security/create_api_key/SecurityCreateApiKeyResponse.ts#L23-L50

func NewResponse

func NewResponse() *Response

NewResponse returns a Response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL