Class: RoleHelper

Inherits:
Object
  • Object
show all
Includes:
CloudmunchService, Util
Defined in:
lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb,
lib/cloudmunch_Ruby_sdk_v3/RoleHelper.rb

Instance Method Summary collapse

Methods included from Util

getJSONArgs, log, logClose, logInit, logIt, openJSONFile

Methods included from CloudmunchService

#deleteCloudmunchData, #deleteKeys, #downloadKeys, #generateServerURL, #getCloudmunchData, #getCloudmunchDataBKUP, getCustomDataContext, #getDataForContext, #getIntegrationWithID, #getResource, http_get, http_post, #parseResponse, putCustomDataContext, #updateCloudmunchData, #updateDataForContext

Constructor Details

#initialize(appContext) ⇒ RoleHelper

Returns a new instance of RoleHelper.



23
24
25
26
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 23

def initialize(appContext)
    @appContext = appContext
    @cloudmunchDataService = CloudmunchService.new 
end

Instance Method Details

#addRole(roleName, roleData) ⇒ Object

/**

* 
* @param string $roleName Name of the role
* @param string $role_status Role status ,valid values are success,failed,in-progress
* @param array  $roleData Array of role properties
*/


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 110

def addRole(roleName, roleData)
    if roleName.empty? then
        log("ERROR", "Role name need to be provided") 
        return false
    end

    roleData["name"] = roleName

    serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/tiers/"
    retResult = @cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), roleData)

    if retResult == nil then 
        return nil
    else
        retResult = JSON.parse(retResult)
        retData = retResult["data"]
        if retData.nil? then 
            return nil
        else
            return retData
        end
    end

end

#checkIfRoleExists(roleID) ⇒ Object

### ### Checks if Role exists in cloudmunch. ### @param string $roleID ### @return boolean ###



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 150

def checkIfRoleExists(roleID)
    serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/tiers/" + roleID

    roleResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(), "")
    if roleResult == nil then  
        return nil
    else
        roleResult = JSON.parse(roleResult)
        roleData = roleResult["data"]
        if roleData.nil? then
            log("ERROR", "Role does not exist") 
            return false
        else
            return true
        end
    end
end

#getExistingRoles(filterData) ⇒ Object

### ### ### @param Json Object $filterdata In the format “filterfield”:“=value” ### @return json object roledetails ### ###



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 49

def getExistingRoles(filterData)
    paramHash = {}
    if !filterData.nil?
        paramHash["filter"] = filterData.to_json
    end

    serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/tiers"
    roleResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(), paramHash)

    if roleResult == nil then 
        log("ERROR", "Unable to get data from cloudmunch") 
        return nil
    else
        roleResult = JSON.parse(roleResult)
        roleData = roleResult["data"]
        if roleData.nil? then
            log("ERROR", "Role does not exist") 
            return nil
        else
            return roleData
        end
    end
end

#getRole(roleID, filterData) ⇒ Object

### ### ### @param String $roleID ### @param Json Object $filterdata In the format “filterfield”:“=value” ### @return json object roledetails ### ###



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 80

def getRole(roleID, filterData)
    paramHash = {}
    if !filterData.nil?
        paramHash["filter"] = filterData.to_json
    end

    serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/tiers/" + roleID
    roleResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(), paramHash)

    if roleResult == nil then 
        log("ERROR", "Unable to get data from cloudmunch") 
        return nil
    else
        roleResult = JSON.parse(roleResult)
        roleData = roleResult["data"]
        if roleData.nil? then
            log("ERROR", "Role does not exist") 
            return nil
        else
            return roleData
        end
    end
end

#isRoleNameUnique(existingRoles, roleName) ⇒ Object

### ### Check if given name of the role is unique with existing ones ### @param string roleName : name of the environment name to be created ### @param string existingRoles : list of existing environments ### @return boolean true if name is unique ###



34
35
36
37
38
39
40
41
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 34

def isRoleNameUnique(existingRoles, roleName)
    existingRoles.each do |k,v|
        if v["name"] == roleName then
            return false
        end
    end
    return true
end

#updateRole(roleID, roleData) ⇒ Object

### ### ### @param String Role ID ### @param JsonObject Role Data ###



140
141
142
143
# File 'lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb', line 140

def updateRole(roleID, roleData)
    serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/tiers/" + roleID
    @cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), roleData)
end