Giter Club home page Giter Club logo

conoha-slack-sg-register-for-gas's Introduction

conoHa SG IP Register for GAS & Slack

logo

Node CI Coverage Status clasp license standard-readme compliant PRs Welcome

This is GoogleAppsScript to register home IP address with conoHa VPS SecurityGroup using Slack command.

Table of Contents

Background

I use conoHa VPS to create my own OpenVPN service and mail service.

For management purposes, there are times when you want to access the server with SSH, but opening the server SSH with any at any time poses a large security risk, so use the ConoHa API when you access SSH. Opening the global IP address, and when the use was over, the access was closed again by API.

Because registering and deleting an IP address every time it is accessed from the API is costly, Slack's Slash command has been used to make it easier to manage OPEN and CLOSE IP addresses in the form of ChatOps.

In addition, the features of using GoogleAppsScript, which can be used for free, and the fact that scripts are described in TypeScript using clasp are also features.

Install

Precondition

Create conoHa target SecurityGroup and attach it on your VPS port

In order to use the conoHa API with this tool, you need to create a SecurityGroup for preparing and managing the API and attach it to your VPS network port in advance.

If you use Postman, use the postman collection and import it.

Create API user

First, create conoHa's API user and check the environments in the below.

  • TenantId
  • username(API)
  • password(API)
  • Identity Service Domain
  • Network Service Domain

1

Create Target SecurityGroup and attach your server's network port

Second, Create new SecurityGroup by Network API and attach your server's network port by Network API.

And check check SecurityGroup ID.

If you use Postman, run the request in the below by order.

  • Token発行
  • セキュリティグループ作成 - Network API v2.0
    • edit request body and change name and description.
    • check security_group.id, this is Security Group ID.
  • ポート一覧取得 - Network API v2.0
    • check your network port attached your target server.
    • check ports[].id, this is Network port ID.
    • also check another SecurityGroups because of add to existing config.
  • ポート更新 - Network API v2.0
    • edit url for your Network port ID like https://{{networkAPI}}/v2.0/ports/xx213e2dewq-1313-aaaaa
    • edit request body and add to SecurityGroup existing config.

Create Slack API

Visit https://api.slack.com/apps?new_app=1 and Create New app

Img

Next, you add SlackToken features because need to VerifyToken

Additionally, Check VerifyToken because of using script.

Img

Set slash command in your project.

Img

Request URL is GAS Endpoint

Img

And also, change Basic Information with API, install this app to your workspace.

Img

Check Slack ChannelID

because of preventing any channel to send command, set channelID.

Channel ID is last path resource in url opening Slack by web browser.

img

Create GAS Project

First you create a empty GAS project from Google Drive.

Img

When you create a GAS project, enter name and note script ID include the URL. (Red Underline)

Img

Next, enter your script ID to .clasp.json

{
  "scriptId": "FIXME: This value is your script ID",
  "rootDir": "dist"
}

Set environment variables with Script Properties

Set some variables with Script Properties

Img

Img

Set variables below.

VERIFY_TOKEN=slack verify token
CHANNEL_ID=slack channelID
CONOHA_NETWORK_ENDPOINT=Network Service Domain
CONOHA_USERNAME=conoHa username
CONOHA_PASSWORD=conoHa password
CONOHA_IDENTITY_ENDPOINT=Identity Service Domain
CONOHA_TENANTID=conoHa tenantID
CONOHA_TARGET_SG=Security Group ID

Install dependencies

Use npm, install dependencies.

npm install

Usage

Build App

Execute the command below, build script file using with webpack and create script files under dist directory.

npm run build

Push App

Before push app, you need to change GA user setting which enable API.

https://script.google.com/home/usersettings

Push App.

clasp login  # only first access
clasp push

Deploy as web app

And also, deploy as web app for the script.

Open your script deployed, click tool bar => publish => deploy as web app

And check Current web app URL, this is Slack outgoing request URL!

