Code Monkey home page Code Monkey logo

approval-api's Introduction

OpenAPI for Rails 5

Build Status Maintainability Test Coverage Security

This is a project to provide OpenAPI support inside the Ruby on Rails framework.

Prerequisites

You need to install ruby >= 2.2.2 and run:

bundle install

Getting started

Environmental variables

export SERVICE_APPROVAL_DATABASE_USERNAME=<<database_user>>
export SERVICE_APPROVAL_DATABASE_PASSSWORD=<<database_password>>
or
export DATABASE_URL=postgres://pguser:pgpass@localhost/somedatabase
export MANAGEIQ_USER=admin
export MANAGEIQ_PASSWORD=smartvm
export MANAGEIQ_HOST=localhost
export MANAGEIQ_PORT=3000
bin/rake db:create db:migrate
bin/rails s

To list all your routes, use:

bin/rake routes

License

This project is available as open source under the terms of the Apache License 2.0.

approval-api's People

Contributors

abellotti avatar bdunne avatar bsquizz avatar bzwei avatar carbonin avatar chambridge avatar eclarizio avatar epwinchell avatar fryguy avatar gburges avatar gmcculloug avatar hsong-rh avatar hyperkid123 avatar lgalis avatar mkanoor avatar syncrou avatar zsadeh avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

approval-api's Issues

Sample code to byebug inside Pod

Only for record, since #327 is closed and not allow to post comments:

require 'byebug'
request_id = 80
r = Request.find(request_id)
# add persona based on current user's role
req = {:headers => r.context['headers'].merge('x-rh-persona' => 'approval/admin'),
       :original_url => r.context['original_url']}
byebug
Insights::API::Common::Request.current = req
user = UserContext.new(Insights::API::Common::Request.current, {})
ActsAsTenant.with_tenant(Tenant.find_by(:external_tenant => Insights::API::Common::Request.current.tenant)) do
  r = Request.find(request_id)
  s = RequestPolicy::Scope.new(user, Request)

  start = Time.now.to_f
  s.resolve.to_a
  stop = Time.now.to_f
  puts "lapsed time: #{1000*(stop-start)}"
end

422 Unprocessable entity when content is passed in as a hash

response_code=422 return_code=ok total_time=0.359236
[----] D, [2019-03-29T16:58:17.393012 #7538:3ff7049e5f6c] DEBUG -- : HTTP response body BEGIN
{"message":"Validation failed: Content can't be blank"}

{"requester":"Fred Flintstone","name":"mongodb-persistent","content":{"product":"mongodb-persistent","portfolio":"Fred","order_id":17,"params":"{\"Name\":\"nginx-example-8fb026c5-dad9-4482-8aec-bd6feef660cc\",\"Namespace\":\"openshift\",\"Context Directory\":null,\"Memory Limit\":\"512Mi\",\"NGINX Version\":\"1.12\",\"Application Hostname\":null,\"GitHub Webhook Secret\":\"********\",\"Git Reference\":null,\"Git Repository URL\":\"https://github.com/sclorg/nginx-ex.git\",\"Generic Webhook Secret\":\"********\"}"}}

request controller spec issues

  1. describe 'GET /requests?decision=approved' test on object counting sporadically fails. Need to investigate.

  2. describe 'POST /workflows/:workflow_id/requests' tests have exceptions in the background thread due to empty stages.

Possible sporadic failure

https://travis-ci.org/ManageIQ/approval-api/builds/457684560 shows a sporadic failure, but I cannot get it to fail locally no matter what I do.

From the spec, it is structured very strangely in that there is a top-level let for template_id, then a before block that uses the template_id, and then a context that sets a different template_id. I'm wondering if that override is happening in a different order, but I'm not sure.

Need a locking mechanism for actions

When a new action is created, we'd better to lock the request for accepting other actions. Because the api pod can be scaled up, we need to have a better locking mechanism.

x-rh-identity needs to be removed from openapi.json

The x-rh-identity defined in the openapi.json causes the generated client to step on the x-rh-identity and set it to nil which causes this error on the approval server

{"@timestamp":"2019-03-29T17:00:15.581740 ","hostname":"approval-api-42-5v95s","pid":17,"tid":"222a3ec","level":"crit","message":"K    eyError (x-rh-identity):"}

422 Unprocessable Entity when requester is missing

{"message":"Validation failed: Requester can't be blank, Content can't be blank"}

For this payload

{"@timestamp":"2019-03-29T17:39:47.002923 ","hostname":"approval-api-42-5v95s","pid":17,"tid":"222a48c","level":"info","message":"      Parameters: {\"name\"=\u003e\"mongodb-persistent\", \"content\"=\u003e{\"product\"=\u003e\"mongodb-persistent\", \"portfolio\"=\u0    03e\"Fred\", \"order_id\"=\u003e8, \"params\"=\u003e\"{\\\"Name\\\":\\\"nginx-example-c30e4a90-c793-47b9-8292-fb53e7c4b910\\\",\\\"    Namespace\\\":\\\"openshift\\\",\\\"Context Directory\\\":null,\\\"Memory Limit\\\":\\\"512Mi\\\",\\\"NGINX Version\\\":\\\"1.12\\\    ",\\\"Application Hostname\\\":null,\\\"GitHub Webhook Secret\\\":\\\"********\\\",\\\"Git Reference\\\":null,\\\"Git Repository UR    L\\\":\\\"https://github.com/sclorg/nginx-ex.git\\\",\\\"Generic Webhook Secret\\\":\\\"********\\\"}\"}, \"workflow_id\"=\u003e\"1    \"}"}

New Auto Approval thread doesn't have context

https://github.com/ManageIQ/approval-api/blob/e62a14340f6f144a8a97362d863852f8ff032b71/app/services/request_create_service.rb#L49

This code needs to change to have a context so that we can log the messages for the request with the context, the code needs to be modified to

def start_internal_approval_process(request)
   Thread.new do
     ManageIQ::API::Common::Request.with_request(request.context.transform_keys(&:to_sym)) do
       default_approve? ? default_approve(request) : auto_approve(request)
     end
   end
 end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.