Github user linwen commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1052#discussion_r93160802
  
    --- Diff: src/backend/libpq/rangerrest.c ---
    @@ -0,0 +1,551 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +/*-------------------------------------------------------------------------
    + *
    + * rangerrest.c
    + * routines to interact with Ranger REST API
    + *
    + *-------------------------------------------------------------------------
    + */
    +#include "postgres.h"
    +
    +#include <json-c/json.h>
    +
    +#include "utils/acl.h"
    +#include "utils/guc.h"
    +#include "utils/rangerrest.h"
    +
    +/*
    + * Internal buffer for libcurl context
    + */
    +typedef struct curl_context_t
    +{
    +    CURL* curl_handle;
    +
    +    char curl_error_buffer[CURL_ERROR_SIZE];
    +
    +    int curl_still_running;
    +
    +    struct
    +    {
    +        char* buffer;
    +        int size;
    +    } response;
    +
    +    char* last_http_reponse;
    +} curl_context_t;
    +typedef curl_context_t* CURL_HANDLE;
    +
    +RangerACLResult parse_ranger_response(char* buffer)
    +{
    +    Assert(buffer != NULL);
    +    if (strlen(buffer) == 0)
    +        return RANGERCHECK_UNKNOWN;
    +
    +    elog(LOG, "read from Ranger Restful API: %s", buffer);
    +
    +    struct json_object *response = json_tokener_parse(buffer);
    +    struct json_object *accessObj = json_object_object_get(response, 
"access");
    +
    +    int arraylen = json_object_array_length(accessObj);
    +    elog(LOG, "Array Length: %dn",arraylen);
    +
    +    json_object * jvalue;
    +    json_object * jallow;
    +    json_bool result;
    +    // here should return which table's acl check failed in future.
    +    for (int i=0; i< arraylen; i++){
    +      jvalue = json_object_array_get_idx(accessObj, i);
    +      jallow = json_object_object_get(jvalue, "allowed");
    +      result = json_object_get_boolean(jallow);
    +      if(result != 1){
    +        return RANGERCHECK_NO_PRIV;
    +      }
    +    }
    +    return RANGERCHECK_OK;
    +
    +}
    +
    +/*
    + * A mapping from AclObjectKind to string
    + */
    +char* AclObjectKindStr[] =
    +{
    +    "table",             /* pg_class */
    +    "sequence",          /* pg_sequence */
    +    "database",          /* pg_database */
    +    "function",          /* pg_proc */
    +    "operator",          /* pg_operator */
    +    "type",              /* pg_type */
    +    "language",          /* pg_language */
    +    "namespace",         /* pg_namespace */
    +    "oplass",            /* pg_opclass */
    +    "conversion",        /* pg_conversion */
    +    "tablespace",        /* pg_tablespace */
    +    "filespace",         /* pg_filespace */
    +    "filesystem",        /* pg_filesystem */
    +    "fdw",               /* pg_foreign_data_wrapper */
    +    "foreign_server",    /* pg_foreign_server */
    +    "protocol",          /* pg_extprotocol */
    +    "none"               /* MUST BE LAST */
    +};
    +
    +/*
    + * args: List of RangerRequestJsonArgs
    + */
    +json_object *create_ranger_request_json_batch(List *args)
    +{
    +  json_object *juser = NULL;
    +  json_object *jaccess = json_object_new_array();
    +  json_object *jrequest = json_object_new_object();
    +  char *user = NULL;
    +  ListCell *arg;
    +  
    +  foreach(arg, args)
    +  {
    +    RangerRequestJsonArgs *arg_ptr = (RangerRequestJsonArgs *) lfirst(arg);
    +    if (user == NULL)
    +    {
    +      user = arg_ptr->user;
    +      juser = json_object_new_string(user);
    +    }
    +    AclObjectKind kind = arg_ptr->kind;
    +    char* object = arg_ptr->object;
    +    char* how = arg_ptr->how;
    --- End diff --
    
    Yes. We just leave it there, will modify it later. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to