Commit 4b44fcc8 authored by Heiko Reese's avatar Heiko Reese
Browse files

parents
// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// requestCmd represents the request command
var requestCmd = &cobra.Command{
Use: "request",
Short: "Request a new certificate and retrieve the pdf application form",
// Long: ``,
TraverseChildren: true,
Run: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
fmt.Println("request called")
fmt.Println(viper.AllSettings())
},
}
func init() {
rootCmd.AddCommand(requestCmd)
// Here you will define your flags and configuration settings.
requestCmd.Flags().SortFlags = false
requestCmd.Flags().StringVarP(&globalArgs.Keyfile, "cn", "c", "", "Set common name »CN«")
requestCmd.MarkFlagRequired("cn")
requestCmd.Flags().StringArrayVar(&globalArgs.DNS, "dns", nil, "Add »DNS« (hostname or domain name) Subject Alternative Name")
requestCmd.Flags().StringArrayVar(&globalArgs.IPs, "ip", nil, "Add »IP« (ip address) Subject Alternative Name")
requestCmd.Flags().StringArrayVar(&globalArgs.URIs, "uri", nil, "Add »URI« Subject Alternative Name")
requestCmd.Flags().StringArrayVar(&globalArgs.OUs, "ou", nil, "Add »OU« (organizational unit) Subject Alternative Name")
requestCmd.Flags().StringArrayVar(&globalArgs.Os, "o", nil, "Add »O« (organization) Subject Alternative Name")
requestCmd.Flags().StringArrayVar(&globalArgs.Localitys, "locality", nil, "Add »L« (locality) Subject Alternative Name")
requestCmd.Flags().StringArrayVar(&globalArgs.Countrys, "country", nil, "Add »C« (country) Subject Alternative Name")
requestCmd.Flags().StringVarP(&globalArgs.Keyfile, "keyfile", "k", "", "Filename of secret key (autogenerated if not set)")
requestCmd.MarkFlagFilename("keyfile", "")
requestCmd.Flags().StringVarP(&globalArgs.Keypass, "keypass", "p", "", "Password if secret key is encrypted")
requestCmd.Flags().StringVarP(&globalArgs.Outdir)
requestCmd.Flags().BoolVarP(&globalArgs.DryRun, "dry-run", "n", false, "Only show request data, don't execute anything")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// requestCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
// Copyright © 2018 Heiko Reese
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
package cmd
import (
"fmt"
"os"
"path/filepath"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const configsubdir = ".config"
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var (
rootCmd = &cobra.Command{
Use: "dfnpkitool",
Short: "cli interface to the dfn-pki soap api.",
// Long: ``,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
fmt.Println()
},
}
globalArgs struct {
DryRun bool
CAName string
RAId int
CN string
DNS []string
IPs []string
URIs []string
Os []string
OUs []string
Localitys []string
Countrys []string
Keyfile string
Keypass string
PIN string // TODO
Outdir string
}
)
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
requestCmd.Flags().SortFlags = false
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/.dfnpkitool.toml)")
rootCmd.PersistentFlags().StringVar(&globalArgs.CAName, "ca", "kit-ca-g2", "Certification Authority identifier")
rootCmd.PersistentFlags().IntVar(&globalArgs.RAId, "raid", 0, "Sub-RA identifier (usually 0 for main RA)")
viper.BindPFlag("ca", rootCmd.PersistentFlags().Lookup("ca"))
viper.BindPFlag("raid", rootCmd.PersistentFlags().Lookup("raid"))
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Search config in home directory with name "dfnpkitool" (without extension).
viper.SetConfigName("dfnpkitool")
viper.AddConfigPath(filepath.Join(home, configsubdir))
viper.AddConfigPath(".")
}
// If a config file is found, read it in.
err := viper.ReadInConfig()
if err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
} else {
fmt.Println("No config file read: ", err)
}
}
// Copyright © 2018 Heiko Reese
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
package main
import "git.scc.kit.edu/KIT-CA/dfnpkitool/cmd"
func main() {
cmd.Execute()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment