Class: Zavudev::Resources::Functions

Inherits:
Object
  • Object
show all
Defined in:
lib/zavudev/resources/functions.rb,
lib/zavudev/resources/functions/secrets.rb,
sig/zavudev/resources/functions.rbs,
sig/zavudev/resources/functions/secrets.rbs

Defined Under Namespace

Classes: Secrets

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Functions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Functions.

Parameters:



239
240
241
242
# File 'lib/zavudev/resources/functions.rb', line 239

def initialize(client:)
  @client = client
  @secrets = Zavudev::Resources::Functions::Secrets.new(client: client)
end

Instance Attribute Details

#secretsZavudev::Resources::Functions::Secrets (readonly)



7
8
9
# File 'lib/zavudev/resources/functions.rb', line 7

def secrets
  @secrets
end

Instance Method Details

#create(name:, slug:, dependencies: nil, description: nil, entrypoint: nil, files: nil, http_enabled: nil, memory_mb: nil, runtime: nil, source_code: nil, timeout_sec: nil, request_options: {}) ⇒ Zavudev::Models::FunctionCreateResponse

Some parameter documentations has been truncated, see Models::FunctionCreateParams for more details.

Create a new Zavu Function. The function starts in draft status. A dedicated API key is auto-provisioned and injected as the ZAVU_API_KEY secret so the function can call back into the Zavu API without manual setup.

Provide sourceCode to seed the draft. Call POST /v1/functions/{functionId}/deploy afterwards to publish.

Parameters:

  • name (String)
  • slug (String)

    URL-safe identifier (lowercase, digits, hyphens). Must be unique per project.

  • dependencies (Hash{Symbol=>String})

    npm dependencies. Keys are package names, values are semver ranges.

  • description (String)
  • entrypoint (String)

    Which file in files is the entry point. Defaults to index.ts.

  • files (Hash{Symbol=>String})

    The project's source files, keyed by path relative to the project root (e.g. `in

  • http_enabled (Boolean)

    Whether to expose a public HTTPS URL for this function.

  • memory_mb (Integer, Zavudev::Models::FunctionCreateParams::MemoryMB)
  • runtime (Symbol, Zavudev::Models::FunctionCreateParams::Runtime)

    Runtime the function is deployed on.

  • source_code (String)

    Shortcut for a single-file function: exactly equivalent to sending files with

  • timeout_sec (Integer)

    Per-invocation timeout in seconds. Event and cron invocations are asynchronous,

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
# File 'lib/zavudev/resources/functions.rb', line 48

def create(params)
  parsed, options = Zavudev::FunctionCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/functions",
    body: parsed,
    model: Zavudev::Models::FunctionCreateResponse,
    options: options
  )
end

#delete(function_id, request_options: {}) ⇒ Zavudev::Models::FunctionDeleteResponse

Permanently delete a function and cascade: triggers, secrets, deployment history, managed agents+tools, and revoke the auto-provisioned API key. The AWS Lambda + log group are torn down asynchronously.

Parameters:

Returns:

See Also:



131
132
133
134
135
136
137
138
# File 'lib/zavudev/resources/functions.rb', line 131

def delete(function_id, params = {})
  @client.request(
    method: :delete,
    path: ["v1/functions/%1$s", function_id],
    model: Zavudev::Models::FunctionDeleteResponse,
    options: params[:request_options]
  )
end

#deploy(function_id, dependencies: nil, entrypoint: nil, files: nil, source_code: nil, request_options: {}) ⇒ Zavudev::Models::FunctionDeployResponse

Some parameter documentations has been truncated, see Models::FunctionDeployParams for more details.

Publish the function. If sourceCode or dependencies are provided in the body, they replace the current draft before deployment. Returns immediately with a deployment ID — poll GET /v1/functions/deployments/{deploymentId} until status is active or failed.

Parameters:

  • function_id (String)

    Zavu Function ID.

  • dependencies (Hash{Symbol=>String})

    New dependency map (replaces existing dependencies).

  • entrypoint (String)

    Which file in files is the entry point. Defaults to index.ts.

  • files (Hash{Symbol=>String})

    The project's source files, keyed by path relative to the project root (e.g. `in

  • source_code (String)

    Shortcut for a single-file function: exactly equivalent to sending files with

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



