Skip to content
Closed
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
15 changes: 15 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG RUBY_VERSION=3.2
FROM ruby:${RUBY_VERSION}

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common

# Install the Dependencies
# we don't install git here as it's installed in the devcontainer.json
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y --no-install-recommends \
# build-essential is required for native extensions
build-essential \
ruby-dev \
&& rm -rf /var/lib/apt/lists/*
2 changes: 2 additions & 0 deletions .devcontainer/devcontainer.dist.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# If you'd like to pass environment variables to the devcontainer,
# Copy this file to ./devcontainer.env, then add them below.
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "Netbox Client Ruby",
"build": {
"dockerfile": "./Dockerfile",
"context": "..",
"args": {
"RUBY_VERSION": "${localEnv:RUBY_VERSION:3.2.5}"
}
},
"runArgs": [
"--env-file", "${localWorkspaceFolder}/.devcontainer/devcontainer.env"
],
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"username": "vscode",
"userUid": "1000",
"userGid": "1000",
"upgradePackages": "true"
},
"ghcr.io/devcontainers/features/ruby:1": "none",
"ghcr.io/devcontainers/features/node:1": "none",
"ghcr.io/devcontainers/features/git:1": {
"version": "latest",
"ppa": "false"
}
},
"customizations": {
"vscode": {
"extensions": [
"github.vscode-github-actions",
"github.vscode-pull-request-github",
// a language server
"shopify.ruby-lsp"
]
}
},
"remoteUser": "vscode",
// we need to sudo bundle install otherwise the prism gem won't compile and install.
"postCreateCommand": "sudo bin/setup",
// make sure we're updated each time we start.
"postStartCommand": "bin/setup"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Gemfile.lock

# Ignore MacOS files
.DS_Store
.devcontainer/devcontainer.env
15 changes: 15 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"shopify.ruby-lsp",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/ninech/netbox-client-ruby.svg?branch=master)](https://travis-ci.org/ninech/netbox-client-ruby)
[![Gem Version](https://badge.fury.io/rb/netbox-client-ruby.svg)](https://badge.fury.io/rb/netbox-client-ruby)
[![Code Climate](https://codeclimate.com/github/ninech/netbox-client-ruby/badges/gpa.svg)](https://codeclimate.com/github/ninech/netbox-client-ruby)
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/ninech/netbox-client-ruby)

This is a gem to pragmatically access your [Netbox instance](https://github.com/digitalocean/netbox)
via it's API from Ruby. This gem is currently only compatible with Netbox v2.4 or newer.
Expand Down Expand Up @@ -236,6 +237,24 @@ docker-compose exec postgres pg_dump -U netbox --exclude-table-data=extras_objec

(Remove `--exclude-table-data=extras_objectchange` from the command if you want to retain the history!)

### Dev Containers

If you'd like to use a [Dev Container](https://code.visualstudio.com/docs/devcontainers/create-dev-container)
development environment in VS Code, the configuration files for the development environment has been provided
in the `./.devcontainer` folder.

By default, the Dockerfile/devcontainer uses the `ruby:3.2` image. If you want to use a different version:

- Update the value for `build.args.RUBY_VERSION` from `${localEnv:RUBY_VERSION:3.2.5}` to the actual version number
(which is just an image tag)
- Or set the local/host environment variable `RUBY_VERSION` before starting/restarting VS Code.
See: [Variables in devcontainer.json](https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson) for more details.

If you would like to pass environment variables into the Dev Container,
copy the `.devcontainer/devcontainer.dist.env` to `.devcontainer/devcontainer.env` and put them in there.

For more details and prerequisite, see: <https://code.visualstudio.com/docs/devcontainers/create-dev-container>

## Contributing

Bug reports and pull requests are very welcome [on GitHub](https://github.com/ninech/netbox-client-ruby).
Expand Down
4 changes: 4 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail

bundle exec rake spec
2 changes: 2 additions & 0 deletions gemfiles/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_RETRY: "1"
4 changes: 2 additions & 2 deletions lib/netbox_client_ruby/api/tenancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module NetboxClientRuby
module Tenancy
{
tenants: Tenants,
tenant_groups: TenantGroups,
tenant_groups: TenantGroups
contacts: Contacts,
contact_groups: ContactGroups
}.each_pair do |method_name, class_name|
Expand All @@ -14,7 +14,7 @@ module Tenancy

{
tenant: Tenant,
tenant_group: TenantGroup,
tenant_group: TenantGroup
contact: Contact,
contact_group: ContactGroup
}.each_pair do |method_name, class_name|
Expand Down
Binary file added netbox-client-ruby-0.10.3.gem
Binary file not shown.
18 changes: 9 additions & 9 deletions spec/fixtures/tenancy/contact-groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"results": [
{
"id": 1,
"display": "Parent Customers",
"name": "Parent Customers",
"slug": "parent-customers",
"display": "Customers",
"name": "Customers",
"slug": "customers",
"description": "Parent Contact contact group",
"parent": null
},
{
"id": 2,
"display": "Child Customers",
"name": "Child Customers",
"slug": "child-customers",
"display": "East Coast Customers",
"name": "East Coast Customers",
"slug": "east-coast-customers",
"description": "Child contact group",
"parent": {
"id": 1,
"url": "http://localhost/api/tenancy/contact_groups/1/",
"display": "Parent Customers",
"name": "Parent Customers",
"slug": "parent-customers",
"display": "Customers",
"name": "Customers",
"slug": "customers",
"description": "Parent Contact contact group"
}
}
Expand Down
10 changes: 4 additions & 6 deletions spec/fixtures/tenancy/contact_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"name": "tenant3",
"email": "contact3@customer.test",
"group": {
"id": 2,
"url": "http://localhost/api/tenancy/contact_groups/2/",
"display": "Child Customers",
"name": "Child Customers",
"slug": "child-customers",
"description": "Child contact group"
"id": 1,
"url": "http://localhost/api/tenancy/contact-groups/1/",
"name": "Customer",
"slug": "customer"
},
"description": "",
"comments": "",
Expand Down
10 changes: 4 additions & 6 deletions spec/fixtures/tenancy/contacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
"name": "contact3",
"email": "contact3@customer.test",
"group": {
"id": 2,
"url": "http://localhost/api/tenancy/contact_groups/2/",
"display": "Child Customers",
"name": "Child Customers",
"slug": "child-customers",
"description": "Child contact group"
"id": 1,
"url": "http://localhost/api/tenancy/contact-groups/1/",
"name": "Customer",
"slug": "customer"
},
"description": "",
"comments": "",
Expand Down
25 changes: 22 additions & 3 deletions spec/netbox_client_ruby/api/dcim/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
require 'spec_helper'

RSpec.describe NetboxClientRuby::DCIM::Site, faraday_stub: true do
let(:class_under_test) { NetboxClientRuby::DCIM::Site }
let(:entity_id) { 1 }
let(:response) { File.read("spec/fixtures/dcim/site_#{entity_id}.json") }
let(:request_url) { "/api/dcim/sites/#{entity_id}/" }

subject { described_class.new entity_id }
subject { class_under_test.new entity_id }

describe '#id' do
it 'shall be the expected id' do
Expand Down Expand Up @@ -55,6 +56,24 @@
end
end

{
region: NetboxClientRuby::DCIM::Region,
tenant: NetboxClientRuby::Tenancy::Tenant,
status: Symbol
}.each_pair do |method_name, expected_type|
describe ".#{method_name}" do
it 'should fetch the data' do
expect(faraday).to receive(:get).and_call_original

expect(subject.public_send(method_name)).to_not be_nil
end

it 'shall return the expected type' do
expect(subject.public_send(method_name)).to be_a(expected_type)
end
end
end

describe '.delete' do
let(:request_method) { :delete }
let(:response_status) { 204 }
Expand Down Expand Up @@ -94,7 +113,7 @@
let(:request_method) { :patch }

subject do
entity = described_class.new entity_id
entity = class_under_test.new entity_id
entity.name = name
entity.slug = slug
entity
Expand Down Expand Up @@ -128,7 +147,7 @@
let(:request_url) { '/api/dcim/sites/' }

subject do
entity = described_class.new
entity = class_under_test.new
entity.name = name
entity.slug = slug
entity
Expand Down
2 changes: 1 addition & 1 deletion spec/netbox_client_ruby/api/tenancy/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
it 'should be a ContactGroup object' do
contact_group = subject.group
expect(contact_group).to be_a NetboxClientRuby::Tenancy::ContactGroup
expect(contact_group.id).to eq(2)
expect(contact_group.id).to eq(1)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/netbox_client_ruby/api/tenancy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
tenant_groups: NetboxClientRuby::Tenancy::TenantGroups,
tenants: NetboxClientRuby::Tenancy::Tenants,
contact_groups: NetboxClientRuby::Tenancy::ContactGroups,
contact_groups: NetboxClientRuby::Tenancy::ContacttGroups,
contacts: NetboxClientRuby::Tenancy::Contacts
}.each do |method, klass|
describe ".#{method}" do
Expand Down
Loading