Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
seipan committed Jun 16, 2024
1 parent 2928a17 commit 499ef20
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
strategy:
matrix:
go-version: ['1.22']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: go build -v ./...

- name: Test
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...

- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/yadon-infra/pem-generate-cron

go 1.22.3
48 changes: 48 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"flag"
"log"
"os"
"path/filepath"
)

func main() {
dir := flag.String("dir", ".", "path of directory")
flag.Parse()

privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
log.Fatalf("Failed to generating key: %v", err)
}

privateKeyPEM := pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
})

if _, err := os.Stat(*dir); os.IsNotExist(err) {
err = os.MkdirAll(*dir, 0755)
if err != nil {
log.Fatalf("Failed to create directory: %v", err)
}
}

privateKeyPath := filepath.Join(*dir, "private-key.pem")

err = os.Remove("private-key.pem")
if err != nil && !os.IsNotExist(err) {
log.Fatalf("Failed remove old pemfile: %v", err)
}

err = os.WriteFile(privateKeyPath, privateKeyPEM, 0600)
if err != nil {
log.Fatalf("Failed to save privateKey to pemfile: %v", err)
}

log.Printf("Private key saved to %s", privateKeyPath)
}

0 comments on commit 499ef20

Please sign in to comment.