165
166
167
168
169
170
171
172
173
174
# File 'lib/zavudev/resources/functions.rb', line 165

def deploy(function_id, params = {})
  parsed, options = Zavudev::FunctionDeployParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/functions/%1$s/deploy", function_id],
    body: parsed,
    model: Zavudev::Models::FunctionDeployResponse,
    options: options
  )
end

#get_deployment(deployment_id, request_options: {}) ⇒ Zavudev::Models::FunctionGetDeploymentResponse

Fetch a deployment to poll its status during a deploy.

Parameters:

  • deployment_id (String)

    Function deployment ID.

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



187
188
189
190
191
192
193
194
# File 'lib/zavudev/resources/functions.rb', line 187

def get_deployment(deployment_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/functions/deployments/%1$s", deployment_id],
    model: Zavudev::Models::FunctionGetDeploymentResponse,
    options: params[:request_options]
  )
end

#retrieve(function_id, request_options: {}) ⇒ Zavudev::Models::FunctionRetrieveResponse

Get function

Parameters:

Returns:

See Also:



70
71
72
73
74
75
76
77
# File 'lib/zavudev/resources/functions.rb', line 70

def retrieve(function_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/functions/%1$s", function_id],
    model: Zavudev::Models::FunctionRetrieveResponse,
    options: params[:request_options]
  )
end

#tail_logs(function_id, end_time: nil, filter_pattern: nil, limit: nil, next_token: nil, start_time: nil, request_options: {}) ⇒ Zavudev::Models::FunctionTailLogsResponse

Fetch invocation logs for a function. Logs are paginated via nextToken. Pass startTime / endTime (Unix epoch milliseconds) to bound the window, or filterPattern to filter messages.

Parameters:

  • function_id (String)

    Zavu Function ID.

  • end_time (Integer)

    End of the log window in Unix epoch milliseconds.

  • filter_pattern (String)
  • limit (Integer)
  • next_token (String)
  • start_time (Integer)

    Start of the log window in Unix epoch milliseconds.

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/zavudev/resources/functions.rb', line 219

def tail_logs(function_id, params = {})
  parsed, options = Zavudev::FunctionTailLogsParams.dump_request(params)
  query = Zavudev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["v1/functions/%1$s/logs", function_id],
    query: query.transform_keys(
      end_time: "endTime",
      filter_pattern: "filterPattern",
      next_token: "nextToken",
      start_time: "startTime"
    ),
    model: Zavudev::Models::FunctionTailLogsResponse,
    options: options
  )
end

#update(function_id, dependencies: nil, entrypoint: nil, files: nil, http_enabled: nil, source_code: nil, request_options: {}) ⇒ Zavudev::Models::FunctionUpdateResponse

Some parameter documentations has been truncated, see Models::FunctionUpdateParams for more details.

Update an existing function. sourceCode / dependencies edit the draft without triggering a build — they go live on the next POST /v1/functions/{functionId}/deploy. httpEnabled is applied to the deployed function immediately, so turning the public endpoint on or off does not require a redeploy.

Parameters:

  • function_id (String)

    Zavu Function ID.

  • dependencies (Hash{Symbol=>String})

    New dependency map (replaces existing dependencies).

  • entrypoint (String)

    Which file in files is the entry point. Defaults to index.ts.

  • files (Hash{Symbol=>String})

    The project's source files, keyed by path relative to the project root (e.g. `in

  • http_enabled (Boolean)

    Expose the function on its public HTTPS URL, or take it down. Applies to the alr

  • source_code (String)

    Shortcut for a single-file function: exactly equivalent to sending files with

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



107
108
109
110
111
112
113
114
115
116
# File 'lib/zavudev/resources/functions.rb', line 107

def update(function_id, params = {})
  parsed, options = Zavudev::FunctionUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["v1/functions/%1$s", function_id],
    body: parsed,
    model: Zavudev::Models::FunctionUpdateResponse,
    options: options
  )
end