
This adds API V3 endpoints for querying, creating, modifying and
deleting environment variables.
It has no concept of encryption yet and should be considered a work in
progress.
We should also talk about the slightly off-track approach in the
EnvVars::Create service – maybe there's a way to standardise the
querying and rendering for post requests?
☕
28 lines
708 B
Ruby
28 lines
708 B
Ruby
module Travis::API::V3
|
|
class Queries::EnvVars < Query
|
|
params :id, :name, :value, :public, prefix: :env_var
|
|
|
|
def find(repository)
|
|
repository.env_vars
|
|
end
|
|
|
|
def create(repository)
|
|
env_var = repository.env_vars.create(env_var_params)
|
|
handle_errors(env_var) unless env_var.valid?
|
|
repository.save!
|
|
env_var
|
|
end
|
|
|
|
private
|
|
|
|
def handle_errors(env_var)
|
|
base = env_var.errors[:base]
|
|
case
|
|
when base.include?(:format) then raise WrongParams
|
|
when base.include?(:duplicate_resource) then raise DuplicateResource
|
|
else raise ServerError
|
|
end
|
|
end
|
|
end
|
|
end
|