Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ RUN apk -U add bind-tools bash

RUN mkdir /bundle
WORKDIR /bundle
COPY dig.sh /bundle/
COPY *.sh /bundle/
RUN chmod +x /bundle/*.sh
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# net - Simple network utilities (0.3.3)



## Installation

In chat:

```
@cog bundle install net
```

Via cogctl:

```
cogctl bundle install net
```

For more details about how to install and configure bundles see:

* [Installing Bundles](https://cog-book.operable.io/#_installing_bundles)
* [Dynamic Command Configuration](https://cog-book.operable.io/#_dynamic_command_configuration)

## Commands

The following commands are included with the bundle. For usage info
about each command see the `help` builtin command: `help net:<command_name>`.

* `dig`
> DNS lookup utility

* `whois`
> Whois query utility
72 changes: 72 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

require 'yaml'

# Make sure we're running from the directory the Rakefile lives in since
# many things (ie: docker build, config reading) use relative paths.
Dir.chdir(File.dirname(__FILE__))

BUNDLE_CONFIG = YAML.safe_load(File.read('config.yaml'))
BUNDLE_VERSION = BUNDLE_CONFIG['version']
BUNDLE_IMAGE = "#{BUNDLE_CONFIG['docker']['image']}:#{BUNDLE_CONFIG['docker']['tag']}"

task :image do |_t|
sh 'docker', 'build', '-t', BUNDLE_IMAGE, '.'
end

task push: [:image] do |_t|
sh 'docker', 'push', BUNDLE_IMAGE
end

task release: [:push] do |_t|
sh 'git', 'tag', BUNDLE_VERSION
sh 'git', 'push', 'origin', BUNDLE_VERSION
end

task install: [:push] do |_t|
sh 'cogctl', 'bundle', 'install', 'config.yaml', '--enable', '--relay-group',
'default', '--force'
end

task :readme do |_t|
name = BUNDLE_CONFIG['name']
description = BUNDLE_CONFIG['description']
version = BUNDLE_CONFIG['version']
long_description = BUNDLE_CONFIG['long_description']
env = BUNDLE_CONFIG.fetch('config', {}).fetch('env', []).map { |e| "* `#{e['var']}`\n > #{e['description']}" }.join("\n\n")
commands = BUNDLE_CONFIG['commands'].map { |n, c| "* `#{n}`\n > #{c['description']}" }.join("\n\n")

readme = <<~END
# #{name} - #{description} (#{version})

#{long_description}

## Installation

In chat:

```
@cog bundle install #{name}
```

Via cogctl:

```
cogctl bundle install #{name}
```

For more details about how to install and configure bundles see:

* [Installing Bundles](https://cog-book.operable.io/#_installing_bundles)
* [Dynamic Command Configuration](https://cog-book.operable.io/#_dynamic_command_configuration)

## Commands

The following commands are included with the bundle. For usage info
about each command see the `help` builtin command: `help #{name}:<command_name>`.

#{commands}
END

File.write('README.md', readme)
end
31 changes: 27 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ name: net
description: "Simple network utilities"
author: "Operable <[email protected]>"
homepage: "https://github.com/cogcmd/net"
version: "0.2"
version: "0.3.3"
docker:
image: "cogcmd/net"
tag: "0.2"
tag: "0.3.3"
commands:
dig:
executable: "/bundle/dig.sh"
Expand Down Expand Up @@ -36,11 +36,34 @@ commands:
description: "Enable the 'trace' query option. Disabled by default"
type: bool
required: false
whois:
executable: "/bundle/whois.sh"
description: "Whois query utility"
long_description: |
Simple wrapper for the `whois` command line utility.
arguments: "<domain>"
rules:
- "when command is net:whois allow"
options:
server:
description: "Whois server to query against."
type: string
required: false
port:
description: "Port on whois server"
type: string
required: false
short:
description: "Returns a terse answer only containing contact information"
type: bool
required: false
templates:
dig:
body: |
~each var=$results~
```~each var=$item.body as=l~
```
~each var=$item.body as=l~
~$l~
~end~```
~end~
```
~end~
30 changes: 30 additions & 0 deletions whois.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

declare -a arguments

if [ "$COG_ARGV_0" == "" ]; then
echo "Error: You must supply a domain to query"
fi

if [ "$COG_OPT_SERVER" != "" ]; then
arguments+=("-h")
arguments+=("${COG_OPT_SERVER}")
fi

if [ "$COG_OPT_PORT" != "" ]; then
arguments+=("-p")
arguments+=("${COG_OPT_PORT}")
fi

# Set template to use for rendering output
echo "COG_TEMPLATE: dig"

# Run the whois command.
result="$(whois "${arguments[@]}" "$COG_ARGV_0")"

echo $COG_OPT_SHORT
if [ "$COG_OPT_SHORT" != "" ]; then
echo -e "${result}" | grep -E "^(Registrant|Admin|Tech)"
else
echo -e "${result}"
fi