repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.[]=
def []=(key, value) raise ArgumentError, "key must be string" unless key.instance_of?(String) raise ArgumentError, "value must be string" unless value.instance_of?(String) @root_node = update_and_delete_storage( @root_node, NibbleKey.from_string(key), value ) update_root_hash end
ruby
def []=(key, value) raise ArgumentError, "key must be string" unless key.instance_of?(String) raise ArgumentError, "value must be string" unless value.instance_of?(String) @root_node = update_and_delete_storage( @root_node, NibbleKey.from_string(key), value ) update_root_hash end
[ "def", "[]=", "(", "key", ",", "value", ")", "raise", "ArgumentError", ",", "\"key must be string\"", "unless", "key", ".", "instance_of?", "(", "String", ")", "raise", "ArgumentError", ",", "\"value must be string\"", "unless", "value", ".", "instance_of?", "(", "String", ")", "@root_node", "=", "update_and_delete_storage", "(", "@root_node", ",", "NibbleKey", ".", "from_string", "(", "key", ")", ",", "value", ")", "update_root_hash", "end" ]
Set value of key. @param key [String] @param value [String]
[ "Set", "value", "of", "key", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L96-L107
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.delete
def delete(key) raise ArgumentError, "key must be string" unless key.instance_of?(String) raise ArgumentError, "max key size is 32" if key.size > 32 @root_node = delete_and_delete_storage( @root_node, NibbleKey.from_string(key) ) update_root_hash end
ruby
def delete(key) raise ArgumentError, "key must be string" unless key.instance_of?(String) raise ArgumentError, "max key size is 32" if key.size > 32 @root_node = delete_and_delete_storage( @root_node, NibbleKey.from_string(key) ) update_root_hash end
[ "def", "delete", "(", "key", ")", "raise", "ArgumentError", ",", "\"key must be string\"", "unless", "key", ".", "instance_of?", "(", "String", ")", "raise", "ArgumentError", ",", "\"max key size is 32\"", "if", "key", ".", "size", ">", "32", "@root_node", "=", "delete_and_delete_storage", "(", "@root_node", ",", "NibbleKey", ".", "from_string", "(", "key", ")", ")", "update_root_hash", "end" ]
Delete value at key. @param key [String] a string with length of [0,32]
[ "Delete", "value", "at", "key", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L115-L125
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.to_h
def to_h h = {} to_hash(@root_node).each do |k, v| key = k.terminate(false).to_string h[key] = v end h end
ruby
def to_h h = {} to_hash(@root_node).each do |k, v| key = k.terminate(false).to_string h[key] = v end h end
[ "def", "to_h", "h", "=", "{", "}", "to_hash", "(", "@root_node", ")", ".", "each", "do", "|", "k", ",", "v", "|", "key", "=", "k", ".", "terminate", "(", "false", ")", ".", "to_string", "h", "[", "key", "]", "=", "v", "end", "h", "end" ]
Convert to hash.
[ "Convert", "to", "hash", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L130-L137
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.find
def find(node, nbk) node_type = get_node_type node case node_type when :blank BLANK_NODE when :branch return node.last if nbk.empty? sub_node = decode_to_node node[nbk[0]] find sub_node, nbk[1..-1] when :leaf node_key = NibbleKey.decode(node[0]).terminate(false) nbk == node_key ? node[1] : BLANK_NODE when :extension node_key = NibbleKey.decode(node[0]).terminate(false) if node_key.prefix?(nbk) sub_node = decode_to_node node[1] find sub_node, nbk[node_key.size..-1] else BLANK_NODE end else raise InvalidNodeType, "node type must be in #{NODE_TYPES}, given: #{node_type}" end end
ruby
def find(node, nbk) node_type = get_node_type node case node_type when :blank BLANK_NODE when :branch return node.last if nbk.empty? sub_node = decode_to_node node[nbk[0]] find sub_node, nbk[1..-1] when :leaf node_key = NibbleKey.decode(node[0]).terminate(false) nbk == node_key ? node[1] : BLANK_NODE when :extension node_key = NibbleKey.decode(node[0]).terminate(false) if node_key.prefix?(nbk) sub_node = decode_to_node node[1] find sub_node, nbk[node_key.size..-1] else BLANK_NODE end else raise InvalidNodeType, "node type must be in #{NODE_TYPES}, given: #{node_type}" end end
[ "def", "find", "(", "node", ",", "nbk", ")", "node_type", "=", "get_node_type", "node", "case", "node_type", "when", ":blank", "BLANK_NODE", "when", ":branch", "return", "node", ".", "last", "if", "nbk", ".", "empty?", "sub_node", "=", "decode_to_node", "node", "[", "nbk", "[", "0", "]", "]", "find", "sub_node", ",", "nbk", "[", "1", "..", "-", "1", "]", "when", ":leaf", "node_key", "=", "NibbleKey", ".", "decode", "(", "node", "[", "0", "]", ")", ".", "terminate", "(", "false", ")", "nbk", "==", "node_key", "?", "node", "[", "1", "]", ":", "BLANK_NODE", "when", ":extension", "node_key", "=", "NibbleKey", ".", "decode", "(", "node", "[", "0", "]", ")", ".", "terminate", "(", "false", ")", "if", "node_key", ".", "prefix?", "(", "nbk", ")", "sub_node", "=", "decode_to_node", "node", "[", "1", "]", "find", "sub_node", ",", "nbk", "[", "node_key", ".", "size", "..", "-", "1", "]", "else", "BLANK_NODE", "end", "else", "raise", "InvalidNodeType", ",", "\"node type must be in #{NODE_TYPES}, given: #{node_type}\"", "end", "end" ]
Get value inside a node. @param node [Array, BLANK_NODE] node in form of array, or BLANK_NODE @param nbk [Array] nibble array without terminator @return [String] BLANK_NODE if does not exist, otherwise node value
[ "Get", "value", "inside", "a", "node", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L172-L197
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.update_node
def update_node(node, key, value) node_type = get_node_type node case node_type when :blank [key.terminate(true).encode, value] when :branch if key.empty? node.last = value else new_node = update_and_delete_storage( decode_to_node(node[key[0]]), key[1..-1], value ) node[key[0]] = encode_node new_node end node when :leaf update_leaf_node(node, key, value) else update_extension_node(node, key, value) end end
ruby
def update_node(node, key, value) node_type = get_node_type node case node_type when :blank [key.terminate(true).encode, value] when :branch if key.empty? node.last = value else new_node = update_and_delete_storage( decode_to_node(node[key[0]]), key[1..-1], value ) node[key[0]] = encode_node new_node end node when :leaf update_leaf_node(node, key, value) else update_extension_node(node, key, value) end end
[ "def", "update_node", "(", "node", ",", "key", ",", "value", ")", "node_type", "=", "get_node_type", "node", "case", "node_type", "when", ":blank", "[", "key", ".", "terminate", "(", "true", ")", ".", "encode", ",", "value", "]", "when", ":branch", "if", "key", ".", "empty?", "node", ".", "last", "=", "value", "else", "new_node", "=", "update_and_delete_storage", "(", "decode_to_node", "(", "node", "[", "key", "[", "0", "]", "]", ")", ",", "key", "[", "1", "..", "-", "1", "]", ",", "value", ")", "node", "[", "key", "[", "0", "]", "]", "=", "encode_node", "new_node", "end", "node", "when", ":leaf", "update_leaf_node", "(", "node", ",", "key", ",", "value", ")", "else", "update_extension_node", "(", "node", ",", "key", ",", "value", ")", "end", "end" ]
Update item inside a node. If this node is changed to a new node, it's parent will take the responsibility to **store** the new node storage, and delete the old node storage. @param node [Array, BLANK_NODE] node in form of array, or BLANK_NODE @param key [Array] nibble key without terminator @param value [String] value string @return [Array, BLANK_NODE] new node
[ "Update", "item", "inside", "a", "node", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L275-L299
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.delete_node
def delete_node(node, key) case get_node_type(node) when :blank BLANK_NODE when :branch delete_branch_node(node, key) else # kv type delete_kv_node(node, key) end end
ruby
def delete_node(node, key) case get_node_type(node) when :blank BLANK_NODE when :branch delete_branch_node(node, key) else # kv type delete_kv_node(node, key) end end
[ "def", "delete_node", "(", "node", ",", "key", ")", "case", "get_node_type", "(", "node", ")", "when", ":blank", "BLANK_NODE", "when", ":branch", "delete_branch_node", "(", "node", ",", "key", ")", "else", "# kv type", "delete_kv_node", "(", "node", ",", "key", ")", "end", "end" ]
Delete item inside node. If this node is changed to a new node, it's parent will take the responsibility to **store** the new node storage, and delete the old node storage. @param node [Array, BLANK_NODE] node in form of array, or BLANK_NODE @param key [Array] nibble key without terminator. key maybe empty @return new node
[ "Delete", "item", "inside", "node", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L403-L412
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.delete_node_storage
def delete_node_storage(node) return if node == BLANK_NODE raise ArgumentError, "node must be Array or BLANK_NODE" unless node.instance_of?(Array) encoded = encode_node node return if encoded.size < 32 # FIXME: in current trie implementation two nodes can share identical # subtree thus we can not safely delete nodes for now # # \@db.delete encoded end
ruby
def delete_node_storage(node) return if node == BLANK_NODE raise ArgumentError, "node must be Array or BLANK_NODE" unless node.instance_of?(Array) encoded = encode_node node return if encoded.size < 32 # FIXME: in current trie implementation two nodes can share identical # subtree thus we can not safely delete nodes for now # # \@db.delete encoded end
[ "def", "delete_node_storage", "(", "node", ")", "return", "if", "node", "==", "BLANK_NODE", "raise", "ArgumentError", ",", "\"node must be Array or BLANK_NODE\"", "unless", "node", ".", "instance_of?", "(", "Array", ")", "encoded", "=", "encode_node", "node", "return", "if", "encoded", ".", "size", "<", "32", "# FIXME: in current trie implementation two nodes can share identical", "# subtree thus we can not safely delete nodes for now", "#", "# \\@db.delete encoded", "end" ]
Delete node storage. @param node [Array, BLANK_NODE] node in form of array, or BLANK_NODE
[ "Delete", "node", "storage", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L494-L505
train
cryptape/ruby-ethereum
lib/ethereum/trie.rb
Ethereum.Trie.get_node_type
def get_node_type(node) return :blank if node == BLANK_NODE case node.size when KV_WIDTH # [k,v] NibbleKey.decode(node[0]).terminate? ? :leaf : :extension when BRANCH_WIDTH # [k0, ... k15, v] :branch else raise InvalidNode, "node size must be #{KV_WIDTH} or #{BRANCH_WIDTH}" end end
ruby
def get_node_type(node) return :blank if node == BLANK_NODE case node.size when KV_WIDTH # [k,v] NibbleKey.decode(node[0]).terminate? ? :leaf : :extension when BRANCH_WIDTH # [k0, ... k15, v] :branch else raise InvalidNode, "node size must be #{KV_WIDTH} or #{BRANCH_WIDTH}" end end
[ "def", "get_node_type", "(", "node", ")", "return", ":blank", "if", "node", "==", "BLANK_NODE", "case", "node", ".", "size", "when", "KV_WIDTH", "# [k,v]", "NibbleKey", ".", "decode", "(", "node", "[", "0", "]", ")", ".", "terminate?", "?", ":leaf", ":", ":extension", "when", "BRANCH_WIDTH", "# [k0, ... k15, v]", ":branch", "else", "raise", "InvalidNode", ",", "\"node size must be #{KV_WIDTH} or #{BRANCH_WIDTH}\"", "end", "end" ]
get node type and content @param node [Array, BLANK_NODE] node in form of array, or BLANK_NODE @return [Symbol] node type
[ "get", "node", "type", "and", "content" ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/trie.rb#L526-L537
train
cryptape/ruby-ethereum
lib/ethereum/vm.rb
Ethereum.VM.preprocess_code
def preprocess_code(code) code = Utils.bytes_to_int_array code ops = [] i = 0 while i < code.size o = Opcodes::TABLE.fetch(code[i], [:INVALID, 0, 0, 0]) + [code[i], 0] ops.push o if o[0][0,Opcodes::PREFIX_PUSH.size] == Opcodes::PREFIX_PUSH n = o[0][Opcodes::PREFIX_PUSH.size..-1].to_i n.times do |j| i += 1 byte = i < code.size ? code[i] : 0 o[-1] = (o[-1] << 8) + byte # polyfill, these INVALID ops will be skipped in execution ops.push [:INVALID, 0, 0, 0, byte, 0] if i < code.size end end i += 1 end ops end
ruby
def preprocess_code(code) code = Utils.bytes_to_int_array code ops = [] i = 0 while i < code.size o = Opcodes::TABLE.fetch(code[i], [:INVALID, 0, 0, 0]) + [code[i], 0] ops.push o if o[0][0,Opcodes::PREFIX_PUSH.size] == Opcodes::PREFIX_PUSH n = o[0][Opcodes::PREFIX_PUSH.size..-1].to_i n.times do |j| i += 1 byte = i < code.size ? code[i] : 0 o[-1] = (o[-1] << 8) + byte # polyfill, these INVALID ops will be skipped in execution ops.push [:INVALID, 0, 0, 0, byte, 0] if i < code.size end end i += 1 end ops end
[ "def", "preprocess_code", "(", "code", ")", "code", "=", "Utils", ".", "bytes_to_int_array", "code", "ops", "=", "[", "]", "i", "=", "0", "while", "i", "<", "code", ".", "size", "o", "=", "Opcodes", "::", "TABLE", ".", "fetch", "(", "code", "[", "i", "]", ",", "[", ":INVALID", ",", "0", ",", "0", ",", "0", "]", ")", "+", "[", "code", "[", "i", "]", ",", "0", "]", "ops", ".", "push", "o", "if", "o", "[", "0", "]", "[", "0", ",", "Opcodes", "::", "PREFIX_PUSH", ".", "size", "]", "==", "Opcodes", "::", "PREFIX_PUSH", "n", "=", "o", "[", "0", "]", "[", "Opcodes", "::", "PREFIX_PUSH", ".", "size", "..", "-", "1", "]", ".", "to_i", "n", ".", "times", "do", "|", "j", "|", "i", "+=", "1", "byte", "=", "i", "<", "code", ".", "size", "?", "code", "[", "i", "]", ":", "0", "o", "[", "-", "1", "]", "=", "(", "o", "[", "-", "1", "]", "<<", "8", ")", "+", "byte", "# polyfill, these INVALID ops will be skipped in execution", "ops", ".", "push", "[", ":INVALID", ",", "0", ",", "0", ",", "0", ",", "byte", ",", "0", "]", "if", "i", "<", "code", ".", "size", "end", "end", "i", "+=", "1", "end", "ops", "end" ]
Preprocesses code, and determines which locations are in the middle of pushdata and thus invalid
[ "Preprocesses", "code", "and", "determines", "which", "locations", "are", "in", "the", "middle", "of", "pushdata", "and", "thus", "invalid" ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/vm.rb#L574-L599
train
cryptape/ruby-ethereum
lib/ethereum/block_header.rb
Ethereum.BlockHeader.check_pow
def check_pow(nonce=nil) logger.debug "checking pow", block: full_hash_hex[0,8] Miner.check_pow(number, mining_hash, mixhash, nonce || self.nonce, difficulty) end
ruby
def check_pow(nonce=nil) logger.debug "checking pow", block: full_hash_hex[0,8] Miner.check_pow(number, mining_hash, mixhash, nonce || self.nonce, difficulty) end
[ "def", "check_pow", "(", "nonce", "=", "nil", ")", "logger", ".", "debug", "\"checking pow\"", ",", "block", ":", "full_hash_hex", "[", "0", ",", "8", "]", "Miner", ".", "check_pow", "(", "number", ",", "mining_hash", ",", "mixhash", ",", "nonce", "||", "self", ".", "nonce", ",", "difficulty", ")", "end" ]
Check if the proof-of-work of the block is valid. @param nonce [String] if given the proof of work function will be evaluated with this nonce instead of the one already present in the header @return [Bool]
[ "Check", "if", "the", "proof", "-", "of", "-", "work", "of", "the", "block", "is", "valid", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/block_header.rb#L147-L150
train
cryptape/ruby-ethereum
lib/ethereum/block_header.rb
Ethereum.BlockHeader.to_h
def to_h h = {} %i(prevhash uncles_hash extra_data nonce mixhash).each do |field| h[field] = "0x#{Utils.encode_hex(send field)}" end %i(state_root tx_list_root receipts_root coinbase).each do |field| h[field] = Utils.encode_hex send(field) end %i(number difficulty gas_limit gas_used timestamp).each do |field| h[field] = send(field).to_s end h[:bloom] = Utils.encode_hex Sedes.int256.serialize(bloom) h end
ruby
def to_h h = {} %i(prevhash uncles_hash extra_data nonce mixhash).each do |field| h[field] = "0x#{Utils.encode_hex(send field)}" end %i(state_root tx_list_root receipts_root coinbase).each do |field| h[field] = Utils.encode_hex send(field) end %i(number difficulty gas_limit gas_used timestamp).each do |field| h[field] = send(field).to_s end h[:bloom] = Utils.encode_hex Sedes.int256.serialize(bloom) h end
[ "def", "to_h", "h", "=", "{", "}", "%i(", "prevhash", "uncles_hash", "extra_data", "nonce", "mixhash", ")", ".", "each", "do", "|", "field", "|", "h", "[", "field", "]", "=", "\"0x#{Utils.encode_hex(send field)}\"", "end", "%i(", "state_root", "tx_list_root", "receipts_root", "coinbase", ")", ".", "each", "do", "|", "field", "|", "h", "[", "field", "]", "=", "Utils", ".", "encode_hex", "send", "(", "field", ")", "end", "%i(", "number", "difficulty", "gas_limit", "gas_used", "timestamp", ")", ".", "each", "do", "|", "field", "|", "h", "[", "field", "]", "=", "send", "(", "field", ")", ".", "to_s", "end", "h", "[", ":bloom", "]", "=", "Utils", ".", "encode_hex", "Sedes", ".", "int256", ".", "serialize", "(", "bloom", ")", "h", "end" ]
Serialize the header to a readable hash.
[ "Serialize", "the", "header", "to", "a", "readable", "hash", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/block_header.rb#L155-L173
train
cryptape/ruby-ethereum
lib/ethereum/chain.rb
Ethereum.Chain.get_brothers
def get_brothers(block) o = [] i = 0 while block.has_parent? && i < @env.config[:max_uncle_depth] parent = block.get_parent children = get_children(parent).select {|c| c != block } o.concat children block = parent i += 1 end o end
ruby
def get_brothers(block) o = [] i = 0 while block.has_parent? && i < @env.config[:max_uncle_depth] parent = block.get_parent children = get_children(parent).select {|c| c != block } o.concat children block = parent i += 1 end o end
[ "def", "get_brothers", "(", "block", ")", "o", "=", "[", "]", "i", "=", "0", "while", "block", ".", "has_parent?", "&&", "i", "<", "@env", ".", "config", "[", ":max_uncle_depth", "]", "parent", "=", "block", ".", "get_parent", "children", "=", "get_children", "(", "parent", ")", ".", "select", "{", "|", "c", "|", "c", "!=", "block", "}", "o", ".", "concat", "children", "block", "=", "parent", "i", "+=", "1", "end", "o", "end" ]
Return the uncles of the hypothetical child of `block`.
[ "Return", "the", "uncles", "of", "the", "hypothetical", "child", "of", "block", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/chain.rb#L68-L81
train
cryptape/ruby-ethereum
lib/ethereum/chain.rb
Ethereum.Chain.add_block
def add_block(block, forward_pending_transaction=true) unless block.has_parent? || block.genesis? logger.debug "missing parent", block_hash: block return false end unless block.validate_uncles logger.debug "invalid uncles", block_hash: block return false end unless block.header.check_pow || block.genesis? logger.debug "invalid nonce", block_hash: block return false end if block.has_parent? begin Block.verify(block, block.get_parent) rescue InvalidBlock => e log.fatal "VERIFICATION FAILED", block_hash: block, error: e f = File.join Utils.data_dir, 'badblock.log' File.write(f, Utils.encode_hex(RLP.encode(block))) return false end end if block.number < head.number logger.debug "older than head", block_hash: block, head_hash: head end @index.add_block block store_block block # set to head if this makes the longest chain w/ most work for that number if block.chain_difficulty > head.chain_difficulty logger.debug "new head", block_hash: block, num_tx: block.transaction_count update_head block, forward_pending_transaction elsif block.number > head.number logger.warn "has higher blk number than head but lower chain_difficulty", block_has: block, head_hash: head, block_difficulty: block.chain_difficulty, head_difficulty: head.chain_difficulty end # Refactor the long calling chain block.transactions.clear_all block.receipts.clear_all block.state.db.commit_refcount_changes block.number block.state.db.cleanup block.number commit # batch commits all changes that came with the new block true end
ruby
def add_block(block, forward_pending_transaction=true) unless block.has_parent? || block.genesis? logger.debug "missing parent", block_hash: block return false end unless block.validate_uncles logger.debug "invalid uncles", block_hash: block return false end unless block.header.check_pow || block.genesis? logger.debug "invalid nonce", block_hash: block return false end if block.has_parent? begin Block.verify(block, block.get_parent) rescue InvalidBlock => e log.fatal "VERIFICATION FAILED", block_hash: block, error: e f = File.join Utils.data_dir, 'badblock.log' File.write(f, Utils.encode_hex(RLP.encode(block))) return false end end if block.number < head.number logger.debug "older than head", block_hash: block, head_hash: head end @index.add_block block store_block block # set to head if this makes the longest chain w/ most work for that number if block.chain_difficulty > head.chain_difficulty logger.debug "new head", block_hash: block, num_tx: block.transaction_count update_head block, forward_pending_transaction elsif block.number > head.number logger.warn "has higher blk number than head but lower chain_difficulty", block_has: block, head_hash: head, block_difficulty: block.chain_difficulty, head_difficulty: head.chain_difficulty end # Refactor the long calling chain block.transactions.clear_all block.receipts.clear_all block.state.db.commit_refcount_changes block.number block.state.db.cleanup block.number commit # batch commits all changes that came with the new block true end
[ "def", "add_block", "(", "block", ",", "forward_pending_transaction", "=", "true", ")", "unless", "block", ".", "has_parent?", "||", "block", ".", "genesis?", "logger", ".", "debug", "\"missing parent\"", ",", "block_hash", ":", "block", "return", "false", "end", "unless", "block", ".", "validate_uncles", "logger", ".", "debug", "\"invalid uncles\"", ",", "block_hash", ":", "block", "return", "false", "end", "unless", "block", ".", "header", ".", "check_pow", "||", "block", ".", "genesis?", "logger", ".", "debug", "\"invalid nonce\"", ",", "block_hash", ":", "block", "return", "false", "end", "if", "block", ".", "has_parent?", "begin", "Block", ".", "verify", "(", "block", ",", "block", ".", "get_parent", ")", "rescue", "InvalidBlock", "=>", "e", "log", ".", "fatal", "\"VERIFICATION FAILED\"", ",", "block_hash", ":", "block", ",", "error", ":", "e", "f", "=", "File", ".", "join", "Utils", ".", "data_dir", ",", "'badblock.log'", "File", ".", "write", "(", "f", ",", "Utils", ".", "encode_hex", "(", "RLP", ".", "encode", "(", "block", ")", ")", ")", "return", "false", "end", "end", "if", "block", ".", "number", "<", "head", ".", "number", "logger", ".", "debug", "\"older than head\"", ",", "block_hash", ":", "block", ",", "head_hash", ":", "head", "end", "@index", ".", "add_block", "block", "store_block", "block", "# set to head if this makes the longest chain w/ most work for that number", "if", "block", ".", "chain_difficulty", ">", "head", ".", "chain_difficulty", "logger", ".", "debug", "\"new head\"", ",", "block_hash", ":", "block", ",", "num_tx", ":", "block", ".", "transaction_count", "update_head", "block", ",", "forward_pending_transaction", "elsif", "block", ".", "number", ">", "head", ".", "number", "logger", ".", "warn", "\"has higher blk number than head but lower chain_difficulty\"", ",", "block_has", ":", "block", ",", "head_hash", ":", "head", ",", "block_difficulty", ":", "block", ".", "chain_difficulty", ",", "head_difficulty", ":", "head", ".", "chain_difficulty", "end", "# Refactor the long calling chain", "block", ".", "transactions", ".", "clear_all", "block", ".", "receipts", ".", "clear_all", "block", ".", "state", ".", "db", ".", "commit_refcount_changes", "block", ".", "number", "block", ".", "state", ".", "db", ".", "cleanup", "block", ".", "number", "commit", "# batch commits all changes that came with the new block", "true", "end" ]
Returns `true` if block was added successfully.
[ "Returns", "true", "if", "block", "was", "added", "successfully", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/chain.rb#L109-L160
train
cryptape/ruby-ethereum
lib/ethereum/chain.rb
Ethereum.Chain.add_transaction
def add_transaction(transaction) raise AssertError, "head candiate cannot be nil" unless @head_candidate hc = @head_candidate logger.debug "add tx", num_txs: transaction_count, tx: transaction, on: hc if @head_candidate.include_transaction?(transaction.full_hash) logger.debug "known tx" return end old_state_root = hc.state_root # revert finalization hc.state_root = @pre_finalize_state_root begin success, output = hc.apply_transaction(transaction) rescue InvalidTransaction => e # if unsuccessful the prerequisites were not fullfilled and the tx is # invalid, state must not have changed logger.debug "invalid tx", error: e hc.state_root = old_state_root return false end logger.debug "valid tx" # we might have a new head_candidate (due to ctx switches in up layer) if @head_candidate != hc logger.debug "head_candidate changed during validation, trying again" return add_transaction(transaction) end @pre_finalize_state_root = hc.state_root hc.finalize logger.debug "tx applied", result: output raise AssertError, "state root unchanged!" unless old_state_root != hc.state_root true end
ruby
def add_transaction(transaction) raise AssertError, "head candiate cannot be nil" unless @head_candidate hc = @head_candidate logger.debug "add tx", num_txs: transaction_count, tx: transaction, on: hc if @head_candidate.include_transaction?(transaction.full_hash) logger.debug "known tx" return end old_state_root = hc.state_root # revert finalization hc.state_root = @pre_finalize_state_root begin success, output = hc.apply_transaction(transaction) rescue InvalidTransaction => e # if unsuccessful the prerequisites were not fullfilled and the tx is # invalid, state must not have changed logger.debug "invalid tx", error: e hc.state_root = old_state_root return false end logger.debug "valid tx" # we might have a new head_candidate (due to ctx switches in up layer) if @head_candidate != hc logger.debug "head_candidate changed during validation, trying again" return add_transaction(transaction) end @pre_finalize_state_root = hc.state_root hc.finalize logger.debug "tx applied", result: output raise AssertError, "state root unchanged!" unless old_state_root != hc.state_root true end
[ "def", "add_transaction", "(", "transaction", ")", "raise", "AssertError", ",", "\"head candiate cannot be nil\"", "unless", "@head_candidate", "hc", "=", "@head_candidate", "logger", ".", "debug", "\"add tx\"", ",", "num_txs", ":", "transaction_count", ",", "tx", ":", "transaction", ",", "on", ":", "hc", "if", "@head_candidate", ".", "include_transaction?", "(", "transaction", ".", "full_hash", ")", "logger", ".", "debug", "\"known tx\"", "return", "end", "old_state_root", "=", "hc", ".", "state_root", "# revert finalization", "hc", ".", "state_root", "=", "@pre_finalize_state_root", "begin", "success", ",", "output", "=", "hc", ".", "apply_transaction", "(", "transaction", ")", "rescue", "InvalidTransaction", "=>", "e", "# if unsuccessful the prerequisites were not fullfilled and the tx is", "# invalid, state must not have changed", "logger", ".", "debug", "\"invalid tx\"", ",", "error", ":", "e", "hc", ".", "state_root", "=", "old_state_root", "return", "false", "end", "logger", ".", "debug", "\"valid tx\"", "# we might have a new head_candidate (due to ctx switches in up layer)", "if", "@head_candidate", "!=", "hc", "logger", ".", "debug", "\"head_candidate changed during validation, trying again\"", "return", "add_transaction", "(", "transaction", ")", "end", "@pre_finalize_state_root", "=", "hc", ".", "state_root", "hc", ".", "finalize", "logger", ".", "debug", "\"tx applied\"", ",", "result", ":", "output", "raise", "AssertError", ",", "\"state root unchanged!\"", "unless", "old_state_root", "!=", "hc", ".", "state_root", "true", "end" ]
Add a transaction to the `head_candidate` block. If the transaction is invalid, the block will not be changed. @return [Bool,NilClass] `true` is the transaction was successfully added or `false` if the transaction was invalid, `nil` if it's already included
[ "Add", "a", "transaction", "to", "the", "head_candidate", "block", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/chain.rb#L174-L211
train
cryptape/ruby-ethereum
lib/ethereum/chain.rb
Ethereum.Chain.get_chain
def get_chain(start: '', count: 10) logger.debug "get_chain", start: Utils.encode_hex(start), count: count if start.true? return [] unless @index.db.include?(start) block = get start return [] unless in_main_branch?(block) else block = head end blocks = [] count.times do |i| blocks.push block break if block.genesis? block = block.get_parent end blocks end
ruby
def get_chain(start: '', count: 10) logger.debug "get_chain", start: Utils.encode_hex(start), count: count if start.true? return [] unless @index.db.include?(start) block = get start return [] unless in_main_branch?(block) else block = head end blocks = [] count.times do |i| blocks.push block break if block.genesis? block = block.get_parent end blocks end
[ "def", "get_chain", "(", "start", ":", "''", ",", "count", ":", "10", ")", "logger", ".", "debug", "\"get_chain\"", ",", "start", ":", "Utils", ".", "encode_hex", "(", "start", ")", ",", "count", ":", "count", "if", "start", ".", "true?", "return", "[", "]", "unless", "@index", ".", "db", ".", "include?", "(", "start", ")", "block", "=", "get", "start", "return", "[", "]", "unless", "in_main_branch?", "(", "block", ")", "else", "block", "=", "head", "end", "blocks", "=", "[", "]", "count", ".", "times", "do", "|", "i", "|", "blocks", ".", "push", "block", "break", "if", "block", ".", "genesis?", "block", "=", "block", ".", "get_parent", "end", "blocks", "end" ]
Return `count` of blocks starting from head or `start`.
[ "Return", "count", "of", "blocks", "starting", "from", "head", "or", "start", "." ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/chain.rb#L233-L253
train
cryptape/ruby-ethereum
lib/ethereum/chain.rb
Ethereum.Chain.update_head_candidate
def update_head_candidate(forward_pending_transaction=true) logger.debug "updating head candidate", head: head # collect uncles blk = head # parent of the block we are collecting uncles for uncles = get_brothers(blk).map(&:header).uniq (@env.config[:max_uncle_depth]+2).times do |i| blk.uncles.each {|u| uncles.delete u } blk = blk.get_parent if blk.has_parent? end raise "strange uncle found!" unless uncles.empty? || uncles.map(&:number).max <= head.number uncles = uncles[0, @env.config[:max_uncles]] # create block ts = [Time.now.to_i, head.timestamp+1].max _env = Env.new DB::OverlayDB.new(head.db), config: @env.config, global_config: @env.global_config hc = Block.build_from_parent head, @coinbase, timestamp: ts, uncles: uncles, env: _env raise ValidationError, "invalid uncles" unless hc.validate_uncles @pre_finalize_state_root = hc.state_root hc.finalize # add transactions from previous head candidate old_hc = @head_candidate @head_candidate = hc if old_hc tx_hashes = head.get_transaction_hashes pending = old_hc.get_transactions.select {|tx| !tx_hashes.include?(tx.full_hash) } if pending.true? if forward_pending_transaction logger.debug "forwarding pending transaction", num: pending.size pending.each {|tx| add_transaction tx } else logger.debug "discarding pending transaction", num: pending.size end end end end
ruby
def update_head_candidate(forward_pending_transaction=true) logger.debug "updating head candidate", head: head # collect uncles blk = head # parent of the block we are collecting uncles for uncles = get_brothers(blk).map(&:header).uniq (@env.config[:max_uncle_depth]+2).times do |i| blk.uncles.each {|u| uncles.delete u } blk = blk.get_parent if blk.has_parent? end raise "strange uncle found!" unless uncles.empty? || uncles.map(&:number).max <= head.number uncles = uncles[0, @env.config[:max_uncles]] # create block ts = [Time.now.to_i, head.timestamp+1].max _env = Env.new DB::OverlayDB.new(head.db), config: @env.config, global_config: @env.global_config hc = Block.build_from_parent head, @coinbase, timestamp: ts, uncles: uncles, env: _env raise ValidationError, "invalid uncles" unless hc.validate_uncles @pre_finalize_state_root = hc.state_root hc.finalize # add transactions from previous head candidate old_hc = @head_candidate @head_candidate = hc if old_hc tx_hashes = head.get_transaction_hashes pending = old_hc.get_transactions.select {|tx| !tx_hashes.include?(tx.full_hash) } if pending.true? if forward_pending_transaction logger.debug "forwarding pending transaction", num: pending.size pending.each {|tx| add_transaction tx } else logger.debug "discarding pending transaction", num: pending.size end end end end
[ "def", "update_head_candidate", "(", "forward_pending_transaction", "=", "true", ")", "logger", ".", "debug", "\"updating head candidate\"", ",", "head", ":", "head", "# collect uncles", "blk", "=", "head", "# parent of the block we are collecting uncles for", "uncles", "=", "get_brothers", "(", "blk", ")", ".", "map", "(", ":header", ")", ".", "uniq", "(", "@env", ".", "config", "[", ":max_uncle_depth", "]", "+", "2", ")", ".", "times", "do", "|", "i", "|", "blk", ".", "uncles", ".", "each", "{", "|", "u", "|", "uncles", ".", "delete", "u", "}", "blk", "=", "blk", ".", "get_parent", "if", "blk", ".", "has_parent?", "end", "raise", "\"strange uncle found!\"", "unless", "uncles", ".", "empty?", "||", "uncles", ".", "map", "(", ":number", ")", ".", "max", "<=", "head", ".", "number", "uncles", "=", "uncles", "[", "0", ",", "@env", ".", "config", "[", ":max_uncles", "]", "]", "# create block", "ts", "=", "[", "Time", ".", "now", ".", "to_i", ",", "head", ".", "timestamp", "+", "1", "]", ".", "max", "_env", "=", "Env", ".", "new", "DB", "::", "OverlayDB", ".", "new", "(", "head", ".", "db", ")", ",", "config", ":", "@env", ".", "config", ",", "global_config", ":", "@env", ".", "global_config", "hc", "=", "Block", ".", "build_from_parent", "head", ",", "@coinbase", ",", "timestamp", ":", "ts", ",", "uncles", ":", "uncles", ",", "env", ":", "_env", "raise", "ValidationError", ",", "\"invalid uncles\"", "unless", "hc", ".", "validate_uncles", "@pre_finalize_state_root", "=", "hc", ".", "state_root", "hc", ".", "finalize", "# add transactions from previous head candidate", "old_hc", "=", "@head_candidate", "@head_candidate", "=", "hc", "if", "old_hc", "tx_hashes", "=", "head", ".", "get_transaction_hashes", "pending", "=", "old_hc", ".", "get_transactions", ".", "select", "{", "|", "tx", "|", "!", "tx_hashes", ".", "include?", "(", "tx", ".", "full_hash", ")", "}", "if", "pending", ".", "true?", "if", "forward_pending_transaction", "logger", ".", "debug", "\"forwarding pending transaction\"", ",", "num", ":", "pending", ".", "size", "pending", ".", "each", "{", "|", "tx", "|", "add_transaction", "tx", "}", "else", "logger", ".", "debug", "\"discarding pending transaction\"", ",", "num", ":", "pending", ".", "size", "end", "end", "end", "end" ]
after new head is set
[ "after", "new", "head", "is", "set" ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/chain.rb#L355-L397
train
cryptape/ruby-ethereum
lib/ethereum/index.rb
Ethereum.Index.update_blocknumbers
def update_blocknumbers(blk) loop do if blk.number > 0 @db.put_temporarily block_by_number_key(blk.number), blk.full_hash else @db.put block_by_number_key(blk.number), blk.full_hash end @db.commit_refcount_changes blk.number break if blk.number == 0 blk = blk.get_parent() break if has_block_by_number(blk.number) && get_block_by_number(blk.number) == blk.full_hash end end
ruby
def update_blocknumbers(blk) loop do if blk.number > 0 @db.put_temporarily block_by_number_key(blk.number), blk.full_hash else @db.put block_by_number_key(blk.number), blk.full_hash end @db.commit_refcount_changes blk.number break if blk.number == 0 blk = blk.get_parent() break if has_block_by_number(blk.number) && get_block_by_number(blk.number) == blk.full_hash end end
[ "def", "update_blocknumbers", "(", "blk", ")", "loop", "do", "if", "blk", ".", "number", ">", "0", "@db", ".", "put_temporarily", "block_by_number_key", "(", "blk", ".", "number", ")", ",", "blk", ".", "full_hash", "else", "@db", ".", "put", "block_by_number_key", "(", "blk", ".", "number", ")", ",", "blk", ".", "full_hash", "end", "@db", ".", "commit_refcount_changes", "blk", ".", "number", "break", "if", "blk", ".", "number", "==", "0", "blk", "=", "blk", ".", "get_parent", "(", ")", "break", "if", "has_block_by_number", "(", "blk", ".", "number", ")", "&&", "get_block_by_number", "(", "blk", ".", "number", ")", "==", "blk", ".", "full_hash", "end", "end" ]
start from head and update until the existing indices match the block
[ "start", "from", "head", "and", "update", "until", "the", "existing", "indices", "match", "the", "block" ]
763f8651085ba145355a290da716884c7625a941
https://github.com/cryptape/ruby-ethereum/blob/763f8651085ba145355a290da716884c7625a941/lib/ethereum/index.rb#L33-L47
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.install_if_reported_available=
def install_if_reported_available=(new_val) return nil if new_val == @install_if_reported_available new_val = false if new_val.to_s.empty? raise JSS::InvalidDataError, 'install_if_reported_available must be boolean true or false' unless JSS::TRUE_FALSE.include? new_val @install_if_reported_available = new_val @need_to_update = true end
ruby
def install_if_reported_available=(new_val) return nil if new_val == @install_if_reported_available new_val = false if new_val.to_s.empty? raise JSS::InvalidDataError, 'install_if_reported_available must be boolean true or false' unless JSS::TRUE_FALSE.include? new_val @install_if_reported_available = new_val @need_to_update = true end
[ "def", "install_if_reported_available", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@install_if_reported_available", "new_val", "=", "false", "if", "new_val", ".", "to_s", ".", "empty?", "raise", "JSS", "::", "InvalidDataError", ",", "'install_if_reported_available must be boolean true or false'", "unless", "JSS", "::", "TRUE_FALSE", ".", "include?", "new_val", "@install_if_reported_available", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change the if_in_swupdate field in the JSS @param new_val[Boolean] @return [void]
[ "Change", "the", "if_in_swupdate", "field", "in", "the", "JSS" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L383-L389
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.priority=
def priority=(new_val) return nil if new_val == @priority new_val = DEFAULT_PRIORITY if new_val.to_s.empty? raise JSS::InvalidDataError, ':priority must be an integer from 1-20' unless PRIORITIES.include? new_val @priority = new_val @need_to_update = true end
ruby
def priority=(new_val) return nil if new_val == @priority new_val = DEFAULT_PRIORITY if new_val.to_s.empty? raise JSS::InvalidDataError, ':priority must be an integer from 1-20' unless PRIORITIES.include? new_val @priority = new_val @need_to_update = true end
[ "def", "priority", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@priority", "new_val", "=", "DEFAULT_PRIORITY", "if", "new_val", ".", "to_s", ".", "empty?", "raise", "JSS", "::", "InvalidDataError", ",", "':priority must be an integer from 1-20'", "unless", "PRIORITIES", ".", "include?", "new_val", "@priority", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change the priority field in the JSS @param new_val[Integer] one of PRIORITIES @return [void]
[ "Change", "the", "priority", "field", "in", "the", "JSS" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L485-L491
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.required_processor=
def required_processor=(new_val) return nil if new_val == @required_processor new_val = DEFAULT_PROCESSOR if new_val.to_s.empty? raise JSS::InvalidDataError, "Required_processor must be one of: #{CPU_TYPES.join ', '}" unless CPU_TYPES.include? new_val @required_processor = new_val @need_to_update = true end
ruby
def required_processor=(new_val) return nil if new_val == @required_processor new_val = DEFAULT_PROCESSOR if new_val.to_s.empty? raise JSS::InvalidDataError, "Required_processor must be one of: #{CPU_TYPES.join ', '}" unless CPU_TYPES.include? new_val @required_processor = new_val @need_to_update = true end
[ "def", "required_processor", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@required_processor", "new_val", "=", "DEFAULT_PROCESSOR", "if", "new_val", ".", "to_s", ".", "empty?", "raise", "JSS", "::", "InvalidDataError", ",", "\"Required_processor must be one of: #{CPU_TYPES.join ', '}\"", "unless", "CPU_TYPES", ".", "include?", "new_val", "@required_processor", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change the required processor field in the JSS @param new_val[String] one of {CPU_TYPES} @return [void]
[ "Change", "the", "required", "processor", "field", "in", "the", "JSS" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L513-L521
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.calculate_checksum
def calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true ) type ||= DEFAULT_CHECKSUM_HASH_TYPE mdp = JSS::DistributionPoint.master_distribution_point api: @api if local_file file_to_calc = local_file else if rw_pw dppw = rw_pw mnt = :rw elsif ro_pw dppw = ro_pw mnt = :ro else raise ArgumentError, 'Either rw_pw: or ro_pw: must be provided' end file_to_calc = mdp.mount(dppw, mnt) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}" end new_checksum = self.class.calculate_checksum(file_to_calc, type) mdp.unmount if unmount && mdp.mounted? new_checksum end
ruby
def calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true ) type ||= DEFAULT_CHECKSUM_HASH_TYPE mdp = JSS::DistributionPoint.master_distribution_point api: @api if local_file file_to_calc = local_file else if rw_pw dppw = rw_pw mnt = :rw elsif ro_pw dppw = ro_pw mnt = :ro else raise ArgumentError, 'Either rw_pw: or ro_pw: must be provided' end file_to_calc = mdp.mount(dppw, mnt) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}" end new_checksum = self.class.calculate_checksum(file_to_calc, type) mdp.unmount if unmount && mdp.mounted? new_checksum end
[ "def", "calculate_checksum", "(", "type", ":", "nil", ",", "local_file", ":", "nil", ",", "rw_pw", ":", "nil", ",", "ro_pw", ":", "nil", ",", "unmount", ":", "true", ")", "type", "||=", "DEFAULT_CHECKSUM_HASH_TYPE", "mdp", "=", "JSS", "::", "DistributionPoint", ".", "master_distribution_point", "api", ":", "@api", "if", "local_file", "file_to_calc", "=", "local_file", "else", "if", "rw_pw", "dppw", "=", "rw_pw", "mnt", "=", ":rw", "elsif", "ro_pw", "dppw", "=", "ro_pw", "mnt", "=", ":ro", "else", "raise", "ArgumentError", ",", "'Either rw_pw: or ro_pw: must be provided'", "end", "file_to_calc", "=", "mdp", ".", "mount", "(", "dppw", ",", "mnt", ")", "+", "\"#{DIST_POINT_PKGS_FOLDER}/#{@filename}\"", "end", "new_checksum", "=", "self", ".", "class", ".", "calculate_checksum", "(", "file_to_calc", ",", "type", ")", "mdp", ".", "unmount", "if", "unmount", "&&", "mdp", ".", "mounted?", "new_checksum", "end" ]
Caclulate and return the checksum hash for a given local file, or the file on the master dist point if no local file is given. @param type [String] The checksum hash type, one of the keys of CHECKSUM_HASH_TYPES @param local_file [String, Pathname] A local copy of the pkg file. BE SURE it's identical to the one on the server. If omitted, the master dist. point will be mounted and the file read from there. @param rw_pw [String] The read-write password for mounting the master dist point. Either this or the ro_pw must be provided if no local_file @param ro_pw [String] The read-onlypassword for mounting the master dist point. Either this or the rw_pw must be provided if no local_file @param unmount [Boolean] Unmount the master dist point after using it. Only used if the dist point is mounted. default: true @return [String] The calculated checksum
[ "Caclulate", "and", "return", "the", "checksum", "hash", "for", "a", "given", "local", "file", "or", "the", "file", "on", "the", "master", "dist", "point", "if", "no", "local", "file", "is", "given", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L702-L723
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.checksum_valid?
def checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true) return false unless @checksum new_checksum = calculate_checksum( type: @checksum_type, local_file: local_file, rw_pw: rw_pw, ro_pw: ro_pw, unmount: unmount ) new_checksum == @checksum end
ruby
def checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true) return false unless @checksum new_checksum = calculate_checksum( type: @checksum_type, local_file: local_file, rw_pw: rw_pw, ro_pw: ro_pw, unmount: unmount ) new_checksum == @checksum end
[ "def", "checksum_valid?", "(", "local_file", ":", "nil", ",", "rw_pw", ":", "nil", ",", "ro_pw", ":", "nil", ",", "unmount", ":", "true", ")", "return", "false", "unless", "@checksum", "new_checksum", "=", "calculate_checksum", "(", "type", ":", "@checksum_type", ",", "local_file", ":", "local_file", ",", "rw_pw", ":", "rw_pw", ",", "ro_pw", ":", "ro_pw", ",", "unmount", ":", "unmount", ")", "new_checksum", "==", "@checksum", "end" ]
Is the checksum for this pkg is valid? @param local_file [String, Pathname] A local copy of the pkg file. BE SURE it's identical to the one on the server. If omitted, the master dist. point will be mounted and the file read from there. @param rw_pw [String] The read-write password for mounting the master dist point. Either this or the ro_pw must be provided if no local_file @param ro_pw [String] The read-onlypassword for mounting the master dist point. Either this or the rw_pw must be provided if no local_file @param unmount [Boolean] Unmount the master dist point after using it. Only used if the dist point is mounted. default: true @return [Boolean] false if there is no checksum for this pkg, otherwise, does the calculated checksum match the one stored for the pkg?
[ "Is", "the", "checksum", "for", "this", "pkg", "is", "valid?" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L743-L753
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.update_master_filename
def update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true) raise JSS::NoSuchItemError, "#{old_file_name} does not exist in the jss." unless @in_jss mdp = JSS::DistributionPoint.master_distribution_point api: @api pkgs_dir = mdp.mount(rw_pw, :rw) + DIST_POINT_PKGS_FOLDER.to_s old_file = pkgs_dir + old_file_name raise JSS::NoSuchItemError, "File not found on the master distribution point at #{DIST_POINT_PKGS_FOLDER}/#{old_file_name}." unless \ old_file.exist? new_file = pkgs_dir + new_file_name # use the extension of the original file. new_file = pkgs_dir + (new_file_name + old_file.extname) if new_file.extname.empty? old_file.rename new_file mdp.unmount if unmount nil end
ruby
def update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true) raise JSS::NoSuchItemError, "#{old_file_name} does not exist in the jss." unless @in_jss mdp = JSS::DistributionPoint.master_distribution_point api: @api pkgs_dir = mdp.mount(rw_pw, :rw) + DIST_POINT_PKGS_FOLDER.to_s old_file = pkgs_dir + old_file_name raise JSS::NoSuchItemError, "File not found on the master distribution point at #{DIST_POINT_PKGS_FOLDER}/#{old_file_name}." unless \ old_file.exist? new_file = pkgs_dir + new_file_name # use the extension of the original file. new_file = pkgs_dir + (new_file_name + old_file.extname) if new_file.extname.empty? old_file.rename new_file mdp.unmount if unmount nil end
[ "def", "update_master_filename", "(", "old_file_name", ",", "new_file_name", ",", "rw_pw", ",", "unmount", "=", "true", ")", "raise", "JSS", "::", "NoSuchItemError", ",", "\"#{old_file_name} does not exist in the jss.\"", "unless", "@in_jss", "mdp", "=", "JSS", "::", "DistributionPoint", ".", "master_distribution_point", "api", ":", "@api", "pkgs_dir", "=", "mdp", ".", "mount", "(", "rw_pw", ",", ":rw", ")", "+", "DIST_POINT_PKGS_FOLDER", ".", "to_s", "old_file", "=", "pkgs_dir", "+", "old_file_name", "raise", "JSS", "::", "NoSuchItemError", ",", "\"File not found on the master distribution point at #{DIST_POINT_PKGS_FOLDER}/#{old_file_name}.\"", "unless", "old_file", ".", "exist?", "new_file", "=", "pkgs_dir", "+", "new_file_name", "# use the extension of the original file.", "new_file", "=", "pkgs_dir", "+", "(", "new_file_name", "+", "old_file", ".", "extname", ")", "if", "new_file", ".", "extname", ".", "empty?", "old_file", ".", "rename", "new_file", "mdp", ".", "unmount", "if", "unmount", "nil", "end" ]
Change the name of a package file on the master distribution point. @param new_file_name[String] @param old_file_name[default: @filename, String] @param unmount[Boolean] whether or not ot unount the distribution point when finished. @param rw_pw[String,Symbol] the password for the read/write account on the master Distribution Point, or :prompt, or :stdin# where # is the line of stdin containing the password See {JSS::DistributionPoint#mount} @return [nil]
[ "Change", "the", "name", "of", "a", "package", "file", "on", "the", "master", "distribution", "point", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L768-L783
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.delete
def delete(delete_file: false, rw_pw: nil, unmount: true) super() delete_master_file(rw_pw, unmount) if delete_file end
ruby
def delete(delete_file: false, rw_pw: nil, unmount: true) super() delete_master_file(rw_pw, unmount) if delete_file end
[ "def", "delete", "(", "delete_file", ":", "false", ",", "rw_pw", ":", "nil", ",", "unmount", ":", "true", ")", "super", "(", ")", "delete_master_file", "(", "rw_pw", ",", "unmount", ")", "if", "delete_file", "end" ]
delete master file Delete this package from the JSS, optionally deleting the master dist point file also. @param delete_file[Boolean] should the master dist point file be deleted? @param rw_pw[String] the password for the read/write account on the master Distribution Point or :prompt, or :stdin# where # is the line of stdin containing the password. See {JSS::DistributionPoint#mount} @param unmount[Boolean] whether or not ot unount the distribution point when finished.
[ "delete", "master", "file", "Delete", "this", "package", "from", "the", "JSS", "optionally", "deleting", "the", "master", "dist", "point", "file", "also", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L822-L825
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/package.rb
JSS.Package.uninstall
def uninstall(args = {}) unless removable? raise JSS::UnsupportedError, \ 'This package cannot be uninstalled. Please use CasperAdmin to index it and allow uninstalls' end raise JSS::UnsupportedError, 'You must have root privileges to uninstall packages' unless JSS.superuser? args[:target] ||= '/' # are we doing "fill existing users" or "fill user template"? do_feu = args[:feu] ? '-feu' : '' do_fut = args[:fut] ? '-fut' : '' # use jamf binary to uninstall the pkg jamf_opts = "-target '#{args[:target]}' -id '#{@id}' #{do_feu} #{do_fut}" # run it via a client JSS::Client.run_jamf 'uninstall', jamf_opts, args[:verbose] $CHILD_STATUS end
ruby
def uninstall(args = {}) unless removable? raise JSS::UnsupportedError, \ 'This package cannot be uninstalled. Please use CasperAdmin to index it and allow uninstalls' end raise JSS::UnsupportedError, 'You must have root privileges to uninstall packages' unless JSS.superuser? args[:target] ||= '/' # are we doing "fill existing users" or "fill user template"? do_feu = args[:feu] ? '-feu' : '' do_fut = args[:fut] ? '-fut' : '' # use jamf binary to uninstall the pkg jamf_opts = "-target '#{args[:target]}' -id '#{@id}' #{do_feu} #{do_fut}" # run it via a client JSS::Client.run_jamf 'uninstall', jamf_opts, args[:verbose] $CHILD_STATUS end
[ "def", "uninstall", "(", "args", "=", "{", "}", ")", "unless", "removable?", "raise", "JSS", "::", "UnsupportedError", ",", "'This package cannot be uninstalled. Please use CasperAdmin to index it and allow uninstalls'", "end", "raise", "JSS", "::", "UnsupportedError", ",", "'You must have root privileges to uninstall packages'", "unless", "JSS", ".", "superuser?", "args", "[", ":target", "]", "||=", "'/'", "# are we doing \"fill existing users\" or \"fill user template\"?", "do_feu", "=", "args", "[", ":feu", "]", "?", "'-feu'", ":", "''", "do_fut", "=", "args", "[", ":fut", "]", "?", "'-fut'", ":", "''", "# use jamf binary to uninstall the pkg", "jamf_opts", "=", "\"-target '#{args[:target]}' -id '#{@id}' #{do_feu} #{do_fut}\"", "# run it via a client", "JSS", "::", "Client", ".", "run_jamf", "'uninstall'", ",", "jamf_opts", ",", "args", "[", ":verbose", "]", "$CHILD_STATUS", "end" ]
Uninstall this pkg via the jamf command. @param args[Hash] the arguments for installation @option args :target[String,Pathname] The drive from which to uninstall the package, defaults to '/' @option args :verbose[Boolean] be verbose to stdout, defaults to false @option args :feu[Boolean] fill existing users, defaults to false @option args :fut[Boolean] fill user template, defaults to false @return [Process::Status] the result of the 'jamf uninstall' command @note This code must be run as root to uninstall packages
[ "Uninstall", "this", "pkg", "via", "the", "jamf", "command", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/package.rb#L959-L978
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/distribution_point.rb
JSS.DistributionPoint.rest_xml
def rest_xml doc = REXML::Document.new dp = doc.add_element "distribution_point" dp.add_element(:name.to_s).text = @name dp.add_element(:ip_address.to_s).text = @ip_address dp.add_element(:local_path.to_s).text = @local_path dp.add_element(:enable_load_balancing.to_s).text = @enable_load_balancing dp.add_element(:failover_point.to_s).text = @failover_point dp.add_element(:is_master.to_s).text = @is_master dp.add_element(:connection_type.to_s).text = @connection_type dp.add_element(:share_port.to_s).text = @share_port dp.add_element(:share_name.to_s).text = @share_name dp.add_element(:read_write_username.to_s).text = @read_write_username dp.add_element(:read_write_password.to_s).text = @read_write_password dp.add_element(:read_only_username.to_s).text = @read_only_username dp.add_element(:read_only_password.to_s).text = @read_only_password dp.add_element(:workgroup_or_domain.to_s).text = @workgroup_or_domain dp.add_element(:http_downloads_enabled.to_s).text = @http_downloads_enabled dp.add_element(:protocol.to_s).text = @protocol dp.add_element(:port.to_s).text = @port dp.add_element(:context.to_s).text = @context dp.add_element(:no_authentication_required.to_s).text = @no_authentication_required dp.add_element(:certificate_required.to_s).text = @certificate_required dp.add_element(:username_password_required.to_s).text = @username_password_required dp.add_element(:http_username.to_s).text = @http_username dp.add_element(:certificate.to_s).text = @certificate dp.add_element(:http_url.to_s).text = @http_url dp.add_element(:failover_point_url.to_s).text = @failover_point_url dp.add_element(:ssh_username.to_s).text = @ssh_username dp.add_element(:ssh_password.to_s).text = @ssh_password if @ssh_password return doc.to_s end
ruby
def rest_xml doc = REXML::Document.new dp = doc.add_element "distribution_point" dp.add_element(:name.to_s).text = @name dp.add_element(:ip_address.to_s).text = @ip_address dp.add_element(:local_path.to_s).text = @local_path dp.add_element(:enable_load_balancing.to_s).text = @enable_load_balancing dp.add_element(:failover_point.to_s).text = @failover_point dp.add_element(:is_master.to_s).text = @is_master dp.add_element(:connection_type.to_s).text = @connection_type dp.add_element(:share_port.to_s).text = @share_port dp.add_element(:share_name.to_s).text = @share_name dp.add_element(:read_write_username.to_s).text = @read_write_username dp.add_element(:read_write_password.to_s).text = @read_write_password dp.add_element(:read_only_username.to_s).text = @read_only_username dp.add_element(:read_only_password.to_s).text = @read_only_password dp.add_element(:workgroup_or_domain.to_s).text = @workgroup_or_domain dp.add_element(:http_downloads_enabled.to_s).text = @http_downloads_enabled dp.add_element(:protocol.to_s).text = @protocol dp.add_element(:port.to_s).text = @port dp.add_element(:context.to_s).text = @context dp.add_element(:no_authentication_required.to_s).text = @no_authentication_required dp.add_element(:certificate_required.to_s).text = @certificate_required dp.add_element(:username_password_required.to_s).text = @username_password_required dp.add_element(:http_username.to_s).text = @http_username dp.add_element(:certificate.to_s).text = @certificate dp.add_element(:http_url.to_s).text = @http_url dp.add_element(:failover_point_url.to_s).text = @failover_point_url dp.add_element(:ssh_username.to_s).text = @ssh_username dp.add_element(:ssh_password.to_s).text = @ssh_password if @ssh_password return doc.to_s end
[ "def", "rest_xml", "doc", "=", "REXML", "::", "Document", ".", "new", "dp", "=", "doc", ".", "add_element", "\"distribution_point\"", "dp", ".", "add_element", "(", ":name", ".", "to_s", ")", ".", "text", "=", "@name", "dp", ".", "add_element", "(", ":ip_address", ".", "to_s", ")", ".", "text", "=", "@ip_address", "dp", ".", "add_element", "(", ":local_path", ".", "to_s", ")", ".", "text", "=", "@local_path", "dp", ".", "add_element", "(", ":enable_load_balancing", ".", "to_s", ")", ".", "text", "=", "@enable_load_balancing", "dp", ".", "add_element", "(", ":failover_point", ".", "to_s", ")", ".", "text", "=", "@failover_point", "dp", ".", "add_element", "(", ":is_master", ".", "to_s", ")", ".", "text", "=", "@is_master", "dp", ".", "add_element", "(", ":connection_type", ".", "to_s", ")", ".", "text", "=", "@connection_type", "dp", ".", "add_element", "(", ":share_port", ".", "to_s", ")", ".", "text", "=", "@share_port", "dp", ".", "add_element", "(", ":share_name", ".", "to_s", ")", ".", "text", "=", "@share_name", "dp", ".", "add_element", "(", ":read_write_username", ".", "to_s", ")", ".", "text", "=", "@read_write_username", "dp", ".", "add_element", "(", ":read_write_password", ".", "to_s", ")", ".", "text", "=", "@read_write_password", "dp", ".", "add_element", "(", ":read_only_username", ".", "to_s", ")", ".", "text", "=", "@read_only_username", "dp", ".", "add_element", "(", ":read_only_password", ".", "to_s", ")", ".", "text", "=", "@read_only_password", "dp", ".", "add_element", "(", ":workgroup_or_domain", ".", "to_s", ")", ".", "text", "=", "@workgroup_or_domain", "dp", ".", "add_element", "(", ":http_downloads_enabled", ".", "to_s", ")", ".", "text", "=", "@http_downloads_enabled", "dp", ".", "add_element", "(", ":protocol", ".", "to_s", ")", ".", "text", "=", "@protocol", "dp", ".", "add_element", "(", ":port", ".", "to_s", ")", ".", "text", "=", "@port", "dp", ".", "add_element", "(", ":context", ".", "to_s", ")", ".", "text", "=", "@context", "dp", ".", "add_element", "(", ":no_authentication_required", ".", "to_s", ")", ".", "text", "=", "@no_authentication_required", "dp", ".", "add_element", "(", ":certificate_required", ".", "to_s", ")", ".", "text", "=", "@certificate_required", "dp", ".", "add_element", "(", ":username_password_required", ".", "to_s", ")", ".", "text", "=", "@username_password_required", "dp", ".", "add_element", "(", ":http_username", ".", "to_s", ")", ".", "text", "=", "@http_username", "dp", ".", "add_element", "(", ":certificate", ".", "to_s", ")", ".", "text", "=", "@certificate", "dp", ".", "add_element", "(", ":http_url", ".", "to_s", ")", ".", "text", "=", "@http_url", "dp", ".", "add_element", "(", ":failover_point_url", ".", "to_s", ")", ".", "text", "=", "@failover_point_url", "dp", ".", "add_element", "(", ":ssh_username", ".", "to_s", ")", ".", "text", "=", "@ssh_username", "dp", ".", "add_element", "(", ":ssh_password", ".", "to_s", ")", ".", "text", "=", "@ssh_password", "if", "@ssh_password", "return", "doc", ".", "to_s", "end" ]
Unused - until I get around to making DP's updatable the XML representation of the current state of this object, for POSTing or PUTting back to the JSS via the API Will be supported for Dist Points some day, I'm sure.
[ "Unused", "-", "until", "I", "get", "around", "to", "making", "DP", "s", "updatable" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/distribution_point.rb#L503-L538
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/webhook.rb
JSS.WebHook.event=
def event=(new_val) return nil if new_val == @event raise JSS::InvalidDataError, 'Unknown webhook event' unless EVENTS.include? new_val @event = new_val @need_to_update = true end
ruby
def event=(new_val) return nil if new_val == @event raise JSS::InvalidDataError, 'Unknown webhook event' unless EVENTS.include? new_val @event = new_val @need_to_update = true end
[ "def", "event", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@event", "raise", "JSS", "::", "InvalidDataError", ",", "'Unknown webhook event'", "unless", "EVENTS", ".", "include?", "new_val", "@event", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set the event handled by this webhook Must be a member of the EVENTS Array @param new_val[String] The event name @return [void]
[ "Set", "the", "event", "handled", "by", "this", "webhook", "Must", "be", "a", "member", "of", "the", "EVENTS", "Array" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/webhook.rb#L185-L190
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/webhook.rb
JSS.WebHook.rest_xml
def rest_xml validate_before_save doc = REXML::Document.new APIConnection::XML_HEADER webhook = doc.add_element 'webhook' webhook.add_element('name').text = @name webhook.add_element('enabled').text = @enabled webhook.add_element('url').text = @url webhook.add_element('content_type').text = CONTENT_TYPES[@content_type] webhook.add_element('event').text = @event doc.to_s end
ruby
def rest_xml validate_before_save doc = REXML::Document.new APIConnection::XML_HEADER webhook = doc.add_element 'webhook' webhook.add_element('name').text = @name webhook.add_element('enabled').text = @enabled webhook.add_element('url').text = @url webhook.add_element('content_type').text = CONTENT_TYPES[@content_type] webhook.add_element('event').text = @event doc.to_s end
[ "def", "rest_xml", "validate_before_save", "doc", "=", "REXML", "::", "Document", ".", "new", "APIConnection", "::", "XML_HEADER", "webhook", "=", "doc", ".", "add_element", "'webhook'", "webhook", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "@name", "webhook", ".", "add_element", "(", "'enabled'", ")", ".", "text", "=", "@enabled", "webhook", ".", "add_element", "(", "'url'", ")", ".", "text", "=", "@url", "webhook", ".", "add_element", "(", "'content_type'", ")", ".", "text", "=", "CONTENT_TYPES", "[", "@content_type", "]", "webhook", ".", "add_element", "(", "'event'", ")", ".", "text", "=", "@event", "doc", ".", "to_s", "end" ]
Return the REST XML for this webhook, with the current values, for saving or updating
[ "Return", "the", "REST", "XML", "for", "this", "webhook", "with", "the", "current", "values", "for", "saving", "or", "updating" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/webhook.rb#L228-L238
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/computer_invitation.rb
JSS.ComputerInvitation.create
def create new_invitation_id = super jss_me = ComputerInvitation.fetch(id: new_invitation_id, name: 'set_by_request') @name = jss_me.name @invitation_type = jss_me.invitation_type @create_account_if_does_not_exist = jss_me.create_account_if_does_not_exist @expiration_date_epoch = jss_me.expiration_date_epoch @ssh_username = jss_me.ssh_username @hide_account = jss_me.hide_account @invitation_status = jss_me.invitation_status @multiple_uses_allowed = jss_me.multiple_uses_allowed end
ruby
def create new_invitation_id = super jss_me = ComputerInvitation.fetch(id: new_invitation_id, name: 'set_by_request') @name = jss_me.name @invitation_type = jss_me.invitation_type @create_account_if_does_not_exist = jss_me.create_account_if_does_not_exist @expiration_date_epoch = jss_me.expiration_date_epoch @ssh_username = jss_me.ssh_username @hide_account = jss_me.hide_account @invitation_status = jss_me.invitation_status @multiple_uses_allowed = jss_me.multiple_uses_allowed end
[ "def", "create", "new_invitation_id", "=", "super", "jss_me", "=", "ComputerInvitation", ".", "fetch", "(", "id", ":", "new_invitation_id", ",", "name", ":", "'set_by_request'", ")", "@name", "=", "jss_me", ".", "name", "@invitation_type", "=", "jss_me", ".", "invitation_type", "@create_account_if_does_not_exist", "=", "jss_me", ".", "create_account_if_does_not_exist", "@expiration_date_epoch", "=", "jss_me", ".", "expiration_date_epoch", "@ssh_username", "=", "jss_me", ".", "ssh_username", "@hide_account", "=", "jss_me", ".", "hide_account", "@invitation_status", "=", "jss_me", ".", "invitation_status", "@multiple_uses_allowed", "=", "jss_me", ".", "multiple_uses_allowed", "end" ]
Public Instance Methods @see APIObject#initialize Public Class Methods Needed to support creation of new Computer Invitations to set their name. @return [JSS::ComputerInvitation]
[ "Public", "Instance", "Methods" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/computer_invitation.rb#L172-L184
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/computer_invitation.rb
JSS.ComputerInvitation.rest_xml
def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER obj = doc.add_element RSRC_OBJECT_KEY.to_s obj.add_element('invitation_type').text = invitation_type obj.add_element('create_account_if_does_not_exist').text = create_account_if_does_not_exist if expiration_date_epoch obj.add_element('expiration_date_epoch').text = expiration_date_epoch end obj.add_element('ssh_username').text = ssh_username obj.add_element('hide_account').text = hide_account obj.add_element('invitation_status').text = invitation_status obj.add_element('multiple_uses_allowed').text = multiple_uses_allowed add_site_to_xml(doc) doc.to_s end
ruby
def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER obj = doc.add_element RSRC_OBJECT_KEY.to_s obj.add_element('invitation_type').text = invitation_type obj.add_element('create_account_if_does_not_exist').text = create_account_if_does_not_exist if expiration_date_epoch obj.add_element('expiration_date_epoch').text = expiration_date_epoch end obj.add_element('ssh_username').text = ssh_username obj.add_element('hide_account').text = hide_account obj.add_element('invitation_status').text = invitation_status obj.add_element('multiple_uses_allowed').text = multiple_uses_allowed add_site_to_xml(doc) doc.to_s end
[ "def", "rest_xml", "doc", "=", "REXML", "::", "Document", ".", "new", "APIConnection", "::", "XML_HEADER", "obj", "=", "doc", ".", "add_element", "RSRC_OBJECT_KEY", ".", "to_s", "obj", ".", "add_element", "(", "'invitation_type'", ")", ".", "text", "=", "invitation_type", "obj", ".", "add_element", "(", "'create_account_if_does_not_exist'", ")", ".", "text", "=", "create_account_if_does_not_exist", "if", "expiration_date_epoch", "obj", ".", "add_element", "(", "'expiration_date_epoch'", ")", ".", "text", "=", "expiration_date_epoch", "end", "obj", ".", "add_element", "(", "'ssh_username'", ")", ".", "text", "=", "ssh_username", "obj", ".", "add_element", "(", "'hide_account'", ")", ".", "text", "=", "hide_account", "obj", ".", "add_element", "(", "'invitation_status'", ")", ".", "text", "=", "invitation_status", "obj", ".", "add_element", "(", "'multiple_uses_allowed'", ")", ".", "text", "=", "multiple_uses_allowed", "add_site_to_xml", "(", "doc", ")", "doc", ".", "to_s", "end" ]
Sets invitation expiration 4 hours after request.
[ "Sets", "invitation", "expiration", "4", "hours", "after", "request", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/computer_invitation.rb#L192-L206
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable/icon.rb
JSS.Icon.save
def save(path, overwrite = false) path = Pathname.new path path = path + @name if path.directory? && @name raise JSS::AlreadyExistsError, "The file #{path} already exists" if path.exist? unless overwrite path.delete if path.exist? path.jss_save @data end
ruby
def save(path, overwrite = false) path = Pathname.new path path = path + @name if path.directory? && @name raise JSS::AlreadyExistsError, "The file #{path} already exists" if path.exist? unless overwrite path.delete if path.exist? path.jss_save @data end
[ "def", "save", "(", "path", ",", "overwrite", "=", "false", ")", "path", "=", "Pathname", ".", "new", "path", "path", "=", "path", "+", "@name", "if", "path", ".", "directory?", "&&", "@name", "raise", "JSS", "::", "AlreadyExistsError", ",", "\"The file #{path} already exists\"", "if", "path", ".", "exist?", "unless", "overwrite", "path", ".", "delete", "if", "path", ".", "exist?", "path", ".", "jss_save", "@data", "end" ]
Save the icon to a file. @param path[Pathname, String] The path to which the file should be saved. If the path given is an existing directory, the icon's current filename will be used, if known. @param overwrite[Boolean] Overwrite the file if it exists? Defaults to false @return [void]
[ "Save", "the", "icon", "to", "a", "file", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable/icon.rb#L177-L184
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/categorizable.rb
JSS.Categorizable.category=
def category=(new_cat) return nil unless updatable? || creatable? # unset the category? Use nil or an empty string if NON_CATEGORIES.include? new_cat unset_category return end new_name, new_id = evaluate_new_category(new_cat) # no change, go home. return nil if new_name == @category_name raise JSS::NoSuchItemError, "Category '#{new_cat}' is not known to the JSS" unless JSS::Category.all_names(:ref, api: @api).include? new_name @category_name = new_name @category_id = new_id @need_to_update = true end
ruby
def category=(new_cat) return nil unless updatable? || creatable? # unset the category? Use nil or an empty string if NON_CATEGORIES.include? new_cat unset_category return end new_name, new_id = evaluate_new_category(new_cat) # no change, go home. return nil if new_name == @category_name raise JSS::NoSuchItemError, "Category '#{new_cat}' is not known to the JSS" unless JSS::Category.all_names(:ref, api: @api).include? new_name @category_name = new_name @category_id = new_id @need_to_update = true end
[ "def", "category", "=", "(", "new_cat", ")", "return", "nil", "unless", "updatable?", "||", "creatable?", "# unset the category? Use nil or an empty string", "if", "NON_CATEGORIES", ".", "include?", "new_cat", "unset_category", "return", "end", "new_name", ",", "new_id", "=", "evaluate_new_category", "(", "new_cat", ")", "# no change, go home.", "return", "nil", "if", "new_name", "==", "@category_name", "raise", "JSS", "::", "NoSuchItemError", ",", "\"Category '#{new_cat}' is not known to the JSS\"", "unless", "JSS", "::", "Category", ".", "all_names", "(", ":ref", ",", "api", ":", "@api", ")", ".", "include?", "new_name", "@category_name", "=", "new_name", "@category_id", "=", "new_id", "@need_to_update", "=", "true", "end" ]
Change the category of this object. Any of the NON_CATEGORIES values will unset the category @param new_cat[Integer, String] The new category @return [void]
[ "Change", "the", "category", "of", "this", "object", ".", "Any", "of", "the", "NON_CATEGORIES", "values", "will", "unset", "the", "category" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/categorizable.rb#L132-L151
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/categorizable.rb
JSS.Categorizable.parse_category
def parse_category cat = if self.class::CATEGORY_SUBSET == :top @init_data[:category] else @init_data[self.class::CATEGORY_SUBSET][:category] end if cat.is_a? String @category_name = cat @category_id = JSS::Category.category_id_from_name @category_name else @category_name = cat[:name] @category_id = cat[:id] end clean_raw_categories end
ruby
def parse_category cat = if self.class::CATEGORY_SUBSET == :top @init_data[:category] else @init_data[self.class::CATEGORY_SUBSET][:category] end if cat.is_a? String @category_name = cat @category_id = JSS::Category.category_id_from_name @category_name else @category_name = cat[:name] @category_id = cat[:id] end clean_raw_categories end
[ "def", "parse_category", "cat", "=", "if", "self", ".", "class", "::", "CATEGORY_SUBSET", "==", ":top", "@init_data", "[", ":category", "]", "else", "@init_data", "[", "self", ".", "class", "::", "CATEGORY_SUBSET", "]", "[", ":category", "]", "end", "if", "cat", ".", "is_a?", "String", "@category_name", "=", "cat", "@category_id", "=", "JSS", "::", "Category", ".", "category_id_from_name", "@category_name", "else", "@category_name", "=", "cat", "[", ":name", "]", "@category_id", "=", "cat", "[", ":id", "]", "end", "clean_raw_categories", "end" ]
Parse the category data from any incoming API data @return [void] description_of_returned_object
[ "Parse", "the", "category", "data", "from", "any", "incoming", "API", "data" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/categorizable.rb#L191-L207
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/categorizable.rb
JSS.Categorizable.add_category_to_xml
def add_category_to_xml(xmldoc) return if category_name.to_s.empty? cat_elem = REXML::Element.new('category') if self.class::CATEGORY_DATA_TYPE == String cat_elem.text = @category_name.to_s elsif self.class::CATEGORY_DATA_TYPE == Hash cat_elem.add_element('name').text = @category_name.to_s else raise JSS::InvalidDataError, "Uknown CATEGORY_DATA_TYPE for class #{self.class}" end root = xmldoc.root if self.class::CATEGORY_SUBSET == :top root.add_element cat_elem return end parent = root.elements[self.class::CATEGORY_SUBSET.to_s] parent ||= root.add_element self.class::CATEGORY_SUBSET.to_s parent.add_element cat_elem end
ruby
def add_category_to_xml(xmldoc) return if category_name.to_s.empty? cat_elem = REXML::Element.new('category') if self.class::CATEGORY_DATA_TYPE == String cat_elem.text = @category_name.to_s elsif self.class::CATEGORY_DATA_TYPE == Hash cat_elem.add_element('name').text = @category_name.to_s else raise JSS::InvalidDataError, "Uknown CATEGORY_DATA_TYPE for class #{self.class}" end root = xmldoc.root if self.class::CATEGORY_SUBSET == :top root.add_element cat_elem return end parent = root.elements[self.class::CATEGORY_SUBSET.to_s] parent ||= root.add_element self.class::CATEGORY_SUBSET.to_s parent.add_element cat_elem end
[ "def", "add_category_to_xml", "(", "xmldoc", ")", "return", "if", "category_name", ".", "to_s", ".", "empty?", "cat_elem", "=", "REXML", "::", "Element", ".", "new", "(", "'category'", ")", "if", "self", ".", "class", "::", "CATEGORY_DATA_TYPE", "==", "String", "cat_elem", ".", "text", "=", "@category_name", ".", "to_s", "elsif", "self", ".", "class", "::", "CATEGORY_DATA_TYPE", "==", "Hash", "cat_elem", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "@category_name", ".", "to_s", "else", "raise", "JSS", "::", "InvalidDataError", ",", "\"Uknown CATEGORY_DATA_TYPE for class #{self.class}\"", "end", "root", "=", "xmldoc", ".", "root", "if", "self", ".", "class", "::", "CATEGORY_SUBSET", "==", ":top", "root", ".", "add_element", "cat_elem", "return", "end", "parent", "=", "root", ".", "elements", "[", "self", ".", "class", "::", "CATEGORY_SUBSET", ".", "to_s", "]", "parent", "||=", "root", ".", "add_element", "self", ".", "class", "::", "CATEGORY_SUBSET", ".", "to_s", "parent", ".", "add_element", "cat_elem", "end" ]
Add the category to the XML for POSTing or PUTting to the API. @param xmldoc[REXML::Document] The in-construction XML document @return [void]
[ "Add", "the", "category", "to", "the", "XML", "for", "POSTing", "or", "PUTting", "to", "the", "API", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/categorizable.rb#L221-L243
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/scopable.rb
JSS.Scopable.scope=
def scope= (new_scope) raise JSS::InvalidDataError, "JSS::Scopable::Scope instance required" unless new_criteria.kind_of?(JSS::Scopable::Scope) raise JSS::InvalidDataError, "Scope object must have target_key of :#{self.class::SCOPE_TARGET_KEY}" unless self.class::SCOPE_TARGET_KEY == new_scope.target_key @scope = new_scope @need_to_update = true end
ruby
def scope= (new_scope) raise JSS::InvalidDataError, "JSS::Scopable::Scope instance required" unless new_criteria.kind_of?(JSS::Scopable::Scope) raise JSS::InvalidDataError, "Scope object must have target_key of :#{self.class::SCOPE_TARGET_KEY}" unless self.class::SCOPE_TARGET_KEY == new_scope.target_key @scope = new_scope @need_to_update = true end
[ "def", "scope", "=", "(", "new_scope", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"JSS::Scopable::Scope instance required\"", "unless", "new_criteria", ".", "kind_of?", "(", "JSS", "::", "Scopable", "::", "Scope", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"Scope object must have target_key of :#{self.class::SCOPE_TARGET_KEY}\"", "unless", "self", ".", "class", "::", "SCOPE_TARGET_KEY", "==", "new_scope", ".", "target_key", "@scope", "=", "new_scope", "@need_to_update", "=", "true", "end" ]
Change the scope @param new_scope[JSS::Scopable::Scope] the new scope @return [void]
[ "Change", "the", "scope" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/scopable.rb#L98-L103
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mdm.rb
JSS.MDM.erase_device
def erase_device(passcode = '', preserve_data_plan: false) self.class.erase_device @id, passcode: passcode, preserve_data_plan: preserve_data_plan, api: @api end
ruby
def erase_device(passcode = '', preserve_data_plan: false) self.class.erase_device @id, passcode: passcode, preserve_data_plan: preserve_data_plan, api: @api end
[ "def", "erase_device", "(", "passcode", "=", "''", ",", "preserve_data_plan", ":", "false", ")", "self", ".", "class", ".", "erase_device", "@id", ",", "passcode", ":", "passcode", ",", "preserve_data_plan", ":", "preserve_data_plan", ",", "api", ":", "@api", "end" ]
Send an erase device command to this object @param passcode[String] a six-char passcode, required for computers & computergroups @return (see .send_mdm_command)
[ "Send", "an", "erase", "device", "command", "to", "this", "object" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mdm.rb#L1033-L1035
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mdm.rb
JSS.MDM.wallpaper
def wallpaper(wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil) self.class.wallpaper( @id, wallpaper_setting: wallpaper_setting, wallpaper_content: wallpaper_content, wallpaper_id: wallpaper_id, api: @api ) end
ruby
def wallpaper(wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil) self.class.wallpaper( @id, wallpaper_setting: wallpaper_setting, wallpaper_content: wallpaper_content, wallpaper_id: wallpaper_id, api: @api ) end
[ "def", "wallpaper", "(", "wallpaper_setting", ":", "nil", ",", "wallpaper_content", ":", "nil", ",", "wallpaper_id", ":", "nil", ")", "self", ".", "class", ".", "wallpaper", "(", "@id", ",", "wallpaper_setting", ":", "wallpaper_setting", ",", "wallpaper_content", ":", "wallpaper_content", ",", "wallpaper_id", ":", "wallpaper_id", ",", "api", ":", "@api", ")", "end" ]
Send a wallpaper command to this object @param wallpaper_setting[Symbol] :lock_screen, :home_screen, or :lock_and_home_screen @param wallpaper_content[String,Pathname] The local path to a .png or .jpg to use as the walpaper image, required if no wallpaper_id @param wallpaper_id[Symbol] The id of an Icon in Jamf Pro to use as the wallpaper image, required if no wallpaper_content @return (see .send_mdm_command)
[ "Send", "a", "wallpaper", "command", "to", "this", "object" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mdm.rb#L1171-L1179
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mdm.rb
JSS.MDM.enable_lost_mode
def enable_lost_mode( message: nil, phone_number: nil, footnote: nil, enforce_lost_mode: true, play_sound: false ) self.class.enable_lost_mode( @id, message: message, phone_number: phone_number, footnote: footnote, play_sound: play_sound, enforce_lost_mode: enforce_lost_mode, api: @api ) end
ruby
def enable_lost_mode( message: nil, phone_number: nil, footnote: nil, enforce_lost_mode: true, play_sound: false ) self.class.enable_lost_mode( @id, message: message, phone_number: phone_number, footnote: footnote, play_sound: play_sound, enforce_lost_mode: enforce_lost_mode, api: @api ) end
[ "def", "enable_lost_mode", "(", "message", ":", "nil", ",", "phone_number", ":", "nil", ",", "footnote", ":", "nil", ",", "enforce_lost_mode", ":", "true", ",", "play_sound", ":", "false", ")", "self", ".", "class", ".", "enable_lost_mode", "(", "@id", ",", "message", ":", "message", ",", "phone_number", ":", "phone_number", ",", "footnote", ":", "footnote", ",", "play_sound", ":", "play_sound", ",", "enforce_lost_mode", ":", "enforce_lost_mode", ",", "api", ":", "@api", ")", "end" ]
Send a enable_lost_mode command to one or more targets Either or both of message and phone number must be provided @param message[String] The message to display on the lock screen @param phone_number[String] The phone number to display on the lock screen @param footnote[String] Optional footnote to display on the lock screen @param play_sound[Boolean] Play a sound when entering lost mode @param enforce_lost_mode[Boolean] Re-enabled lost mode when re-enrolled after wipe. @return (see .send_mdm_command)
[ "Send", "a", "enable_lost_mode", "command", "to", "one", "or", "more", "targets" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mdm.rb#L1260-L1276
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.frequency=
def frequency=(freq) raise JSS::InvalidDataError, "New frequency must be one of :#{FREQUENCIES.keys.join ', :'}" unless FREQUENCIES.key?(freq) @frequency = FREQUENCIES[freq] @need_to_update = true end
ruby
def frequency=(freq) raise JSS::InvalidDataError, "New frequency must be one of :#{FREQUENCIES.keys.join ', :'}" unless FREQUENCIES.key?(freq) @frequency = FREQUENCIES[freq] @need_to_update = true end
[ "def", "frequency", "=", "(", "freq", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"New frequency must be one of :#{FREQUENCIES.keys.join ', :'}\"", "unless", "FREQUENCIES", ".", "key?", "(", "freq", ")", "@frequency", "=", "FREQUENCIES", "[", "freq", "]", "@need_to_update", "=", "true", "end" ]
Set a new frequency for this policy. @param freq[Symbol] the desired frequency, must be one of the keys of {FREQUENCIES} @return [void]
[ "Set", "a", "new", "frequency", "for", "this", "policy", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L718-L722
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.target_drive=
def target_drive=(path_to_drive) raise JSS::InvalidDataError, 'Path to target drive must be absolute' unless path_to_drive.to_s.start_with? '/' @target_drive = path_to_drive.to_s @need_to_update = true end
ruby
def target_drive=(path_to_drive) raise JSS::InvalidDataError, 'Path to target drive must be absolute' unless path_to_drive.to_s.start_with? '/' @target_drive = path_to_drive.to_s @need_to_update = true end
[ "def", "target_drive", "=", "(", "path_to_drive", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Path to target drive must be absolute'", "unless", "path_to_drive", ".", "to_s", ".", "start_with?", "'/'", "@target_drive", "=", "path_to_drive", ".", "to_s", "@need_to_update", "=", "true", "end" ]
Set a new target drive for this policy. @param path_to_drive[String,Pathname] the full path to the target drive, must start with a '/' @return [void]
[ "Set", "a", "new", "target", "drive", "for", "this", "policy", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L730-L734
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.offline=
def offline=(new_val) raise JSS::InvalidDataError, 'New value must be boolean true or false' unless JSS::TRUE_FALSE.include? new_val @offline = new_val @need_to_update = true end
ruby
def offline=(new_val) raise JSS::InvalidDataError, 'New value must be boolean true or false' unless JSS::TRUE_FALSE.include? new_val @offline = new_val @need_to_update = true end
[ "def", "offline", "=", "(", "new_val", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be boolean true or false'", "unless", "JSS", "::", "TRUE_FALSE", ".", "include?", "new_val", "@offline", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether this policy is available offline. @param new_val[Boolean] @return [void]
[ "Set", "whether", "this", "policy", "is", "available", "offline", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L742-L746
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.set_trigger_event
def set_trigger_event(type, new_val) raise JSS::InvalidDataError, "Trigger type must be one of #{TRIGGER_EVENTS.keys.join(', ')}" unless TRIGGER_EVENTS.key?(type) if type == :custom raise JSS::InvalidDataError, 'Custom triggers must be Strings' unless new_val.is_a? String else raise JSS::InvalidDataError, 'Non-custom triggers must be true or false' unless JSS::TRUE_FALSE.include? new_val end @trigger_events[TRIGGER_EVENTS[type]] = new_val @need_to_update = true end
ruby
def set_trigger_event(type, new_val) raise JSS::InvalidDataError, "Trigger type must be one of #{TRIGGER_EVENTS.keys.join(', ')}" unless TRIGGER_EVENTS.key?(type) if type == :custom raise JSS::InvalidDataError, 'Custom triggers must be Strings' unless new_val.is_a? String else raise JSS::InvalidDataError, 'Non-custom triggers must be true or false' unless JSS::TRUE_FALSE.include? new_val end @trigger_events[TRIGGER_EVENTS[type]] = new_val @need_to_update = true end
[ "def", "set_trigger_event", "(", "type", ",", "new_val", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"Trigger type must be one of #{TRIGGER_EVENTS.keys.join(', ')}\"", "unless", "TRIGGER_EVENTS", ".", "key?", "(", "type", ")", "if", "type", "==", ":custom", "raise", "JSS", "::", "InvalidDataError", ",", "'Custom triggers must be Strings'", "unless", "new_val", ".", "is_a?", "String", "else", "raise", "JSS", "::", "InvalidDataError", ",", "'Non-custom triggers must be true or false'", "unless", "JSS", "::", "TRUE_FALSE", ".", "include?", "new_val", "end", "@trigger_events", "[", "TRIGGER_EVENTS", "[", "type", "]", "]", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change a trigger event @param type[Symbol] the type of trigger, one of the keys of {TRIGGER_EVENTS} @param new_val[Boolean] whether the type of trigger is active or not. @return [void]
[ "Change", "a", "trigger", "event" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L756-L765
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.server_side_activation=
def server_side_activation=(activation) raise JSS::InvalidDataError, 'Activation must be a Time' unless activation.is_a? Time @server_side_limitations[:activation] = activation @need_to_update = true end
ruby
def server_side_activation=(activation) raise JSS::InvalidDataError, 'Activation must be a Time' unless activation.is_a? Time @server_side_limitations[:activation] = activation @need_to_update = true end
[ "def", "server_side_activation", "=", "(", "activation", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Activation must be a Time'", "unless", "activation", ".", "is_a?", "Time", "@server_side_limitations", "[", ":activation", "]", "=", "activation", "@need_to_update", "=", "true", "end" ]
Set Server Side Activation @param activation[Time] Activation date and time @return [void]
[ "Set", "Server", "Side", "Activation" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L773-L777
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.server_side_expiration=
def server_side_expiration=(expiration) raise JSS::InvalidDataError, 'Expiration must be a Time' unless expiration.is_a? Time @server_side_limitations[:expiration] = expiration @need_to_update = true end
ruby
def server_side_expiration=(expiration) raise JSS::InvalidDataError, 'Expiration must be a Time' unless expiration.is_a? Time @server_side_limitations[:expiration] = expiration @need_to_update = true end
[ "def", "server_side_expiration", "=", "(", "expiration", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Expiration must be a Time'", "unless", "expiration", ".", "is_a?", "Time", "@server_side_limitations", "[", ":expiration", "]", "=", "expiration", "@need_to_update", "=", "true", "end" ]
Set Server Side Expiration @param expiration[Time] Expiration date and time @return [void]
[ "Set", "Server", "Side", "Expiration" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L785-L789
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.user_logged_in=
def user_logged_in=(logged_in_option) raise JSS::InvalidDataError, "user_logged_in options: #{USER_LOGGED_IN.join(', ')}" unless USER_LOGGED_IN.include? logged_in_option @reboot_options[:user_logged_in] = logged_in_option @need_to_update = true end
ruby
def user_logged_in=(logged_in_option) raise JSS::InvalidDataError, "user_logged_in options: #{USER_LOGGED_IN.join(', ')}" unless USER_LOGGED_IN.include? logged_in_option @reboot_options[:user_logged_in] = logged_in_option @need_to_update = true end
[ "def", "user_logged_in", "=", "(", "logged_in_option", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"user_logged_in options: #{USER_LOGGED_IN.join(', ')}\"", "unless", "USER_LOGGED_IN", ".", "include?", "logged_in_option", "@reboot_options", "[", ":user_logged_in", "]", "=", "logged_in_option", "@need_to_update", "=", "true", "end" ]
What to do at reboot when there is a User Logged In @param logged_in_option[String] Any one of the Strings from USER_LOGGED_IN @return [void]
[ "What", "to", "do", "at", "reboot", "when", "there", "is", "a", "User", "Logged", "In" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L879-L883
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.reboot_message=
def reboot_message=(message) raise JSS::InvalidDataError, 'Reboot message must be a String' unless message.is_a? String @reboot_options[:message] = message @need_to_update = true end
ruby
def reboot_message=(message) raise JSS::InvalidDataError, 'Reboot message must be a String' unless message.is_a? String @reboot_options[:message] = message @need_to_update = true end
[ "def", "reboot_message", "=", "(", "message", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Reboot message must be a String'", "unless", "message", ".", "is_a?", "String", "@reboot_options", "[", ":message", "]", "=", "message", "@need_to_update", "=", "true", "end" ]
Set Reboot Message @param reboot_message[String] Text of Reboot Message @return [void] description of returned object
[ "Set", "Reboot", "Message" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L891-L895
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.startup_disk=
def startup_disk=(startup_disk_option) raise JSS::InvalidDataError, "#{startup_disk_option} is not a valid Startup Disk" unless startup_disk_option.is_a? String @reboot_options[:startup_disk] = 'Specify Local Startup Disk' self.specify_startup = startup_disk_option @need_to_update = true end
ruby
def startup_disk=(startup_disk_option) raise JSS::InvalidDataError, "#{startup_disk_option} is not a valid Startup Disk" unless startup_disk_option.is_a? String @reboot_options[:startup_disk] = 'Specify Local Startup Disk' self.specify_startup = startup_disk_option @need_to_update = true end
[ "def", "startup_disk", "=", "(", "startup_disk_option", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"#{startup_disk_option} is not a valid Startup Disk\"", "unless", "startup_disk_option", ".", "is_a?", "String", "@reboot_options", "[", ":startup_disk", "]", "=", "'Specify Local Startup Disk'", "self", ".", "specify_startup", "=", "startup_disk_option", "@need_to_update", "=", "true", "end" ]
Set Startup Disk Only Supports 'Specify Local Startup Disk' at the moment @param startup_disk_option[String] @return [void]
[ "Set", "Startup", "Disk", "Only", "Supports", "Specify", "Local", "Startup", "Disk", "at", "the", "moment" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L905-L910
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.specify_startup=
def specify_startup=(startup_volume) raise JSS::InvalidDataError, "#{startup_volume} is not a valid Startup Disk" unless startup_volume.is_a? String @reboot_options[:specify_startup] = startup_volume @need_to_update = true end
ruby
def specify_startup=(startup_volume) raise JSS::InvalidDataError, "#{startup_volume} is not a valid Startup Disk" unless startup_volume.is_a? String @reboot_options[:specify_startup] = startup_volume @need_to_update = true end
[ "def", "specify_startup", "=", "(", "startup_volume", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"#{startup_volume} is not a valid Startup Disk\"", "unless", "startup_volume", ".", "is_a?", "String", "@reboot_options", "[", ":specify_startup", "]", "=", "startup_volume", "@need_to_update", "=", "true", "end" ]
Specify Startup Volume Only Supports "Specify Local Startup Disk" @param startup_volume[String] a Volume to reboot to @return [void]
[ "Specify", "Startup", "Volume", "Only", "Supports", "Specify", "Local", "Startup", "Disk" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L919-L923
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.minutes_until_reboot=
def minutes_until_reboot=(minutes) raise JSS::InvalidDataError, 'Minutes until reboot must be an Integer' unless minutes.is_a? Integer @reboot_options[:minutes_until_reboot] = minutes @need_to_update = true end
ruby
def minutes_until_reboot=(minutes) raise JSS::InvalidDataError, 'Minutes until reboot must be an Integer' unless minutes.is_a? Integer @reboot_options[:minutes_until_reboot] = minutes @need_to_update = true end
[ "def", "minutes_until_reboot", "=", "(", "minutes", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Minutes until reboot must be an Integer'", "unless", "minutes", ".", "is_a?", "Integer", "@reboot_options", "[", ":minutes_until_reboot", "]", "=", "minutes", "@need_to_update", "=", "true", "end" ]
Reboot Options Minutes Until Reboot @param minutes[String] The number of minutes to delay prior to reboot @return [void]
[ "Reboot", "Options", "Minutes", "Until", "Reboot" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L944-L948
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.run_command=
def run_command=(command) raise JSS::InvalidDataError, 'Command to run must be a String' unless command.is_a? String @files_processes[:run_command] = command @need_to_update = true end
ruby
def run_command=(command) raise JSS::InvalidDataError, 'Command to run must be a String' unless command.is_a? String @files_processes[:run_command] = command @need_to_update = true end
[ "def", "run_command", "=", "(", "command", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Command to run must be a String'", "unless", "command", ".", "is_a?", "String", "@files_processes", "[", ":run_command", "]", "=", "command", "@need_to_update", "=", "true", "end" ]
Set the unix shell command to be run on the client @param command[String] the unix shell command to be run on the client @return [void]
[ "Set", "the", "unix", "shell", "command", "to", "be", "run", "on", "the", "client" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L978-L982
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.set_search_for_process
def set_search_for_process(process, kill = false) @files_processes[:search_for_process] = process.to_s @files_processes[:kill_process] = kill ? true : false @need_to_update = true end
ruby
def set_search_for_process(process, kill = false) @files_processes[:search_for_process] = process.to_s @files_processes[:kill_process] = kill ? true : false @need_to_update = true end
[ "def", "set_search_for_process", "(", "process", ",", "kill", "=", "false", ")", "@files_processes", "[", ":search_for_process", "]", "=", "process", ".", "to_s", "@files_processes", "[", ":kill_process", "]", "=", "kill", "?", "true", ":", "false", "@need_to_update", "=", "true", "end" ]
Set the process name to search for, and if it should be killed if found. Setter methods (which end with =) can't easily take multiple arguments, so we instead name them "set_blah_blah" rather than "blah_blah=" @param process[String] the process name to search for @param kill[Boolean] should be process be killed if found @return [void]
[ "Set", "the", "process", "name", "to", "search", "for", "and", "if", "it", "should", "be", "killed", "if", "found", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1026-L1030
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.set_search_by_path
def set_search_by_path(path, delete = false) raise JSS::InvalidDataError, 'Path to search for must be a String or a Pathname' unless path.is_a?(String) || path.is_a?(Pathname) @files_processes[:search_by_path] = path.to_s @files_processes[:delete_file] = delete ? true : false @need_to_update = true end
ruby
def set_search_by_path(path, delete = false) raise JSS::InvalidDataError, 'Path to search for must be a String or a Pathname' unless path.is_a?(String) || path.is_a?(Pathname) @files_processes[:search_by_path] = path.to_s @files_processes[:delete_file] = delete ? true : false @need_to_update = true end
[ "def", "set_search_by_path", "(", "path", ",", "delete", "=", "false", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Path to search for must be a String or a Pathname'", "unless", "path", ".", "is_a?", "(", "String", ")", "||", "path", ".", "is_a?", "(", "Pathname", ")", "@files_processes", "[", ":search_by_path", "]", "=", "path", ".", "to_s", "@files_processes", "[", ":delete_file", "]", "=", "delete", "?", "true", ":", "false", "@need_to_update", "=", "true", "end" ]
Set the path to search for, a String or Pathname, and whether or not to delete it if found. Setter methods (which end with =) can't easily take multiple arguments, so we instead name them "set_blah_blah" rather than "blah_blah=" @param path[String,Pathname] the path to search for @param delete[Boolean] should the path be deleted if found @return [void]
[ "Set", "the", "path", "to", "search", "for", "a", "String", "or", "Pathname", "and", "whether", "or", "not", "to", "delete", "it", "if", "found", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1057-L1062
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.spotlight_search=
def spotlight_search=(term) raise JSS::InvalidDataError, 'Spotlight search term must be a String' unless term.is_a? String @files_processes[:spotlight_search] = term @need_to_update = true end
ruby
def spotlight_search=(term) raise JSS::InvalidDataError, 'Spotlight search term must be a String' unless term.is_a? String @files_processes[:spotlight_search] = term @need_to_update = true end
[ "def", "spotlight_search", "=", "(", "term", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Spotlight search term must be a String'", "unless", "term", ".", "is_a?", "String", "@files_processes", "[", ":spotlight_search", "]", "=", "term", "@need_to_update", "=", "true", "end" ]
Set the term to seach for using spotlight @param term[String] the term to seach for using spotlight @return [void]
[ "Set", "the", "term", "to", "seach", "for", "using", "spotlight" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1076-L1080
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.locate_file=
def locate_file=(term) raise JSS::InvalidDataError, 'Term to locate must be a String' unless term.is_a? String @files_processes[:locate_file] = term @need_to_update = true end
ruby
def locate_file=(term) raise JSS::InvalidDataError, 'Term to locate must be a String' unless term.is_a? String @files_processes[:locate_file] = term @need_to_update = true end
[ "def", "locate_file", "=", "(", "term", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'Term to locate must be a String'", "unless", "term", ".", "is_a?", "String", "@files_processes", "[", ":locate_file", "]", "=", "term", "@need_to_update", "=", "true", "end" ]
Set the term to seach for using the locate command @param term[String] the term to seach for using the locate command @return [void]
[ "Set", "the", "term", "to", "seach", "for", "using", "the", "locate", "command" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1094-L1098
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.add_package
def add_package(identifier, **opts) id = validate_package_opts(identifier, opts) return nil if @packages.map { |p| p[:id] }.include? id name = JSS::Package.map_all_ids_to(:name, api: @api)[id] pkg_data = { id: id, name: name, action: PACKAGE_ACTIONS[opts[:action]], feu: opts[:feu], fut: opts[:feu], update_autorun: opts[:update_autorun] } @packages.insert opts[:position], pkg_data @need_to_update = true @packages end
ruby
def add_package(identifier, **opts) id = validate_package_opts(identifier, opts) return nil if @packages.map { |p| p[:id] }.include? id name = JSS::Package.map_all_ids_to(:name, api: @api)[id] pkg_data = { id: id, name: name, action: PACKAGE_ACTIONS[opts[:action]], feu: opts[:feu], fut: opts[:feu], update_autorun: opts[:update_autorun] } @packages.insert opts[:position], pkg_data @need_to_update = true @packages end
[ "def", "add_package", "(", "identifier", ",", "**", "opts", ")", "id", "=", "validate_package_opts", "(", "identifier", ",", "opts", ")", "return", "nil", "if", "@packages", ".", "map", "{", "|", "p", "|", "p", "[", ":id", "]", "}", ".", "include?", "id", "name", "=", "JSS", "::", "Package", ".", "map_all_ids_to", "(", ":name", ",", "api", ":", "@api", ")", "[", "id", "]", "pkg_data", "=", "{", "id", ":", "id", ",", "name", ":", "name", ",", "action", ":", "PACKAGE_ACTIONS", "[", "opts", "[", ":action", "]", "]", ",", "feu", ":", "opts", "[", ":feu", "]", ",", "fut", ":", "opts", "[", ":feu", "]", ",", "update_autorun", ":", "opts", "[", ":update_autorun", "]", "}", "@packages", ".", "insert", "opts", "[", ":position", "]", ",", "pkg_data", "@need_to_update", "=", "true", "@packages", "end" ]
Add a package to the list of pkgs handled by this policy. If the pkg already exists in the policy, nil is returned and no changes are made. @param [String,Integer] identifier the name or id of the package to add to this policy @param position [Symbol, Integer] where to add this pkg among the list of pkgs. Zero-based, :start and 0 are the same, as are :end and -1. Defaults to :end @param action [String] One of the values of PACKAGE_ACTIONS @param feu [Boolean] Overrides the setting for the pkg itself Defaults to false @param fut [Boolean] Overrides the setting for the pkg itself Defaults to false @param update_autorun [Boolean] Defaults to false @return [Array, nil] the new @packages array, nil if pkg was already in the policy
[ "Add", "a", "package", "to", "the", "list", "of", "pkgs", "handled", "by", "this", "policy", ".", "If", "the", "pkg", "already", "exists", "in", "the", "policy", "nil", "is", "returned", "and", "no", "changes", "are", "made", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1136-L1156
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.remove_package
def remove_package(identifier) removed = @packages.delete_if { |p| p[:id] == identifier || p[:name] == identifier } @need_to_update = true if removed removed end
ruby
def remove_package(identifier) removed = @packages.delete_if { |p| p[:id] == identifier || p[:name] == identifier } @need_to_update = true if removed removed end
[ "def", "remove_package", "(", "identifier", ")", "removed", "=", "@packages", ".", "delete_if", "{", "|", "p", "|", "p", "[", ":id", "]", "==", "identifier", "||", "p", "[", ":name", "]", "==", "identifier", "}", "@need_to_update", "=", "true", "if", "removed", "removed", "end" ]
Remove a package from this policy by name or id @param identfier [String,Integer] the name or id of the package to remove @return [Array, nil] the new packages array or nil if no change
[ "Remove", "a", "package", "from", "this", "policy", "by", "name", "or", "id" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1164-L1168
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.add_script
def add_script(identifier, **opts) id = validate_script_opts(identifier, opts) return nil if @scripts.map { |s| s[:id] }.include? id name = JSS::Script.map_all_ids_to(:name, api: @api)[id] script_data = { id: id, name: name, priority: SCRIPT_PRIORITIES[opts[:priority]], parameter4: opts[:parameter4], parameter5: opts[:parameter5], parameter6: opts[:parameter6], parameter7: opts[:parameter7], parameter8: opts[:parameter8], parameter9: opts[:parameter9], parameter10: opts[:parameter10], parameter11: opts[:parameter11] } @scripts.insert opts[:position], script_data @need_to_update = true @scripts end
ruby
def add_script(identifier, **opts) id = validate_script_opts(identifier, opts) return nil if @scripts.map { |s| s[:id] }.include? id name = JSS::Script.map_all_ids_to(:name, api: @api)[id] script_data = { id: id, name: name, priority: SCRIPT_PRIORITIES[opts[:priority]], parameter4: opts[:parameter4], parameter5: opts[:parameter5], parameter6: opts[:parameter6], parameter7: opts[:parameter7], parameter8: opts[:parameter8], parameter9: opts[:parameter9], parameter10: opts[:parameter10], parameter11: opts[:parameter11] } @scripts.insert opts[:position], script_data @need_to_update = true @scripts end
[ "def", "add_script", "(", "identifier", ",", "**", "opts", ")", "id", "=", "validate_script_opts", "(", "identifier", ",", "opts", ")", "return", "nil", "if", "@scripts", ".", "map", "{", "|", "s", "|", "s", "[", ":id", "]", "}", ".", "include?", "id", "name", "=", "JSS", "::", "Script", ".", "map_all_ids_to", "(", ":name", ",", "api", ":", "@api", ")", "[", "id", "]", "script_data", "=", "{", "id", ":", "id", ",", "name", ":", "name", ",", "priority", ":", "SCRIPT_PRIORITIES", "[", "opts", "[", ":priority", "]", "]", ",", "parameter4", ":", "opts", "[", ":parameter4", "]", ",", "parameter5", ":", "opts", "[", ":parameter5", "]", ",", "parameter6", ":", "opts", "[", ":parameter6", "]", ",", "parameter7", ":", "opts", "[", ":parameter7", "]", ",", "parameter8", ":", "opts", "[", ":parameter8", "]", ",", "parameter9", ":", "opts", "[", ":parameter9", "]", ",", "parameter10", ":", "opts", "[", ":parameter10", "]", ",", "parameter11", ":", "opts", "[", ":parameter11", "]", "}", "@scripts", ".", "insert", "opts", "[", ":position", "]", ",", "script_data", "@need_to_update", "=", "true", "@scripts", "end" ]
Add a script to the list of SCRIPT_PRIORITIESipts run by this policy. If the script already exists in the policy, nil is returned and no changes are made. @param [String,Integer] identifier the name or id of the script to add to this policy @param [Hash] opts the options for this script @option [Symbol, Integer] position: where to add this script among the list of scripts. Zero-based, :start and 0 are the same, as are :end and -1. Defaults to :end @option [Symbol] priority: either :before or :after @option [String] parameter4: the value of the 4th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter5: the value of the 5th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter6: the value of the 6th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter7: the value of the 7th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter8: the value of the 8th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter9: the value of the 9th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter10: the value of the 10th parameter passed to the script. this overrides the same parameter in the script object itself. @option [String] parameter11: the value of the 11th parameter passed to the script. this overrides the same parameter in the script object itself. @return [Array, nil] the new @scripts array, nil if script was already in the policy
[ "Add", "a", "script", "to", "the", "list", "of", "SCRIPT_PRIORITIESipts", "run", "by", "this", "policy", ".", "If", "the", "script", "already", "exists", "in", "the", "policy", "nil", "is", "returned", "and", "no", "changes", "are", "made", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1221-L1246
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.remove_script
def remove_script(identifier) removed = @scripts.delete_if { |s| s[:id] == identifier || s[:name] == identifier } @need_to_update = true if removed removed end
ruby
def remove_script(identifier) removed = @scripts.delete_if { |s| s[:id] == identifier || s[:name] == identifier } @need_to_update = true if removed removed end
[ "def", "remove_script", "(", "identifier", ")", "removed", "=", "@scripts", ".", "delete_if", "{", "|", "s", "|", "s", "[", ":id", "]", "==", "identifier", "||", "s", "[", ":name", "]", "==", "identifier", "}", "@need_to_update", "=", "true", "if", "removed", "removed", "end" ]
Remove a script from this policy by name or id @param identfier [String,Integer] the name or id of the script to remove @return [Array, nil] the new scripts array or nil if no change
[ "Remove", "a", "script", "from", "this", "policy", "by", "name", "or", "id" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1254-L1258
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.run
def run(show_output = false) return nil unless enabled? output = JSS::Client.run_jamf('policy', "-id #{id}", show_output) return nil if output.include? 'No policies were found for the ID' $CHILD_STATUS.exitstatus.zero? ? true : false end
ruby
def run(show_output = false) return nil unless enabled? output = JSS::Client.run_jamf('policy', "-id #{id}", show_output) return nil if output.include? 'No policies were found for the ID' $CHILD_STATUS.exitstatus.zero? ? true : false end
[ "def", "run", "(", "show_output", "=", "false", ")", "return", "nil", "unless", "enabled?", "output", "=", "JSS", "::", "Client", ".", "run_jamf", "(", "'policy'", ",", "\"-id #{id}\"", ",", "show_output", ")", "return", "nil", "if", "output", ".", "include?", "'No policies were found for the ID'", "$CHILD_STATUS", ".", "exitstatus", ".", "zero?", "?", "true", ":", "false", "end" ]
Actions Try to execute this policy on this machine. @param show_output[Boolean] should the stdout and stderr of the 'jamf policy' command be sent to stdout in realtime? @return [Boolean, nil] The success of the 'jamf policy' command, or nil if the policy couldn't be executed (out of scope, policy disabled, etc)
[ "Actions", "Try", "to", "execute", "this", "policy", "on", "this", "machine", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1306-L1311
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.flush_logs
def flush_logs(older_than: 0, period: :days) raise JSS::NoSuchItemError, "Policy doesn't exist in the JSS. Use #create first." unless @in_jss unless LOG_FLUSH_INTERVAL_INTEGERS.key?(older_than) raise JSS::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" end unless LOG_FLUSH_INTERVAL_PERIODS.key?(period) raise JSS::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" end interval = "#{LOG_FLUSH_INTERVAL_INTEGERS[older_than]}+#{LOG_FLUSH_INTERVAL_PERIODS[period]}" @api.delete_rsrc "#{LOG_FLUSH_RSRC}/policy/id/#{@id}/interval/#{interval}" end
ruby
def flush_logs(older_than: 0, period: :days) raise JSS::NoSuchItemError, "Policy doesn't exist in the JSS. Use #create first." unless @in_jss unless LOG_FLUSH_INTERVAL_INTEGERS.key?(older_than) raise JSS::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" end unless LOG_FLUSH_INTERVAL_PERIODS.key?(period) raise JSS::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" end interval = "#{LOG_FLUSH_INTERVAL_INTEGERS[older_than]}+#{LOG_FLUSH_INTERVAL_PERIODS[period]}" @api.delete_rsrc "#{LOG_FLUSH_RSRC}/policy/id/#{@id}/interval/#{interval}" end
[ "def", "flush_logs", "(", "older_than", ":", "0", ",", "period", ":", ":days", ")", "raise", "JSS", "::", "NoSuchItemError", ",", "\"Policy doesn't exist in the JSS. Use #create first.\"", "unless", "@in_jss", "unless", "LOG_FLUSH_INTERVAL_INTEGERS", ".", "key?", "(", "older_than", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}\"", "end", "unless", "LOG_FLUSH_INTERVAL_PERIODS", ".", "key?", "(", "period", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}\"", "end", "interval", "=", "\"#{LOG_FLUSH_INTERVAL_INTEGERS[older_than]}+#{LOG_FLUSH_INTERVAL_PERIODS[period]}\"", "@api", ".", "delete_rsrc", "\"#{LOG_FLUSH_RSRC}/policy/id/#{@id}/interval/#{interval}\"", "end" ]
Flush all policy logs for this policy older than some number of days, weeks, months or years. With no parameters, flushes all logs NOTE: Currently the API doesn't have a way to flush only failed policies. @param older_than[Integer] 0, 1, 2, 3, or 6 @param period[Symbol] :days, :weeks, :months, or :years @return [void]
[ "Flush", "all", "policy", "logs", "for", "this", "policy", "older", "than", "some", "number", "of", "days", "weeks", "months", "or", "years", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1328-L1342
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.validate_package_opts
def validate_package_opts(identifier, opts) opts[:position] ||= -1 opts[:action] ||= :install opts[:feu] ||= false opts[:fut] ||= false opts[:update_autorun] ||= false opts[:position] = case opts[:position] when :start then 0 when :end then -1 else JSS::Validate.integer(opts[:position]) end # if the given position is past the end, set it to -1 (the end) opts[:position] = -1 if opts[:position] > @packages.size id = JSS::Package.valid_id identifier, api: @api raise JSS::NoSuchItemError, "No package matches '#{identifier}'" unless id raise JSS::InvalidDataError, "action must be one of: :#{PACKAGE_ACTIONS.keys.join ', :'}" unless \ PACKAGE_ACTIONS.include? opts[:action] opts[:feu] = JSS::Validate.boolean opts[:feu] opts[:fut] = JSS::Validate.boolean opts[:fut] opts[:update_autorun] = JSS::Validate.boolean opts[:update_autorun] id end
ruby
def validate_package_opts(identifier, opts) opts[:position] ||= -1 opts[:action] ||= :install opts[:feu] ||= false opts[:fut] ||= false opts[:update_autorun] ||= false opts[:position] = case opts[:position] when :start then 0 when :end then -1 else JSS::Validate.integer(opts[:position]) end # if the given position is past the end, set it to -1 (the end) opts[:position] = -1 if opts[:position] > @packages.size id = JSS::Package.valid_id identifier, api: @api raise JSS::NoSuchItemError, "No package matches '#{identifier}'" unless id raise JSS::InvalidDataError, "action must be one of: :#{PACKAGE_ACTIONS.keys.join ', :'}" unless \ PACKAGE_ACTIONS.include? opts[:action] opts[:feu] = JSS::Validate.boolean opts[:feu] opts[:fut] = JSS::Validate.boolean opts[:fut] opts[:update_autorun] = JSS::Validate.boolean opts[:update_autorun] id end
[ "def", "validate_package_opts", "(", "identifier", ",", "opts", ")", "opts", "[", ":position", "]", "||=", "-", "1", "opts", "[", ":action", "]", "||=", ":install", "opts", "[", ":feu", "]", "||=", "false", "opts", "[", ":fut", "]", "||=", "false", "opts", "[", ":update_autorun", "]", "||=", "false", "opts", "[", ":position", "]", "=", "case", "opts", "[", ":position", "]", "when", ":start", "then", "0", "when", ":end", "then", "-", "1", "else", "JSS", "::", "Validate", ".", "integer", "(", "opts", "[", ":position", "]", ")", "end", "# if the given position is past the end, set it to -1 (the end)", "opts", "[", ":position", "]", "=", "-", "1", "if", "opts", "[", ":position", "]", ">", "@packages", ".", "size", "id", "=", "JSS", "::", "Package", ".", "valid_id", "identifier", ",", "api", ":", "@api", "raise", "JSS", "::", "NoSuchItemError", ",", "\"No package matches '#{identifier}'\"", "unless", "id", "raise", "JSS", "::", "InvalidDataError", ",", "\"action must be one of: :#{PACKAGE_ACTIONS.keys.join ', :'}\"", "unless", "PACKAGE_ACTIONS", ".", "include?", "opts", "[", ":action", "]", "opts", "[", ":feu", "]", "=", "JSS", "::", "Validate", ".", "boolean", "opts", "[", ":feu", "]", "opts", "[", ":fut", "]", "=", "JSS", "::", "Validate", ".", "boolean", "opts", "[", ":fut", "]", "opts", "[", ":update_autorun", "]", "=", "JSS", "::", "Validate", ".", "boolean", "opts", "[", ":update_autorun", "]", "id", "end" ]
raise an error if a package being added isn't valid @see #add_package @return [Integer, nil] the valid id for the package
[ "raise", "an", "error", "if", "a", "package", "being", "added", "isn", "t", "valid" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1355-L1383
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/policy.rb
JSS.Policy.validate_script_opts
def validate_script_opts(identifier, opts) opts[:position] ||= -1 opts[:priority] ||= :after raise JSS::InvalidDataError, "priority must be one of: :#{SCRIPT_PRIORITIES.keys.join ', :'}" unless \ SCRIPT_PRIORITIES.include? opts[:priority] opts[:position] = case opts[:position] when :start then 0 when :end then -1 else JSS::Validate.integer(opts[:position]) end # if the given position is past the end, set it to -1 (the end) opts[:position] = -1 if opts[:position] > @packages.size id = JSS::Script.valid_id identifier, api: @api raise JSS::NoSuchItemError, "No script matches '#{identifier}'" unless id id end
ruby
def validate_script_opts(identifier, opts) opts[:position] ||= -1 opts[:priority] ||= :after raise JSS::InvalidDataError, "priority must be one of: :#{SCRIPT_PRIORITIES.keys.join ', :'}" unless \ SCRIPT_PRIORITIES.include? opts[:priority] opts[:position] = case opts[:position] when :start then 0 when :end then -1 else JSS::Validate.integer(opts[:position]) end # if the given position is past the end, set it to -1 (the end) opts[:position] = -1 if opts[:position] > @packages.size id = JSS::Script.valid_id identifier, api: @api raise JSS::NoSuchItemError, "No script matches '#{identifier}'" unless id id end
[ "def", "validate_script_opts", "(", "identifier", ",", "opts", ")", "opts", "[", ":position", "]", "||=", "-", "1", "opts", "[", ":priority", "]", "||=", ":after", "raise", "JSS", "::", "InvalidDataError", ",", "\"priority must be one of: :#{SCRIPT_PRIORITIES.keys.join ', :'}\"", "unless", "SCRIPT_PRIORITIES", ".", "include?", "opts", "[", ":priority", "]", "opts", "[", ":position", "]", "=", "case", "opts", "[", ":position", "]", "when", ":start", "then", "0", "when", ":end", "then", "-", "1", "else", "JSS", "::", "Validate", ".", "integer", "(", "opts", "[", ":position", "]", ")", "end", "# if the given position is past the end, set it to -1 (the end)", "opts", "[", ":position", "]", "=", "-", "1", "if", "opts", "[", ":position", "]", ">", "@packages", ".", "size", "id", "=", "JSS", "::", "Script", ".", "valid_id", "identifier", ",", "api", ":", "@api", "raise", "JSS", "::", "NoSuchItemError", ",", "\"No script matches '#{identifier}'\"", "unless", "id", "id", "end" ]
raise an error if a script being added isn't valid @see #add_script @return [Integer, nil] the valid id for the package
[ "raise", "an", "error", "if", "a", "script", "being", "added", "isn", "t", "valid" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/policy.rb#L1391-L1411
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/extension_attribute.rb
JSS.ExtensionAttribute.web_display=
def web_display=(new_val) return nil if @web_display == new_val raise JSS::InvalidDataError, "inventory_display must be a string, one of: #{INVENTORY_DISPLAY_CHOICES.join(', ')}" unless WEB_DISPLAY_CHOICES.include? new_val @web_display = new_val @need_to_update = true end
ruby
def web_display=(new_val) return nil if @web_display == new_val raise JSS::InvalidDataError, "inventory_display must be a string, one of: #{INVENTORY_DISPLAY_CHOICES.join(', ')}" unless WEB_DISPLAY_CHOICES.include? new_val @web_display = new_val @need_to_update = true end
[ "def", "web_display", "=", "(", "new_val", ")", "return", "nil", "if", "@web_display", "==", "new_val", "raise", "JSS", "::", "InvalidDataError", ",", "\"inventory_display must be a string, one of: #{INVENTORY_DISPLAY_CHOICES.join(', ')}\"", "unless", "WEB_DISPLAY_CHOICES", ".", "include?", "new_val", "@web_display", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change the inventory_display of this EA @param new_val[String] the new value, which must be a member of INVENTORY_DISPLAY_CHOICES @return [void]
[ "Change", "the", "inventory_display", "of", "this", "EA" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/extension_attribute.rb#L214-L219
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/extension_attribute.rb
JSS.ExtensionAttribute.input_type=
def input_type=(new_val) return nil if @input_type == new_val raise JSS::InvalidDataError, "input_type must be a string, one of: #{INPUT_TYPES.join(', ')}" unless INPUT_TYPES.include? new_val @input_type = new_val @popup_choices = nil if @input_type == 'Text Field' @need_to_update = true end
ruby
def input_type=(new_val) return nil if @input_type == new_val raise JSS::InvalidDataError, "input_type must be a string, one of: #{INPUT_TYPES.join(', ')}" unless INPUT_TYPES.include? new_val @input_type = new_val @popup_choices = nil if @input_type == 'Text Field' @need_to_update = true end
[ "def", "input_type", "=", "(", "new_val", ")", "return", "nil", "if", "@input_type", "==", "new_val", "raise", "JSS", "::", "InvalidDataError", ",", "\"input_type must be a string, one of: #{INPUT_TYPES.join(', ')}\"", "unless", "INPUT_TYPES", ".", "include?", "new_val", "@input_type", "=", "new_val", "@popup_choices", "=", "nil", "if", "@input_type", "==", "'Text Field'", "@need_to_update", "=", "true", "end" ]
Change the input type of this EA @param new_val[String] the new value, which must be a member of INPUT_TYPES @return [void]
[ "Change", "the", "input", "type", "of", "this", "EA" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/extension_attribute.rb#L227-L233
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/extension_attribute.rb
JSS.ExtensionAttribute.popup_choices=
def popup_choices=(new_val) return nil if @popup_choices == new_val raise JSS::InvalidDataError, 'popup_choices must be an Array' unless new_val.is_a?(Array) # convert each one to a String, # and check that it matches the @data_type new_val.map! do |v| v = v.to_s.strip case @data_type when 'Date' raise JSS::InvalidDataError, "data_type is Date, but '#{v}' is not formatted 'YYYY-MM-DD hh:mm:ss'" unless v =~ /^\d{4}(-\d\d){2} (\d\d:){2}\d\d$/ when 'Integer' raise JSS::InvalidDataError, "data_type is Integer, but '#{v}' is not one" unless v =~ /^\d+$/ end v end self.input_type = 'Pop-up Menu' @popup_choices = new_val @need_to_update = true end
ruby
def popup_choices=(new_val) return nil if @popup_choices == new_val raise JSS::InvalidDataError, 'popup_choices must be an Array' unless new_val.is_a?(Array) # convert each one to a String, # and check that it matches the @data_type new_val.map! do |v| v = v.to_s.strip case @data_type when 'Date' raise JSS::InvalidDataError, "data_type is Date, but '#{v}' is not formatted 'YYYY-MM-DD hh:mm:ss'" unless v =~ /^\d{4}(-\d\d){2} (\d\d:){2}\d\d$/ when 'Integer' raise JSS::InvalidDataError, "data_type is Integer, but '#{v}' is not one" unless v =~ /^\d+$/ end v end self.input_type = 'Pop-up Menu' @popup_choices = new_val @need_to_update = true end
[ "def", "popup_choices", "=", "(", "new_val", ")", "return", "nil", "if", "@popup_choices", "==", "new_val", "raise", "JSS", "::", "InvalidDataError", ",", "'popup_choices must be an Array'", "unless", "new_val", ".", "is_a?", "(", "Array", ")", "# convert each one to a String,", "# and check that it matches the @data_type", "new_val", ".", "map!", "do", "|", "v", "|", "v", "=", "v", ".", "to_s", ".", "strip", "case", "@data_type", "when", "'Date'", "raise", "JSS", "::", "InvalidDataError", ",", "\"data_type is Date, but '#{v}' is not formatted 'YYYY-MM-DD hh:mm:ss'\"", "unless", "v", "=~", "/", "\\d", "\\d", "\\d", "\\d", "\\d", "\\d", "\\d", "/", "when", "'Integer'", "raise", "JSS", "::", "InvalidDataError", ",", "\"data_type is Integer, but '#{v}' is not one\"", "unless", "v", "=~", "/", "\\d", "/", "end", "v", "end", "self", ".", "input_type", "=", "'Pop-up Menu'", "@popup_choices", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change the Popup Choices of this EA New value must be an Array, the items will be converted to Strings. This automatically sets input_type to "Pop-up Menu" Values are checked to ensure they match the @data_type Note, Dates must be in the format "YYYY-MM-DD hh:mm:ss" @param new_val[Array<#to_s>] the new values @return [void]
[ "Change", "the", "Popup", "Choices", "of", "this", "EA", "New", "value", "must", "be", "an", "Array", "the", "items", "will", "be", "converted", "to", "Strings", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/extension_attribute.rb#L247-L266
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/extension_attribute.rb
JSS.ExtensionAttribute.all_with_result
def all_with_result(search_type, desired_value) raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}." unless @in_jss raise JSS::InvalidDataError, 'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES' unless JSS::Criteriable::Criterion::SEARCH_TYPES.include? search_type.to_s begin search_class = self.class::TARGET_CLASS::SEARCH_CLASS acs = search_class.make api: @api, name: "ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}" acs.display_fields = [@name] crit_list = [JSS::Criteriable::Criterion.new(and_or: 'and', name: @name, search_type: search_type.to_s, value: desired_value)] acs.criteria = JSS::Criteriable::Criteria.new crit_list acs.create :get_results results = [] acs.search_results.each do |i| value = case @data_type when 'Date' then JSS.parse_datetime i[@symbolized_name] when 'Integer' then i[@symbolized_name].to_i else i[@symbolized_name] end # case results << { id: i[:id], name: i[:name], value: value } end ensure acs.delete if acs.is_a? self.class::TARGET_CLASS::SEARCH_CLASS end results end
ruby
def all_with_result(search_type, desired_value) raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}." unless @in_jss raise JSS::InvalidDataError, 'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES' unless JSS::Criteriable::Criterion::SEARCH_TYPES.include? search_type.to_s begin search_class = self.class::TARGET_CLASS::SEARCH_CLASS acs = search_class.make api: @api, name: "ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}" acs.display_fields = [@name] crit_list = [JSS::Criteriable::Criterion.new(and_or: 'and', name: @name, search_type: search_type.to_s, value: desired_value)] acs.criteria = JSS::Criteriable::Criteria.new crit_list acs.create :get_results results = [] acs.search_results.each do |i| value = case @data_type when 'Date' then JSS.parse_datetime i[@symbolized_name] when 'Integer' then i[@symbolized_name].to_i else i[@symbolized_name] end # case results << { id: i[:id], name: i[:name], value: value } end ensure acs.delete if acs.is_a? self.class::TARGET_CLASS::SEARCH_CLASS end results end
[ "def", "all_with_result", "(", "search_type", ",", "desired_value", ")", "raise", "JSS", "::", "NoSuchItemError", ",", "\"EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}.\"", "unless", "@in_jss", "raise", "JSS", "::", "InvalidDataError", ",", "'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES'", "unless", "JSS", "::", "Criteriable", "::", "Criterion", "::", "SEARCH_TYPES", ".", "include?", "search_type", ".", "to_s", "begin", "search_class", "=", "self", ".", "class", "::", "TARGET_CLASS", "::", "SEARCH_CLASS", "acs", "=", "search_class", ".", "make", "api", ":", "@api", ",", "name", ":", "\"ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}\"", "acs", ".", "display_fields", "=", "[", "@name", "]", "crit_list", "=", "[", "JSS", "::", "Criteriable", "::", "Criterion", ".", "new", "(", "and_or", ":", "'and'", ",", "name", ":", "@name", ",", "search_type", ":", "search_type", ".", "to_s", ",", "value", ":", "desired_value", ")", "]", "acs", ".", "criteria", "=", "JSS", "::", "Criteriable", "::", "Criteria", ".", "new", "crit_list", "acs", ".", "create", ":get_results", "results", "=", "[", "]", "acs", ".", "search_results", ".", "each", "do", "|", "i", "|", "value", "=", "case", "@data_type", "when", "'Date'", "then", "JSS", ".", "parse_datetime", "i", "[", "@symbolized_name", "]", "when", "'Integer'", "then", "i", "[", "@symbolized_name", "]", ".", "to_i", "else", "i", "[", "@symbolized_name", "]", "end", "# case", "results", "<<", "{", "id", ":", "i", "[", ":id", "]", ",", "name", ":", "i", "[", ":name", "]", ",", "value", ":", "value", "}", "end", "ensure", "acs", ".", "delete", "if", "acs", ".", "is_a?", "self", ".", "class", "::", "TARGET_CLASS", "::", "SEARCH_CLASS", "end", "results", "end" ]
Get an Array of Hashes for all inventory objects with a desired result in their latest report for this EA. Each Hash is one inventory object (computer, mobile device, user), with these keys: :id - the computer id :name - the computer name :value - the matching ext attr value for the objects latest report. This is done by creating a temprary {AdvancedSearch} for objects with matching values in the EA field, then getting the #search_results hash from it. The AdvancedSearch is then deleted. @param search_type[String] how are we comparing the stored value with the desired value. must be a member of JSS::Criterion::SEARCH_TYPES @param desired_value[String] the value to compare with the stored value to determine a match. @return [Array<Hash{:id=>Integer,:name=>String,:value=>String,Integer,Time}>] the items that match the result.
[ "Get", "an", "Array", "of", "Hashes", "for", "all", "inventory", "objects", "with", "a", "desired", "result", "in", "their", "latest", "report", "for", "this", "EA", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/extension_attribute.rb#L288-L314
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/extension_attribute.rb
JSS.ExtensionAttribute.rest_rexml
def rest_rexml ea = REXML::Element.new self.class::RSRC_OBJECT_KEY.to_s ea.add_element('name').text = @name ea.add_element('description').text = @description ea.add_element('data_type').text = @data_type ea.add_element('inventory_display').text = @web_display it = ea.add_element('input_type') it.add_element('type').text = @input_type if @input_type == 'Pop-up Menu' pcs = it.add_element('popup_choices') @popup_choices.each { |pc| pcs.add_element('choice').text = pc } end ea end
ruby
def rest_rexml ea = REXML::Element.new self.class::RSRC_OBJECT_KEY.to_s ea.add_element('name').text = @name ea.add_element('description').text = @description ea.add_element('data_type').text = @data_type ea.add_element('inventory_display').text = @web_display it = ea.add_element('input_type') it.add_element('type').text = @input_type if @input_type == 'Pop-up Menu' pcs = it.add_element('popup_choices') @popup_choices.each { |pc| pcs.add_element('choice').text = pc } end ea end
[ "def", "rest_rexml", "ea", "=", "REXML", "::", "Element", ".", "new", "self", ".", "class", "::", "RSRC_OBJECT_KEY", ".", "to_s", "ea", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "@name", "ea", ".", "add_element", "(", "'description'", ")", ".", "text", "=", "@description", "ea", ".", "add_element", "(", "'data_type'", ")", ".", "text", "=", "@data_type", "ea", ".", "add_element", "(", "'inventory_display'", ")", ".", "text", "=", "@web_display", "it", "=", "ea", ".", "add_element", "(", "'input_type'", ")", "it", ".", "add_element", "(", "'type'", ")", ".", "text", "=", "@input_type", "if", "@input_type", "==", "'Pop-up Menu'", "pcs", "=", "it", ".", "add_element", "(", "'popup_choices'", ")", "@popup_choices", ".", "each", "{", "|", "pc", "|", "pcs", ".", "add_element", "(", "'choice'", ")", ".", "text", "=", "pc", "}", "end", "ea", "end" ]
Return a REXML object for this ext attr, with the current values. Subclasses should augment this in their rest_xml methods then return it .to_s, for saving or updating
[ "Return", "a", "REXML", "object", "for", "this", "ext", "attr", "with", "the", "current", "values", ".", "Subclasses", "should", "augment", "this", "in", "their", "rest_xml", "methods", "then", "return", "it", ".", "to_s", "for", "saving", "or", "updating" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/extension_attribute.rb#L394-L408
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/extension_attribute/computer_extension_attribute.rb
JSS.ComputerExtensionAttribute.recon_display=
def recon_display= (new_val) return nil if @recon_display == new_val raise JSS::InvalidDataError, "recon_display must be a string, one of: #{RECON_DISPLAY_CHOICES.join(", ")}" unless RECON_DISPLAY_CHOICES.include? new_val @recon_display = new_val @need_to_update = true end
ruby
def recon_display= (new_val) return nil if @recon_display == new_val raise JSS::InvalidDataError, "recon_display must be a string, one of: #{RECON_DISPLAY_CHOICES.join(", ")}" unless RECON_DISPLAY_CHOICES.include? new_val @recon_display = new_val @need_to_update = true end
[ "def", "recon_display", "=", "(", "new_val", ")", "return", "nil", "if", "@recon_display", "==", "new_val", "raise", "JSS", "::", "InvalidDataError", ",", "\"recon_display must be a string, one of: #{RECON_DISPLAY_CHOICES.join(\", \")}\"", "unless", "RECON_DISPLAY_CHOICES", ".", "include?", "new_val", "@recon_display", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Change the recon_display of this EA
[ "Change", "the", "recon_display", "of", "this", "EA" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb#L180-L185
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/patch_source/patch_external_source.rb
JSS.PatchExternalSource.validate_host_port
def validate_host_port(action) raise JSS::UnsupportedError, "Cannot #{action} without first setting a host_name and port" if host_name.to_s.empty? || port.to_s.empty? end
ruby
def validate_host_port(action) raise JSS::UnsupportedError, "Cannot #{action} without first setting a host_name and port" if host_name.to_s.empty? || port.to_s.empty? end
[ "def", "validate_host_port", "(", "action", ")", "raise", "JSS", "::", "UnsupportedError", ",", "\"Cannot #{action} without first setting a host_name and port\"", "if", "host_name", ".", "to_s", ".", "empty?", "||", "port", ".", "to_s", ".", "empty?", "end" ]
raise an exeption if needed when trying to do something that needs a host and port set @param action[String] The action that needs a host and port @return [void]
[ "raise", "an", "exeption", "if", "needed", "when", "trying", "to", "do", "something", "that", "needs", "a", "host", "and", "port", "set" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/patch_source/patch_external_source.rb#L139-L141
train
PixarAnimationStudios/ruby-jss
lib/jss/db_connection.rb
JSS.DBConnection.valid_server?
def valid_server?(server, port = DFT_PORT) mysql = Mysql.init mysql.options Mysql::OPT_CONNECT_TIMEOUT, 5 begin # this connection should get an access denied error if there is # a mysql server there. I'm assuming no one will use this username # and pw for anything real mysql.connect server, 'notArealUser', "definatelyNotA#{$PROCESS_ID}password", 'not_a_db', port rescue Mysql::ServerError::AccessDeniedError return true rescue return false end false end
ruby
def valid_server?(server, port = DFT_PORT) mysql = Mysql.init mysql.options Mysql::OPT_CONNECT_TIMEOUT, 5 begin # this connection should get an access denied error if there is # a mysql server there. I'm assuming no one will use this username # and pw for anything real mysql.connect server, 'notArealUser', "definatelyNotA#{$PROCESS_ID}password", 'not_a_db', port rescue Mysql::ServerError::AccessDeniedError return true rescue return false end false end
[ "def", "valid_server?", "(", "server", ",", "port", "=", "DFT_PORT", ")", "mysql", "=", "Mysql", ".", "init", "mysql", ".", "options", "Mysql", "::", "OPT_CONNECT_TIMEOUT", ",", "5", "begin", "# this connection should get an access denied error if there is", "# a mysql server there. I'm assuming no one will use this username", "# and pw for anything real", "mysql", ".", "connect", "server", ",", "'notArealUser'", ",", "\"definatelyNotA#{$PROCESS_ID}password\"", ",", "'not_a_db'", ",", "port", "rescue", "Mysql", "::", "ServerError", "::", "AccessDeniedError", "return", "true", "rescue", "return", "false", "end", "false", "end" ]
disconnect Test that a given hostname is a MySQL server @param server[String] The hostname to test @return [Boolean] does the server host a MySQL server?
[ "disconnect", "Test", "that", "a", "given", "hostname", "is", "a", "MySQL", "server" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/db_connection.rb#L240-L256
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_self_service_category
def add_self_service_category(new_cat, display_in: true, feature_in: false) new_cat = JSS::Category.map_all_ids_to(:name, api: @api)[new_cat] if new_cat.is_a? Integer feature_in = false if display_in == false raise JSS::NoSuchItemError, "No category '#{new_cat}' in the JSS" unless JSS::Category.all_names(:refresh, api: @api).include? new_cat raise JSS::InvalidDataError, 'display_in must be true or false' unless display_in.jss_boolean? raise JSS::InvalidDataError, 'feature_in must be true or false' unless feature_in.jss_boolean? new_data = { name: new_cat } new_data[:display_in] = display_in if @self_service_data_config[:can_display_in_categories] new_data[:feature_in] = feature_in if @self_service_data_config[:can_feature_in_categories] # see if this category is already among our categories. idx = @self_service_categories.index { |c| c[:name] == new_cat } if idx @self_service_categories[idx] = new_data else @self_service_categories << new_data end @need_to_update = true end
ruby
def add_self_service_category(new_cat, display_in: true, feature_in: false) new_cat = JSS::Category.map_all_ids_to(:name, api: @api)[new_cat] if new_cat.is_a? Integer feature_in = false if display_in == false raise JSS::NoSuchItemError, "No category '#{new_cat}' in the JSS" unless JSS::Category.all_names(:refresh, api: @api).include? new_cat raise JSS::InvalidDataError, 'display_in must be true or false' unless display_in.jss_boolean? raise JSS::InvalidDataError, 'feature_in must be true or false' unless feature_in.jss_boolean? new_data = { name: new_cat } new_data[:display_in] = display_in if @self_service_data_config[:can_display_in_categories] new_data[:feature_in] = feature_in if @self_service_data_config[:can_feature_in_categories] # see if this category is already among our categories. idx = @self_service_categories.index { |c| c[:name] == new_cat } if idx @self_service_categories[idx] = new_data else @self_service_categories << new_data end @need_to_update = true end
[ "def", "add_self_service_category", "(", "new_cat", ",", "display_in", ":", "true", ",", "feature_in", ":", "false", ")", "new_cat", "=", "JSS", "::", "Category", ".", "map_all_ids_to", "(", ":name", ",", "api", ":", "@api", ")", "[", "new_cat", "]", "if", "new_cat", ".", "is_a?", "Integer", "feature_in", "=", "false", "if", "display_in", "==", "false", "raise", "JSS", "::", "NoSuchItemError", ",", "\"No category '#{new_cat}' in the JSS\"", "unless", "JSS", "::", "Category", ".", "all_names", "(", ":refresh", ",", "api", ":", "@api", ")", ".", "include?", "new_cat", "raise", "JSS", "::", "InvalidDataError", ",", "'display_in must be true or false'", "unless", "display_in", ".", "jss_boolean?", "raise", "JSS", "::", "InvalidDataError", ",", "'feature_in must be true or false'", "unless", "feature_in", ".", "jss_boolean?", "new_data", "=", "{", "name", ":", "new_cat", "}", "new_data", "[", ":display_in", "]", "=", "display_in", "if", "@self_service_data_config", "[", ":can_display_in_categories", "]", "new_data", "[", ":feature_in", "]", "=", "feature_in", "if", "@self_service_data_config", "[", ":can_feature_in_categories", "]", "# see if this category is already among our categories.", "idx", "=", "@self_service_categories", ".", "index", "{", "|", "c", "|", "c", "[", ":name", "]", "==", "new_cat", "}", "if", "idx", "@self_service_categories", "[", "idx", "]", "=", "new_data", "else", "@self_service_categories", "<<", "new_data", "end", "@need_to_update", "=", "true", "end" ]
Add or change one of the categories for this item in self service @param new_cat[String, Integer] the name or id of a category where this object should appear in SelfSvc @param display_in[Boolean] should this item appear in the SelfSvc page for the category? Only meaningful in applicable classes @param feature_in[Boolean] should this item be featured in the SelfSvc page for the category? Only meaningful in applicable classes. NOTE: this will always be false if display_in is false. @return [void]
[ "Add", "or", "change", "one", "of", "the", "categories", "for", "this", "item", "in", "self", "service" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L431-L454
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.self_service_user_removable=
def self_service_user_removable=(new_val, pw = @self_service_removal_password) new_val, pw = *new_val if new_val.is_a? Array pw = nil unless new_val == :with_auth return if new_val == self_service_user_removable && pw == self_service_removal_password validate_user_removable new_val @self_service_user_removable = new_val @self_service_removal_password = pw @need_to_update = true end
ruby
def self_service_user_removable=(new_val, pw = @self_service_removal_password) new_val, pw = *new_val if new_val.is_a? Array pw = nil unless new_val == :with_auth return if new_val == self_service_user_removable && pw == self_service_removal_password validate_user_removable new_val @self_service_user_removable = new_val @self_service_removal_password = pw @need_to_update = true end
[ "def", "self_service_user_removable", "=", "(", "new_val", ",", "pw", "=", "@self_service_removal_password", ")", "new_val", ",", "pw", "=", "new_val", "if", "new_val", ".", "is_a?", "Array", "pw", "=", "nil", "unless", "new_val", "==", ":with_auth", "return", "if", "new_val", "==", "self_service_user_removable", "&&", "pw", "==", "self_service_removal_password", "validate_user_removable", "new_val", "@self_service_user_removable", "=", "new_val", "@self_service_removal_password", "=", "pw", "@need_to_update", "=", "true", "end" ]
Set the value for user-removability of profiles, optionally providing a password for removal, on iOS targets. @param new_val[Symbol] One of the keys of PROFILE_REMOVAL_BY_USER, :always, :never, or :with_auth @param pw[String] A new password to use if removable :with_auth @return [void]
[ "Set", "the", "value", "for", "user", "-", "removability", "of", "profiles", "optionally", "providing", "a", "password", "for", "removal", "on", "iOS", "targets", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L479-L490
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.self_service_notification_type=
def self_service_notification_type=(type) validate_notifications_supported # HACK: Until jamf fixes bugs, you can only set notifications # :off or :ssvc_only. If you want :ssvc_and_nctr, you must # check the checkbox in the web-UI. if @self_service_data_config[:notifications_supported] == :ssvc_only && type != :ssvc_only raise "JAMF BUG: Until Jamf fixes API bugs in #{self.class}, you can only set Self Service notifications to :ssvc_only. Use the WebUI to activate Notification Center notifications" end raise JSS::InvalidDataError, "type must be one of: :#{NOTIFICATION_TYPES.keys.join ', :'}" unless NOTIFICATION_TYPES.key? type @self_service_notification_type = type @need_to_update = true end
ruby
def self_service_notification_type=(type) validate_notifications_supported # HACK: Until jamf fixes bugs, you can only set notifications # :off or :ssvc_only. If you want :ssvc_and_nctr, you must # check the checkbox in the web-UI. if @self_service_data_config[:notifications_supported] == :ssvc_only && type != :ssvc_only raise "JAMF BUG: Until Jamf fixes API bugs in #{self.class}, you can only set Self Service notifications to :ssvc_only. Use the WebUI to activate Notification Center notifications" end raise JSS::InvalidDataError, "type must be one of: :#{NOTIFICATION_TYPES.keys.join ', :'}" unless NOTIFICATION_TYPES.key? type @self_service_notification_type = type @need_to_update = true end
[ "def", "self_service_notification_type", "=", "(", "type", ")", "validate_notifications_supported", "# HACK: Until jamf fixes bugs, you can only set notifications", "# :off or :ssvc_only. If you want :ssvc_and_nctr, you must", "# check the checkbox in the web-UI.", "if", "@self_service_data_config", "[", ":notifications_supported", "]", "==", ":ssvc_only", "&&", "type", "!=", ":ssvc_only", "raise", "\"JAMF BUG: Until Jamf fixes API bugs in #{self.class}, you can only set Self Service notifications to :ssvc_only. Use the WebUI to activate Notification Center notifications\"", "end", "raise", "JSS", "::", "InvalidDataError", ",", "\"type must be one of: :#{NOTIFICATION_TYPES.keys.join ', :'}\"", "unless", "NOTIFICATION_TYPES", ".", "key?", "type", "@self_service_notification_type", "=", "type", "@need_to_update", "=", "true", "end" ]
How should self service notifications be displayed @param type[Symbol] A key from SelfServable::NOTIFICATION_TYPES @return [void]
[ "How", "should", "self", "service", "notifications", "be", "displayed" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L512-L526
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.self_service_reminder_frequency=
def self_service_reminder_frequency=(days) return if days == self_service_reminder_frequency validate_notification_reminders_supported JSS::Validate.integer days @self_service_reminder_frequency = days @need_to_update = true end
ruby
def self_service_reminder_frequency=(days) return if days == self_service_reminder_frequency validate_notification_reminders_supported JSS::Validate.integer days @self_service_reminder_frequency = days @need_to_update = true end
[ "def", "self_service_reminder_frequency", "=", "(", "days", ")", "return", "if", "days", "==", "self_service_reminder_frequency", "validate_notification_reminders_supported", "JSS", "::", "Validate", ".", "integer", "days", "@self_service_reminder_frequency", "=", "days", "@need_to_update", "=", "true", "end" ]
set reminder notification frequency @param new_val[Integer] How many days between reminder notifications? @return [void]
[ "set", "reminder", "notification", "frequency" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L572-L578
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.icon=
def icon=(new_icon) if new_icon.is_a? Integer return if @icon && new_icon == @icon.id validate_icon new_icon @new_icon_id = new_icon @need_to_update = true else unless uploadable? && defined?(self.class::UPLOAD_TYPES) && self.class::UPLOAD_TYPES.key?(:icon) raise JSS::UnsupportedError, "Class #{self.class} does not support icon uploads." end new_icon = Pathname.new new_icon upload(:icon, new_icon) refresh_icon end # new_icon.is_a? Integer new_icon end
ruby
def icon=(new_icon) if new_icon.is_a? Integer return if @icon && new_icon == @icon.id validate_icon new_icon @new_icon_id = new_icon @need_to_update = true else unless uploadable? && defined?(self.class::UPLOAD_TYPES) && self.class::UPLOAD_TYPES.key?(:icon) raise JSS::UnsupportedError, "Class #{self.class} does not support icon uploads." end new_icon = Pathname.new new_icon upload(:icon, new_icon) refresh_icon end # new_icon.is_a? Integer new_icon end
[ "def", "icon", "=", "(", "new_icon", ")", "if", "new_icon", ".", "is_a?", "Integer", "return", "if", "@icon", "&&", "new_icon", "==", "@icon", ".", "id", "validate_icon", "new_icon", "@new_icon_id", "=", "new_icon", "@need_to_update", "=", "true", "else", "unless", "uploadable?", "&&", "defined?", "(", "self", ".", "class", "::", "UPLOAD_TYPES", ")", "&&", "self", ".", "class", "::", "UPLOAD_TYPES", ".", "key?", "(", ":icon", ")", "raise", "JSS", "::", "UnsupportedError", ",", "\"Class #{self.class} does not support icon uploads.\"", "end", "new_icon", "=", "Pathname", ".", "new", "new_icon", "upload", "(", ":icon", ",", "new_icon", ")", "refresh_icon", "end", "# new_icon.is_a? Integer", "new_icon", "end" ]
Set a new Self Service icon for this object. Since JSS::Icon objects are read-only, the icon can only be changed by supplying the id number of an icon already existing in the JSS, or a path to a local file, which will be uploaded to the JSS and added to this instance. Uploads take effect immediately, but if an integer is supplied, the change must be sent to the JSS via {#update} or {#create} @param new_icon[Integer, String, Pathname] The id or path to the new icon. @return [false, Integer, Pathname] false means no change was made.
[ "Set", "a", "new", "Self", "Service", "icon", "for", "this", "object", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L594-L609
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.parse_self_service_notifications
def parse_self_service_notifications(ss_data) return unless @self_service_data_config[:notifications_supported] # oldstyle/broken, we need the XML to know if notifications are turned on if @self_service_data_config[:notifications_supported] == :ssvc_only && @in_jss ssrsrc = "#{rest_rsrc}/subset/selfservice" raw_xml = api.get_rsrc(ssrsrc, :xml) @self_service_notifications_enabled = raw_xml.include? '<notification>true</notification>' @self_service_notification_type = NOTIFICATION_TYPES.invert[ss_data[:notification]] @self_service_notification_subject = ss_data[:notification_subject] @self_service_notification_message = ss_data[:notification_message] return end # newstyle, 'notifications' subset notif_data = ss_data[:notifications] notif_data ||= {} @self_service_notifications_enabled = notif_data[:notification_enabled] @self_service_notification_type = NOTIFICATION_TYPES.invert[notif_data[:notification_type]] @self_service_notification_type ||= DFT_NOTIFICATION_TYPE @self_service_notification_subject = notif_data[:notification_subject] @self_service_notification_message = notif_data[:notification_message] reminders = notif_data[:reminders] reminders ||= {} @self_service_reminders_enabled = reminders[:notification_reminders_enabled] @self_service_reminder_frequency = reminders[:notification_reminder_frequency] end
ruby
def parse_self_service_notifications(ss_data) return unless @self_service_data_config[:notifications_supported] # oldstyle/broken, we need the XML to know if notifications are turned on if @self_service_data_config[:notifications_supported] == :ssvc_only && @in_jss ssrsrc = "#{rest_rsrc}/subset/selfservice" raw_xml = api.get_rsrc(ssrsrc, :xml) @self_service_notifications_enabled = raw_xml.include? '<notification>true</notification>' @self_service_notification_type = NOTIFICATION_TYPES.invert[ss_data[:notification]] @self_service_notification_subject = ss_data[:notification_subject] @self_service_notification_message = ss_data[:notification_message] return end # newstyle, 'notifications' subset notif_data = ss_data[:notifications] notif_data ||= {} @self_service_notifications_enabled = notif_data[:notification_enabled] @self_service_notification_type = NOTIFICATION_TYPES.invert[notif_data[:notification_type]] @self_service_notification_type ||= DFT_NOTIFICATION_TYPE @self_service_notification_subject = notif_data[:notification_subject] @self_service_notification_message = notif_data[:notification_message] reminders = notif_data[:reminders] reminders ||= {} @self_service_reminders_enabled = reminders[:notification_reminders_enabled] @self_service_reminder_frequency = reminders[:notification_reminder_frequency] end
[ "def", "parse_self_service_notifications", "(", "ss_data", ")", "return", "unless", "@self_service_data_config", "[", ":notifications_supported", "]", "# oldstyle/broken, we need the XML to know if notifications are turned on", "if", "@self_service_data_config", "[", ":notifications_supported", "]", "==", ":ssvc_only", "&&", "@in_jss", "ssrsrc", "=", "\"#{rest_rsrc}/subset/selfservice\"", "raw_xml", "=", "api", ".", "get_rsrc", "(", "ssrsrc", ",", ":xml", ")", "@self_service_notifications_enabled", "=", "raw_xml", ".", "include?", "'<notification>true</notification>'", "@self_service_notification_type", "=", "NOTIFICATION_TYPES", ".", "invert", "[", "ss_data", "[", ":notification", "]", "]", "@self_service_notification_subject", "=", "ss_data", "[", ":notification_subject", "]", "@self_service_notification_message", "=", "ss_data", "[", ":notification_message", "]", "return", "end", "# newstyle, 'notifications' subset", "notif_data", "=", "ss_data", "[", ":notifications", "]", "notif_data", "||=", "{", "}", "@self_service_notifications_enabled", "=", "notif_data", "[", ":notification_enabled", "]", "@self_service_notification_type", "=", "NOTIFICATION_TYPES", ".", "invert", "[", "notif_data", "[", ":notification_type", "]", "]", "@self_service_notification_type", "||=", "DFT_NOTIFICATION_TYPE", "@self_service_notification_subject", "=", "notif_data", "[", ":notification_subject", "]", "@self_service_notification_message", "=", "notif_data", "[", ":notification_message", "]", "reminders", "=", "notif_data", "[", ":reminders", "]", "reminders", "||=", "{", "}", "@self_service_reminders_enabled", "=", "reminders", "[", ":notification_reminders_enabled", "]", "@self_service_reminder_frequency", "=", "reminders", "[", ":notification_reminder_frequency", "]", "end" ]
parse incoming ssvc notification settings
[ "parse", "incoming", "ssvc", "notification", "settings" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L760-L788
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_self_service_xml
def add_self_service_xml(xdoc) doc_root = xdoc.root # whether or not we're in self service is usually not in the # ssvc subset... add_in_self_service_xml doc_root subset_key = @self_service_data_config[:self_service_subset] ? @self_service_data_config[:self_service_subset] : :self_service ssvc = doc_root.add_element subset_key.to_s ssvc.add_element('self_service_description').text = @self_service_description if @self_service_description ssvc.add_element('feature_on_main_page').text = @self_service_feature_on_main_page if @new_icon_id icon = ssvc.add_element('self_service_icon') icon.add_element('id').text = @new_icon_id end add_self_service_category_xml ssvc add_self_service_profile_xml ssvc, doc_root add_self_service_macos_xml ssvc add_self_service_notification_xml ssvc end
ruby
def add_self_service_xml(xdoc) doc_root = xdoc.root # whether or not we're in self service is usually not in the # ssvc subset... add_in_self_service_xml doc_root subset_key = @self_service_data_config[:self_service_subset] ? @self_service_data_config[:self_service_subset] : :self_service ssvc = doc_root.add_element subset_key.to_s ssvc.add_element('self_service_description').text = @self_service_description if @self_service_description ssvc.add_element('feature_on_main_page').text = @self_service_feature_on_main_page if @new_icon_id icon = ssvc.add_element('self_service_icon') icon.add_element('id').text = @new_icon_id end add_self_service_category_xml ssvc add_self_service_profile_xml ssvc, doc_root add_self_service_macos_xml ssvc add_self_service_notification_xml ssvc end
[ "def", "add_self_service_xml", "(", "xdoc", ")", "doc_root", "=", "xdoc", ".", "root", "# whether or not we're in self service is usually not in the", "# ssvc subset...", "add_in_self_service_xml", "doc_root", "subset_key", "=", "@self_service_data_config", "[", ":self_service_subset", "]", "?", "@self_service_data_config", "[", ":self_service_subset", "]", ":", ":self_service", "ssvc", "=", "doc_root", ".", "add_element", "subset_key", ".", "to_s", "ssvc", ".", "add_element", "(", "'self_service_description'", ")", ".", "text", "=", "@self_service_description", "if", "@self_service_description", "ssvc", ".", "add_element", "(", "'feature_on_main_page'", ")", ".", "text", "=", "@self_service_feature_on_main_page", "if", "@new_icon_id", "icon", "=", "ssvc", ".", "add_element", "(", "'self_service_icon'", ")", "icon", ".", "add_element", "(", "'id'", ")", ".", "text", "=", "@new_icon_id", "end", "add_self_service_category_xml", "ssvc", "add_self_service_profile_xml", "ssvc", ",", "doc_root", "add_self_service_macos_xml", "ssvc", "add_self_service_notification_xml", "ssvc", "end" ]
refresh icon Add approriate XML for self service data to the XML document for this item. @param xdoc[REXML::Document] The XML Document to which we're adding Self Service data @return [void]
[ "refresh", "icon", "Add", "approriate", "XML", "for", "self", "service", "data", "to", "the", "XML", "document", "for", "this", "item", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L814-L840
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_in_self_service_xml
def add_in_self_service_xml(doc_root) return unless @self_service_data_config[:in_self_service_data_path] in_ss_section, in_ss_elem = @self_service_data_config[:in_self_service_data_path] in_ss_value = @in_self_service ? @self_service_data_config[:in_self_service] : @self_service_data_config[:not_in_self_service] in_ss_section_xml = doc_root.elements[in_ss_section.to_s] in_ss_section_xml ||= doc_root.add_element(in_ss_section.to_s) in_ss_section_xml.add_element(in_ss_elem.to_s).text = in_ss_value.to_s end
ruby
def add_in_self_service_xml(doc_root) return unless @self_service_data_config[:in_self_service_data_path] in_ss_section, in_ss_elem = @self_service_data_config[:in_self_service_data_path] in_ss_value = @in_self_service ? @self_service_data_config[:in_self_service] : @self_service_data_config[:not_in_self_service] in_ss_section_xml = doc_root.elements[in_ss_section.to_s] in_ss_section_xml ||= doc_root.add_element(in_ss_section.to_s) in_ss_section_xml.add_element(in_ss_elem.to_s).text = in_ss_value.to_s end
[ "def", "add_in_self_service_xml", "(", "doc_root", ")", "return", "unless", "@self_service_data_config", "[", ":in_self_service_data_path", "]", "in_ss_section", ",", "in_ss_elem", "=", "@self_service_data_config", "[", ":in_self_service_data_path", "]", "in_ss_value", "=", "@in_self_service", "?", "@self_service_data_config", "[", ":in_self_service", "]", ":", "@self_service_data_config", "[", ":not_in_self_service", "]", "in_ss_section_xml", "=", "doc_root", ".", "elements", "[", "in_ss_section", ".", "to_s", "]", "in_ss_section_xml", "||=", "doc_root", ".", "add_element", "(", "in_ss_section", ".", "to_s", ")", "in_ss_section_xml", ".", "add_element", "(", "in_ss_elem", ".", "to_s", ")", ".", "text", "=", "in_ss_value", ".", "to_s", "end" ]
add_self_service_xml add the correct XML indicating whether or not we're even in SSvc
[ "add_self_service_xml", "add", "the", "correct", "XML", "indicating", "whether", "or", "not", "we", "re", "even", "in", "SSvc" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L843-L853
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_self_service_profile_xml
def add_self_service_profile_xml(ssvc, doc_root) return unless self_service_payload == :profile if self_service_targets.include? :ios sec = ssvc.add_element('security') sec.add_element('removal_disallowed').text = PROFILE_REMOVAL_BY_USER[@self_service_user_removable] sec.add_element('password').text = @self_service_removal_password.to_s return end gen = doc_root.elements['general'] gen.add_element('user_removable').text = (@self_service_user_removable == :always).to_s end
ruby
def add_self_service_profile_xml(ssvc, doc_root) return unless self_service_payload == :profile if self_service_targets.include? :ios sec = ssvc.add_element('security') sec.add_element('removal_disallowed').text = PROFILE_REMOVAL_BY_USER[@self_service_user_removable] sec.add_element('password').text = @self_service_removal_password.to_s return end gen = doc_root.elements['general'] gen.add_element('user_removable').text = (@self_service_user_removable == :always).to_s end
[ "def", "add_self_service_profile_xml", "(", "ssvc", ",", "doc_root", ")", "return", "unless", "self_service_payload", "==", ":profile", "if", "self_service_targets", ".", "include?", ":ios", "sec", "=", "ssvc", ".", "add_element", "(", "'security'", ")", "sec", ".", "add_element", "(", "'removal_disallowed'", ")", ".", "text", "=", "PROFILE_REMOVAL_BY_USER", "[", "@self_service_user_removable", "]", "sec", ".", "add_element", "(", "'password'", ")", ".", "text", "=", "@self_service_removal_password", ".", "to_s", "return", "end", "gen", "=", "doc_root", ".", "elements", "[", "'general'", "]", "gen", ".", "add_element", "(", "'user_removable'", ")", ".", "text", "=", "(", "@self_service_user_removable", "==", ":always", ")", ".", "to_s", "end" ]
add the xml specific to profiles
[ "add", "the", "xml", "specific", "to", "profiles" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L856-L866
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_self_service_category_xml
def add_self_service_category_xml(ssvc) cats = ssvc.add_element('self_service_categories') return if self_service_categories.empty? self_service_categories.each do |cat| catelem = cats.add_element('category') catelem.add_element('name').text = cat[:name] catelem.add_element('display_in').text = cat[:display_in] if @self_service_data_config[:can_display_in_categories] catelem.add_element('feature_in').text = cat[:feature_in] if @self_service_data_config[:can_feature_in_categories] end end
ruby
def add_self_service_category_xml(ssvc) cats = ssvc.add_element('self_service_categories') return if self_service_categories.empty? self_service_categories.each do |cat| catelem = cats.add_element('category') catelem.add_element('name').text = cat[:name] catelem.add_element('display_in').text = cat[:display_in] if @self_service_data_config[:can_display_in_categories] catelem.add_element('feature_in').text = cat[:feature_in] if @self_service_data_config[:can_feature_in_categories] end end
[ "def", "add_self_service_category_xml", "(", "ssvc", ")", "cats", "=", "ssvc", ".", "add_element", "(", "'self_service_categories'", ")", "return", "if", "self_service_categories", ".", "empty?", "self_service_categories", ".", "each", "do", "|", "cat", "|", "catelem", "=", "cats", ".", "add_element", "(", "'category'", ")", "catelem", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "cat", "[", ":name", "]", "catelem", ".", "add_element", "(", "'display_in'", ")", ".", "text", "=", "cat", "[", ":display_in", "]", "if", "@self_service_data_config", "[", ":can_display_in_categories", "]", "catelem", ".", "add_element", "(", "'feature_in'", ")", ".", "text", "=", "cat", "[", ":feature_in", "]", "if", "@self_service_data_config", "[", ":can_feature_in_categories", "]", "end", "end" ]
add the xml for self-service categories
[ "add", "the", "xml", "for", "self", "-", "service", "categories" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L869-L878
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_self_service_macos_xml
def add_self_service_macos_xml(ssvc) return unless self_service_targets.include? :macos ssvc.add_element('self_service_display_name').text = self_service_display_name if self_service_display_name ssvc.add_element('install_button_text').text = self_service_install_button_text if self_service_install_button_text ssvc.add_element('reinstall_button_text').text = self_service_reinstall_button_text if self_service_reinstall_button_text ssvc.add_element('force_users_to_view_description').text = self_service_force_users_to_view_description.to_s end
ruby
def add_self_service_macos_xml(ssvc) return unless self_service_targets.include? :macos ssvc.add_element('self_service_display_name').text = self_service_display_name if self_service_display_name ssvc.add_element('install_button_text').text = self_service_install_button_text if self_service_install_button_text ssvc.add_element('reinstall_button_text').text = self_service_reinstall_button_text if self_service_reinstall_button_text ssvc.add_element('force_users_to_view_description').text = self_service_force_users_to_view_description.to_s end
[ "def", "add_self_service_macos_xml", "(", "ssvc", ")", "return", "unless", "self_service_targets", ".", "include?", ":macos", "ssvc", ".", "add_element", "(", "'self_service_display_name'", ")", ".", "text", "=", "self_service_display_name", "if", "self_service_display_name", "ssvc", ".", "add_element", "(", "'install_button_text'", ")", ".", "text", "=", "self_service_install_button_text", "if", "self_service_install_button_text", "ssvc", ".", "add_element", "(", "'reinstall_button_text'", ")", ".", "text", "=", "self_service_reinstall_button_text", "if", "self_service_reinstall_button_text", "ssvc", ".", "add_element", "(", "'force_users_to_view_description'", ")", ".", "text", "=", "self_service_force_users_to_view_description", ".", "to_s", "end" ]
set macOS settings in ssvc xml
[ "set", "macOS", "settings", "in", "ssvc", "xml" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L881-L887
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.add_self_service_notification_xml
def add_self_service_notification_xml(ssvc) return unless @self_service_data_config[:notifications_supported] # oldstyle/broken, only sscv notifs if @self_service_data_config[:notifications_supported] == :ssvc_only ssvc.add_element('notification').text = self_service_notifications_enabled.to_s ssvc.add_element('notification_subject').text = self_service_notification_subject if self_service_notification_subject ssvc.add_element('notification_message').text = self_service_notification_message if self_service_notification_message return end # newstyle, 'notifications' subset notif = ssvc.add_element('notifications') notif.add_element('notifications_enabled').text = self_service_notifications_enabled.to_s notif.add_element('notification_type').text = NOTIFICATION_TYPES[self_service_notification_type] if self_service_notification_type notif.add_element('notification_subject').text = self_service_notification_subject if self_service_notification_subject notif.add_element('notification_message').text = self_service_notification_message if self_service_notification_message return unless @self_service_data_config[:notification_reminders] reminds = notif.add_element('reminders') reminds.add_element('notification_reminders_enabled').text = self_service_reminders_enabled.to_s reminds.add_element('notification_reminder_frequency').text = self_service_reminder_frequency.to_s if self_service_reminder_frequency end
ruby
def add_self_service_notification_xml(ssvc) return unless @self_service_data_config[:notifications_supported] # oldstyle/broken, only sscv notifs if @self_service_data_config[:notifications_supported] == :ssvc_only ssvc.add_element('notification').text = self_service_notifications_enabled.to_s ssvc.add_element('notification_subject').text = self_service_notification_subject if self_service_notification_subject ssvc.add_element('notification_message').text = self_service_notification_message if self_service_notification_message return end # newstyle, 'notifications' subset notif = ssvc.add_element('notifications') notif.add_element('notifications_enabled').text = self_service_notifications_enabled.to_s notif.add_element('notification_type').text = NOTIFICATION_TYPES[self_service_notification_type] if self_service_notification_type notif.add_element('notification_subject').text = self_service_notification_subject if self_service_notification_subject notif.add_element('notification_message').text = self_service_notification_message if self_service_notification_message return unless @self_service_data_config[:notification_reminders] reminds = notif.add_element('reminders') reminds.add_element('notification_reminders_enabled').text = self_service_reminders_enabled.to_s reminds.add_element('notification_reminder_frequency').text = self_service_reminder_frequency.to_s if self_service_reminder_frequency end
[ "def", "add_self_service_notification_xml", "(", "ssvc", ")", "return", "unless", "@self_service_data_config", "[", ":notifications_supported", "]", "# oldstyle/broken, only sscv notifs", "if", "@self_service_data_config", "[", ":notifications_supported", "]", "==", ":ssvc_only", "ssvc", ".", "add_element", "(", "'notification'", ")", ".", "text", "=", "self_service_notifications_enabled", ".", "to_s", "ssvc", ".", "add_element", "(", "'notification_subject'", ")", ".", "text", "=", "self_service_notification_subject", "if", "self_service_notification_subject", "ssvc", ".", "add_element", "(", "'notification_message'", ")", ".", "text", "=", "self_service_notification_message", "if", "self_service_notification_message", "return", "end", "# newstyle, 'notifications' subset", "notif", "=", "ssvc", ".", "add_element", "(", "'notifications'", ")", "notif", ".", "add_element", "(", "'notifications_enabled'", ")", ".", "text", "=", "self_service_notifications_enabled", ".", "to_s", "notif", ".", "add_element", "(", "'notification_type'", ")", ".", "text", "=", "NOTIFICATION_TYPES", "[", "self_service_notification_type", "]", "if", "self_service_notification_type", "notif", ".", "add_element", "(", "'notification_subject'", ")", ".", "text", "=", "self_service_notification_subject", "if", "self_service_notification_subject", "notif", ".", "add_element", "(", "'notification_message'", ")", ".", "text", "=", "self_service_notification_message", "if", "self_service_notification_message", "return", "unless", "@self_service_data_config", "[", ":notification_reminders", "]", "reminds", "=", "notif", ".", "add_element", "(", "'reminders'", ")", "reminds", ".", "add_element", "(", "'notification_reminders_enabled'", ")", ".", "text", "=", "self_service_reminders_enabled", ".", "to_s", "reminds", ".", "add_element", "(", "'notification_reminder_frequency'", ")", ".", "text", "=", "self_service_reminder_frequency", ".", "to_s", "if", "self_service_reminder_frequency", "end" ]
set ssvc notification settings in xml
[ "set", "ssvc", "notification", "settings", "in", "xml" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L891-L915
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.validate_user_removable
def validate_user_removable(new_val) raise JSS::UnsupportedError, 'User removal settings not applicable to this class' unless self_service_payload == :profile raise JSS::UnsupportedError, 'Removal :with_auth not applicable to this class' if new_val == :with_auth && !self_service_targets.include?(:ios) raise JSS::InvalidDataError, "Value must be one of: :#{PROFILE_REMOVAL_BY_USER.keys.join(', :')}" unless PROFILE_REMOVAL_BY_USER.key?(new_val) end
ruby
def validate_user_removable(new_val) raise JSS::UnsupportedError, 'User removal settings not applicable to this class' unless self_service_payload == :profile raise JSS::UnsupportedError, 'Removal :with_auth not applicable to this class' if new_val == :with_auth && !self_service_targets.include?(:ios) raise JSS::InvalidDataError, "Value must be one of: :#{PROFILE_REMOVAL_BY_USER.keys.join(', :')}" unless PROFILE_REMOVAL_BY_USER.key?(new_val) end
[ "def", "validate_user_removable", "(", "new_val", ")", "raise", "JSS", "::", "UnsupportedError", ",", "'User removal settings not applicable to this class'", "unless", "self_service_payload", "==", ":profile", "raise", "JSS", "::", "UnsupportedError", ",", "'Removal :with_auth not applicable to this class'", "if", "new_val", "==", ":with_auth", "&&", "!", "self_service_targets", ".", "include?", "(", ":ios", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"Value must be one of: :#{PROFILE_REMOVAL_BY_USER.keys.join(', :')}\"", "unless", "PROFILE_REMOVAL_BY_USER", ".", "key?", "(", "new_val", ")", "end" ]
Raise an error if user_removable settings are wrong
[ "Raise", "an", "error", "if", "user_removable", "settings", "are", "wrong" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L918-L924
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/self_servable.rb
JSS.SelfServable.validate_icon
def validate_icon(id) return nil unless JSS::DB_CNX.connected? raise JSS::NoSuchItemError, "No icon with id #{id}" unless JSS::Icon.all_ids.include? id end
ruby
def validate_icon(id) return nil unless JSS::DB_CNX.connected? raise JSS::NoSuchItemError, "No icon with id #{id}" unless JSS::Icon.all_ids.include? id end
[ "def", "validate_icon", "(", "id", ")", "return", "nil", "unless", "JSS", "::", "DB_CNX", ".", "connected?", "raise", "JSS", "::", "NoSuchItemError", ",", "\"No icon with id #{id}\"", "unless", "JSS", "::", "Icon", ".", "all_ids", ".", "include?", "id", "end" ]
Raise an error if an icon id is not valid
[ "Raise", "an", "error", "if", "an", "icon", "id", "is", "not", "valid" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/self_servable.rb#L927-L930
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/advanced_search.rb
JSS.AdvancedSearch.update
def update(get_results = false) orig_timeout = @api.cnx.options[:timeout] @api.timeout = 1800 super() requery_search_results if get_results @api.timeout = orig_timeout @id # remember to return the id end
ruby
def update(get_results = false) orig_timeout = @api.cnx.options[:timeout] @api.timeout = 1800 super() requery_search_results if get_results @api.timeout = orig_timeout @id # remember to return the id end
[ "def", "update", "(", "get_results", "=", "false", ")", "orig_timeout", "=", "@api", ".", "cnx", ".", "options", "[", ":timeout", "]", "@api", ".", "timeout", "=", "1800", "super", "(", ")", "requery_search_results", "if", "get_results", "@api", ".", "timeout", "=", "orig_timeout", "@id", "# remember to return the id", "end" ]
Save any changes If get_results is true, they'll be available in {#search_results}. This might be slow. @param get_results[Boolean] should the results of the search be queried immediately? @return [Integer] the id of the updated search
[ "Save", "any", "changes" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/advanced_search.rb#L191-L199
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/advanced_search.rb
JSS.AdvancedSearch.requery_search_results
def requery_search_results orig_open_timeout = @api.cnx.options[:open_timeout] orig_timeout = @api.cnx.options[:timeout] @api.timeout = 1800 @api.open_timeout = 1800 begin requery = self.class.fetch(id: @id) @search_results = requery.search_results @result_display_keys = requery.result_display_keys ensure @api.timeout = orig_timeout @api.open_timeout = orig_open_timeout end end
ruby
def requery_search_results orig_open_timeout = @api.cnx.options[:open_timeout] orig_timeout = @api.cnx.options[:timeout] @api.timeout = 1800 @api.open_timeout = 1800 begin requery = self.class.fetch(id: @id) @search_results = requery.search_results @result_display_keys = requery.result_display_keys ensure @api.timeout = orig_timeout @api.open_timeout = orig_open_timeout end end
[ "def", "requery_search_results", "orig_open_timeout", "=", "@api", ".", "cnx", ".", "options", "[", ":open_timeout", "]", "orig_timeout", "=", "@api", ".", "cnx", ".", "options", "[", ":timeout", "]", "@api", ".", "timeout", "=", "1800", "@api", ".", "open_timeout", "=", "1800", "begin", "requery", "=", "self", ".", "class", ".", "fetch", "(", "id", ":", "@id", ")", "@search_results", "=", "requery", ".", "search_results", "@result_display_keys", "=", "requery", ".", "result_display_keys", "ensure", "@api", ".", "timeout", "=", "orig_timeout", "@api", ".", "open_timeout", "=", "orig_open_timeout", "end", "end" ]
Requery the API for the search results. This can be very slow, so temporarily reset the API timeout to 30 minutes @return [Array<Hash>] the new search results
[ "Requery", "the", "API", "for", "the", "search", "results", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/advanced_search.rb#L207-L220
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/advanced_search.rb
JSS.AdvancedSearch.display_fields=
def display_fields=(new_val) raise JSS::InvalidDataError, 'display_fields must be an Array.' unless new_val.is_a? Array return if new_val.sort == @display_fields.sort @display_fields = new_val @need_to_update = true end
ruby
def display_fields=(new_val) raise JSS::InvalidDataError, 'display_fields must be an Array.' unless new_val.is_a? Array return if new_val.sort == @display_fields.sort @display_fields = new_val @need_to_update = true end
[ "def", "display_fields", "=", "(", "new_val", ")", "raise", "JSS", "::", "InvalidDataError", ",", "'display_fields must be an Array.'", "unless", "new_val", ".", "is_a?", "Array", "return", "if", "new_val", ".", "sort", "==", "@display_fields", ".", "sort", "@display_fields", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set the list of fields to be retrieved with the search results. @param new_val[Array<String>] the new field names
[ "Set", "the", "list", "of", "fields", "to", "be", "retrieved", "with", "the", "search", "results", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/advanced_search.rb#L244-L249
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/advanced_search.rb
JSS.AdvancedSearch.export
def export(output_file, format = :csv, overwrite = false) raise JSS::InvalidDataError, "Export format must be one of: :#{EXPORT_FORMATS.join ', :'}" unless EXPORT_FORMATS.include? format out = Pathname.new output_file unless overwrite raise JSS::AlreadyExistsError, "The output file already exists: #{out}" if out.exist? end case format when :csv require 'csv' CSV.open(out.to_s, 'wb') do |csv| csv << @result_display_keys @search_results.each do |row| csv << @result_display_keys.map { |key| row[key] } end # each do row end # CSV.open when :tab tabbed = @result_display_keys.join("\t") + "\n" @search_results.each do |row| tabbed << @result_display_keys.map { |key| row[key] }.join("\t") + "\n" end # each do row out.jss_save tabbed.chomp else # :xml doc = REXML::Document.new '<?xml version="1.0" encoding="ISO-8859-1"?>' members = doc.add_element self.class::RESULT_CLASS::RSRC_LIST_KEY.to_s @search_results.each do |row| member = members.add_element self.class::RESULT_CLASS::RSRC_OBJECT_KEY.to_s @result_display_keys.each do |field| member.add_element(field.to_s.tr(' ', '_')).text = row[field].empty? ? nil : row[field] end # ech do field end # each do row out.jss_save doc.to_s.gsub('><', ">\n<") end # case out end
ruby
def export(output_file, format = :csv, overwrite = false) raise JSS::InvalidDataError, "Export format must be one of: :#{EXPORT_FORMATS.join ', :'}" unless EXPORT_FORMATS.include? format out = Pathname.new output_file unless overwrite raise JSS::AlreadyExistsError, "The output file already exists: #{out}" if out.exist? end case format when :csv require 'csv' CSV.open(out.to_s, 'wb') do |csv| csv << @result_display_keys @search_results.each do |row| csv << @result_display_keys.map { |key| row[key] } end # each do row end # CSV.open when :tab tabbed = @result_display_keys.join("\t") + "\n" @search_results.each do |row| tabbed << @result_display_keys.map { |key| row[key] }.join("\t") + "\n" end # each do row out.jss_save tabbed.chomp else # :xml doc = REXML::Document.new '<?xml version="1.0" encoding="ISO-8859-1"?>' members = doc.add_element self.class::RESULT_CLASS::RSRC_LIST_KEY.to_s @search_results.each do |row| member = members.add_element self.class::RESULT_CLASS::RSRC_OBJECT_KEY.to_s @result_display_keys.each do |field| member.add_element(field.to_s.tr(' ', '_')).text = row[field].empty? ? nil : row[field] end # ech do field end # each do row out.jss_save doc.to_s.gsub('><', ">\n<") end # case out end
[ "def", "export", "(", "output_file", ",", "format", "=", ":csv", ",", "overwrite", "=", "false", ")", "raise", "JSS", "::", "InvalidDataError", ",", "\"Export format must be one of: :#{EXPORT_FORMATS.join ', :'}\"", "unless", "EXPORT_FORMATS", ".", "include?", "format", "out", "=", "Pathname", ".", "new", "output_file", "unless", "overwrite", "raise", "JSS", "::", "AlreadyExistsError", ",", "\"The output file already exists: #{out}\"", "if", "out", ".", "exist?", "end", "case", "format", "when", ":csv", "require", "'csv'", "CSV", ".", "open", "(", "out", ".", "to_s", ",", "'wb'", ")", "do", "|", "csv", "|", "csv", "<<", "@result_display_keys", "@search_results", ".", "each", "do", "|", "row", "|", "csv", "<<", "@result_display_keys", ".", "map", "{", "|", "key", "|", "row", "[", "key", "]", "}", "end", "# each do row", "end", "# CSV.open", "when", ":tab", "tabbed", "=", "@result_display_keys", ".", "join", "(", "\"\\t\"", ")", "+", "\"\\n\"", "@search_results", ".", "each", "do", "|", "row", "|", "tabbed", "<<", "@result_display_keys", ".", "map", "{", "|", "key", "|", "row", "[", "key", "]", "}", ".", "join", "(", "\"\\t\"", ")", "+", "\"\\n\"", "end", "# each do row", "out", ".", "jss_save", "tabbed", ".", "chomp", "else", "# :xml", "doc", "=", "REXML", "::", "Document", ".", "new", "'<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>'", "members", "=", "doc", ".", "add_element", "self", ".", "class", "::", "RESULT_CLASS", "::", "RSRC_LIST_KEY", ".", "to_s", "@search_results", ".", "each", "do", "|", "row", "|", "member", "=", "members", ".", "add_element", "self", ".", "class", "::", "RESULT_CLASS", "::", "RSRC_OBJECT_KEY", ".", "to_s", "@result_display_keys", ".", "each", "do", "|", "field", "|", "member", ".", "add_element", "(", "field", ".", "to_s", ".", "tr", "(", "' '", ",", "'_'", ")", ")", ".", "text", "=", "row", "[", "field", "]", ".", "empty?", "?", "nil", ":", "row", "[", "field", "]", "end", "# ech do field", "end", "# each do row", "out", ".", "jss_save", "doc", ".", "to_s", ".", "gsub", "(", "'><'", ",", "\">\\n<\"", ")", "end", "# case", "out", "end" ]
Export the display fields of the search results to a file. @param output_file[String,Pathname] The file in which to store the exported results @param format[Symbol] one of :csv, :tab, or :xml, defaults to :csv @param overwrite[Boolean] should the output_file be overwrite if it exists? Defaults to false @return [Pathname] the path to the output file @note This method only exports the display fields defined in this advanced search for the search_result members (computers, mobile_devices, or users) It doesn't currently provide the ability to export subsets of info about those objects, as the Web UI does (e.g. group memberships, applications, receipts, etc)
[ "Export", "the", "display", "fields", "of", "the", "search", "results", "to", "a", "file", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/advanced_search.rb#L272-L311
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/advanced_search.rb
JSS.AdvancedSearch.rest_xml
def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER acs = doc.add_element self.class::RSRC_OBJECT_KEY.to_s acs.add_element('name').text = @name acs.add_element('sort_1').text = @sort_1 if @sort_1 acs.add_element('sort_2').text = @sort_2 if @sort_2 acs.add_element('sort_3').text = @sort_3 if @sort_3 acs << @criteria.rest_xml df = acs.add_element('display_fields') @display_fields.each { |f| df.add_element('display_field').add_element('name').text = f } add_site_to_xml(doc) doc.to_s end
ruby
def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER acs = doc.add_element self.class::RSRC_OBJECT_KEY.to_s acs.add_element('name').text = @name acs.add_element('sort_1').text = @sort_1 if @sort_1 acs.add_element('sort_2').text = @sort_2 if @sort_2 acs.add_element('sort_3').text = @sort_3 if @sort_3 acs << @criteria.rest_xml df = acs.add_element('display_fields') @display_fields.each { |f| df.add_element('display_field').add_element('name').text = f } add_site_to_xml(doc) doc.to_s end
[ "def", "rest_xml", "doc", "=", "REXML", "::", "Document", ".", "new", "APIConnection", "::", "XML_HEADER", "acs", "=", "doc", ".", "add_element", "self", ".", "class", "::", "RSRC_OBJECT_KEY", ".", "to_s", "acs", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "@name", "acs", ".", "add_element", "(", "'sort_1'", ")", ".", "text", "=", "@sort_1", "if", "@sort_1", "acs", ".", "add_element", "(", "'sort_2'", ")", ".", "text", "=", "@sort_2", "if", "@sort_2", "acs", ".", "add_element", "(", "'sort_3'", ")", ".", "text", "=", "@sort_3", "if", "@sort_3", "acs", "<<", "@criteria", ".", "rest_xml", "df", "=", "acs", ".", "add_element", "(", "'display_fields'", ")", "@display_fields", ".", "each", "{", "|", "f", "|", "df", ".", "add_element", "(", "'display_field'", ")", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "f", "}", "add_site_to_xml", "(", "doc", ")", "doc", ".", "to_s", "end" ]
Clean up the inconsistent "Display Field" keys in the search results. Sometimes spaces have been converted to underscores, sometimes not, sometimes both. Same for dashes. E.g :"Last Check-in"/:Last_Check_in/:"Last_Check-in", :Computer_Name, and :"Display Name"/:Display_Name This ensures there's always the fully underscored version. Update an internally used array of the display field names, symbolized, with spaces and dashes converted to underscores. We use these to overcome inconsistencies in how the names come from the API @return [void] def standardize_display_field_keys spdash = us = @display_field_std_keys = @display_fields.map { |f| f.gsub(/ |-/, '_').to_sym } end
[ "Clean", "up", "the", "inconsistent", "Display", "Field", "keys", "in", "the", "search", "results", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/advanced_search.rb#L337-L351
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.deploy_as_managed_app=
def deploy_as_managed_app=(new_val) return nil if new_val == @deploy_as_managed_app raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @deploy_as_managed_app = new_val @need_to_update = true end
ruby
def deploy_as_managed_app=(new_val) return nil if new_val == @deploy_as_managed_app raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @deploy_as_managed_app = new_val @need_to_update = true end
[ "def", "deploy_as_managed_app", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@deploy_as_managed_app", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@deploy_as_managed_app", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not this app should be deployed as managed @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "this", "app", "should", "be", "deployed", "as", "managed" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L284-L289
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.remove_app_when_mdm_profile_is_removed=
def remove_app_when_mdm_profile_is_removed=(new_val) return nil if new_val == @remove_app_when_mdm_profile_is_removed raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @remove_app_when_mdm_profile_is_removed = new_val @need_to_update = true end
ruby
def remove_app_when_mdm_profile_is_removed=(new_val) return nil if new_val == @remove_app_when_mdm_profile_is_removed raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @remove_app_when_mdm_profile_is_removed = new_val @need_to_update = true end
[ "def", "remove_app_when_mdm_profile_is_removed", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@remove_app_when_mdm_profile_is_removed", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@remove_app_when_mdm_profile_is_removed", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not this app should be removed when the device is unmanaged @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "this", "app", "should", "be", "removed", "when", "the", "device", "is", "unmanaged" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L299-L304
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.prevent_backup_of_app_data=
def prevent_backup_of_app_data=(new_val) return nil if new_val == @prevent_backup_of_app_data raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @prevent_backup_of_app_data = new_val @need_to_update = true end
ruby
def prevent_backup_of_app_data=(new_val) return nil if new_val == @prevent_backup_of_app_data raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @prevent_backup_of_app_data = new_val @need_to_update = true end
[ "def", "prevent_backup_of_app_data", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@prevent_backup_of_app_data", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@prevent_backup_of_app_data", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not the device should back up this app's data @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "the", "device", "should", "back", "up", "this", "app", "s", "data" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L312-L317
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.keep_description_and_icon_up_to_date=
def keep_description_and_icon_up_to_date=(new_val) return nil if new_val == @keep_description_and_icon_up_to_date raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @keep_description_and_icon_up_to_date = new_val @need_to_update = true end
ruby
def keep_description_and_icon_up_to_date=(new_val) return nil if new_val == @keep_description_and_icon_up_to_date raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @keep_description_and_icon_up_to_date = new_val @need_to_update = true end
[ "def", "keep_description_and_icon_up_to_date", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@keep_description_and_icon_up_to_date", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@keep_description_and_icon_up_to_date", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not the jss should update info about this app from the app store @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "the", "jss", "should", "update", "info", "about", "this", "app", "from", "the", "app", "store" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L326-L331
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.free=
def free=(new_val) return nil if new_val == @free raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @free = new_val @need_to_update = true end
ruby
def free=(new_val) return nil if new_val == @free raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @free = new_val @need_to_update = true end
[ "def", "free", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@free", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@free", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not this is a free app @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "this", "is", "a", "free", "app" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L339-L344
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.take_over_management=
def take_over_management=(new_val) return nil if new_val == @take_over_management raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @take_over_management = new_val @need_to_update = true end
ruby
def take_over_management=(new_val) return nil if new_val == @take_over_management raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @take_over_management = new_val @need_to_update = true end
[ "def", "take_over_management", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@take_over_management", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@take_over_management", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not Jamf should manage this app even if the user installed it on their own. @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "Jamf", "should", "manage", "this", "app", "even", "if", "the", "user", "installed", "it", "on", "their", "own", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L353-L358
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.host_externally=
def host_externally=(new_val) return nil if new_val == @host_externally raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @host_externally = new_val @need_to_update = true end
ruby
def host_externally=(new_val) return nil if new_val == @host_externally raise JSS::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean? @host_externally = new_val @need_to_update = true end
[ "def", "host_externally", "=", "(", "new_val", ")", "return", "nil", "if", "new_val", "==", "@host_externally", "raise", "JSS", "::", "InvalidDataError", ",", "'New value must be true or false'", "unless", "new_val", ".", "jss_boolean?", "@host_externally", "=", "new_val", "@need_to_update", "=", "true", "end" ]
Set whether or not this app's .ipa is hosted outside the Jamf server @param new_val[Boolean] The new value @return [void]
[ "Set", "whether", "or", "not", "this", "app", "s", ".", "ipa", "is", "hosted", "outside", "the", "Jamf", "server" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L390-L395
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/mobile_device_application.rb
JSS.MobileDeviceApplication.save_ipa
def save_ipa(path, overwrite = false) return nil unless @ipa[:data] path = Pathname.new path path = path + @ipa[:name] if path.directory? && @ipa[:name] raise JSS::AlreadyExistsError, "The file #{path} already exists" if path.exist? && !overwrite path.delete if path.exist? path.jss_save Base64.decode64(@ipa[:data]) end
ruby
def save_ipa(path, overwrite = false) return nil unless @ipa[:data] path = Pathname.new path path = path + @ipa[:name] if path.directory? && @ipa[:name] raise JSS::AlreadyExistsError, "The file #{path} already exists" if path.exist? && !overwrite path.delete if path.exist? path.jss_save Base64.decode64(@ipa[:data]) end
[ "def", "save_ipa", "(", "path", ",", "overwrite", "=", "false", ")", "return", "nil", "unless", "@ipa", "[", ":data", "]", "path", "=", "Pathname", ".", "new", "path", "path", "=", "path", "+", "@ipa", "[", ":name", "]", "if", "path", ".", "directory?", "&&", "@ipa", "[", ":name", "]", "raise", "JSS", "::", "AlreadyExistsError", ",", "\"The file #{path} already exists\"", "if", "path", ".", "exist?", "&&", "!", "overwrite", "path", ".", "delete", "if", "path", ".", "exist?", "path", ".", "jss_save", "Base64", ".", "decode64", "(", "@ipa", "[", ":data", "]", ")", "end" ]
Save the application to a file. @param path[Pathname, String] The path to which the file should be saved. If the path given is an existing directory, the ipa's current filename will be used, if known. @param overwrite[Boolean] Overwrite the file if it exists? Defaults to false @return [void]
[ "Save", "the", "application", "to", "a", "file", "." ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/mobile_device_application.rb#L433-L441
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/computer.rb
JSS.Computer.management_data
def management_data(subset: nil, only: nil) raise JSS::NoSuchItemError, 'Computer not yet saved in the JSS' unless @in_jss JSS::Computer.management_data @id, subset: subset, only: only, api: @api end
ruby
def management_data(subset: nil, only: nil) raise JSS::NoSuchItemError, 'Computer not yet saved in the JSS' unless @in_jss JSS::Computer.management_data @id, subset: subset, only: only, api: @api end
[ "def", "management_data", "(", "subset", ":", "nil", ",", "only", ":", "nil", ")", "raise", "JSS", "::", "NoSuchItemError", ",", "'Computer not yet saved in the JSS'", "unless", "@in_jss", "JSS", "::", "Computer", ".", "management_data", "@id", ",", "subset", ":", "subset", ",", "only", ":", "only", ",", "api", ":", "@api", "end" ]
app usage The 'computer management' data for this computer NOTE: the data isn't cached locally, and the API is queried every time @see {JSS::Computer.management_data} for details
[ "app", "usage", "The", "computer", "management", "data", "for", "this", "computer" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/computer.rb#L886-L889
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/computer.rb
JSS.Computer.set_management_to
def set_management_to(name, password) password = nil unless name @management_username = name @management_password = password @managed = name ? true : false @need_to_update = true end
ruby
def set_management_to(name, password) password = nil unless name @management_username = name @management_password = password @managed = name ? true : false @need_to_update = true end
[ "def", "set_management_to", "(", "name", ",", "password", ")", "password", "=", "nil", "unless", "name", "@management_username", "=", "name", "@management_password", "=", "password", "@managed", "=", "name", "?", "true", ":", "false", "@need_to_update", "=", "true", "end" ]
Set or unset management acct and password for this computer @param name[String] the name of the management acct. @param password[String] the password of the management acct @return [void] The changes will need to be pushed to the server with {#update} before they take effect. CAUTION: this does nothing to confirm the name and password will work on the machine!
[ "Set", "or", "unset", "management", "acct", "and", "password", "for", "this", "computer" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/computer.rb#L953-L959
train
PixarAnimationStudios/ruby-jss
lib/jss/api_object/computer.rb
JSS.Computer.rest_xml
def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER computer = doc.add_element self.class::RSRC_OBJECT_KEY.to_s general = computer.add_element('general') general.add_element('name').text = @name general.add_element('alt_mac_address').text = @alt_mac_address general.add_element('asset_tag').text = @asset_tag general.add_element('barcode_1').text = @barcode1 general.add_element('barcode_2').text = @barcode2 general.add_element('ip_address').text = @ip_address general.add_element('mac_address').text = @mac_address general.add_element('udid').text = @udid general.add_element('serial_number').text = @serial_number rmgmt = general.add_element('remote_management') rmgmt.add_element('managed').text = @managed rmgmt.add_element('management_username').text = @management_username rmgmt.add_element('management_password').text = @management_password if @management_password computer << ext_attr_xml if unsaved_eas? computer << location_xml if has_location? computer << purchasing_xml if has_purchasing? add_site_to_xml(doc) doc.to_s end
ruby
def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER computer = doc.add_element self.class::RSRC_OBJECT_KEY.to_s general = computer.add_element('general') general.add_element('name').text = @name general.add_element('alt_mac_address').text = @alt_mac_address general.add_element('asset_tag').text = @asset_tag general.add_element('barcode_1').text = @barcode1 general.add_element('barcode_2').text = @barcode2 general.add_element('ip_address').text = @ip_address general.add_element('mac_address').text = @mac_address general.add_element('udid').text = @udid general.add_element('serial_number').text = @serial_number rmgmt = general.add_element('remote_management') rmgmt.add_element('managed').text = @managed rmgmt.add_element('management_username').text = @management_username rmgmt.add_element('management_password').text = @management_password if @management_password computer << ext_attr_xml if unsaved_eas? computer << location_xml if has_location? computer << purchasing_xml if has_purchasing? add_site_to_xml(doc) doc.to_s end
[ "def", "rest_xml", "doc", "=", "REXML", "::", "Document", ".", "new", "APIConnection", "::", "XML_HEADER", "computer", "=", "doc", ".", "add_element", "self", ".", "class", "::", "RSRC_OBJECT_KEY", ".", "to_s", "general", "=", "computer", ".", "add_element", "(", "'general'", ")", "general", ".", "add_element", "(", "'name'", ")", ".", "text", "=", "@name", "general", ".", "add_element", "(", "'alt_mac_address'", ")", ".", "text", "=", "@alt_mac_address", "general", ".", "add_element", "(", "'asset_tag'", ")", ".", "text", "=", "@asset_tag", "general", ".", "add_element", "(", "'barcode_1'", ")", ".", "text", "=", "@barcode1", "general", ".", "add_element", "(", "'barcode_2'", ")", ".", "text", "=", "@barcode2", "general", ".", "add_element", "(", "'ip_address'", ")", ".", "text", "=", "@ip_address", "general", ".", "add_element", "(", "'mac_address'", ")", ".", "text", "=", "@mac_address", "general", ".", "add_element", "(", "'udid'", ")", ".", "text", "=", "@udid", "general", ".", "add_element", "(", "'serial_number'", ")", ".", "text", "=", "@serial_number", "rmgmt", "=", "general", ".", "add_element", "(", "'remote_management'", ")", "rmgmt", ".", "add_element", "(", "'managed'", ")", ".", "text", "=", "@managed", "rmgmt", ".", "add_element", "(", "'management_username'", ")", ".", "text", "=", "@management_username", "rmgmt", ".", "add_element", "(", "'management_password'", ")", ".", "text", "=", "@management_password", "if", "@management_password", "computer", "<<", "ext_attr_xml", "if", "unsaved_eas?", "computer", "<<", "location_xml", "if", "has_location?", "computer", "<<", "purchasing_xml", "if", "has_purchasing?", "add_site_to_xml", "(", "doc", ")", "doc", ".", "to_s", "end" ]
Return a String with the XML Resource for submitting changes to the JSS via the API For Computers, only some items can be changed via the API In particular, any data gatherd by a Recon cannot be changed
[ "Return", "a", "String", "with", "the", "XML", "Resource", "for", "submitting", "changes", "to", "the", "JSS", "via", "the", "API" ]
4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9
https://github.com/PixarAnimationStudios/ruby-jss/blob/4ab645bfaec8b2edb1ea146bfc2b10f0d62edee9/lib/jss/api_object/computer.rb#L1113-L1142
train