img

GitHub Actions also deploying as web apps!

Demos

Run main function , send Slack your web page screenshot.

Img

Test

If you modify this codes, run unit test with jest.

npm test

Also, this repo is integrated with GitHub Action.

So, Run CI test, if you write test.

GitHub Action

This repo use GitHub Action, Run tests, Build scripts and push scripts to GAS triggered by push to master branch.

If you want to upload script with GitHub Action, you will set your .clasprc.json on GitHub Action SECRET.

How to setup your clasprc.json

Before set your clasprc.json, run clasp login with your local PC.

clasp login

And you open ~/.clasprc.json with editor.

# If you use VSCode
code ~/.clasprc.json

Img

Copy it and paste another window, and replace " character to \" because of reading to one-line string on bash command.

Img

Copy it and paste your GitHub Action Secret (https://github.com/{your_name}/{your_repo}/settings/secrets)

Sectet name is CLASPRC_JSON and paste your clasprc.json.

Image

Congratulation! You can deploy to GitHub Action!

Contributing

See the contributing file!

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © tubone.

conoha-slack-sg-register-for-gas's People

Contributors

dependabot[bot] avatar tubone24 avatar

Watchers

 avatar  avatar  avatar

conoha-slack-sg-register-for-gas's Issues

https://networking.tyo1.conoha.io のリクエストに失敗しました(エラー: 409)。サーバー応答の一部: {"NeutronError": {"message": "Security group rule already exists. Rule id is d3ae887a-667b-4a74-8651-0a4345fc02ec.", "type": "SecurityGroupRuleExis...(応答の全文を見るには muteHttpExceptions オプションを使用してください) at [unknown function](bundle:241) at [unknown function](bundle:420) [unknown function] (bundle)

message: "https://networking.tyo1.conoha.io のリクエストに失敗しました(エラー: 409)。サーバー応答の一部: {"NeutronError": {"message": "Security group rule already exists. Rule id is d3ae887a-667b-4a74-8651-0a4345fc02ec.", "type": "SecurityGroupRuleExis...(応答の全文を見るには muteHttpExceptions オプションを使用してください)
    at [unknown function](bundle:241)
    at [unknown function](bundle:420)
    ```

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm cpx Available
npm tslint Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Replace dependency cpx with cpx2 2.0.0
  • Update dependency @types/node to v13.13.52
  • Update dependency tslint to v5.20.1
  • Update dependency tslint-plugin-prettier to v2.3.0
  • Update dependency typescript to v3.9.10
  • Update dependency webpack to v4.47.0
  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4
  • Update dependency @types/google-apps-script to v1
  • Update dependency @types/node to v20
  • Update dependency dotenv to v16
  • Update dependency gas-webpack-plugin to v2
  • Update dependency prettier to v3
  • Update dependency rimraf to v5
  • Update dependency ts-loader to v9
  • Update dependency tslint to v6
  • Update dependency typescript to v5
  • Update dependency webpack to v5
  • Update dependency webpack-cli to v5
  • Update jest monorepo to v29 (major) (@types/jest, jest, ts-jest)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/nodejs.yml
  • actions/checkout v1
  • actions/setup-node v1
npm
package.json
  • dotenv ^8.1.0
  • fs 0.0.1-security
  • gas-local ^1.3.1
  • @types/google-apps-script 0.0.59
  • @types/jest 24.0.18
  • @types/node ^13.9.0
  • braces 2.3.1
  • cpx 1.5.0
  • gas-webpack-plugin 1.0.2
  • jest 24.9.0
  • prettier 1.18.2
  • rimraf 3.0.0
  • ts-jest 24.0.2
  • ts-loader 6.0.4
  • tslint 5.19.0
  • tslint-config-prettier 1.18.0
  • tslint-plugin-prettier 2.0.1
  • typescript 3.5.3
  • webpack 4.39.3
  • webpack-cli 3.3.8

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.