github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/meta/constants.go (about)

     1  /*
     2   * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved.
     3   * This software is released under GPL3.
     4   * The full license information can be found under:
     5   * https://www.gnu.org/licenses/gpl-3.0.en.html
     6   *
     7   */
     8  
     9  package meta
    10  
    11  import (
    12  	"fmt"
    13  	"log"
    14  	"runtime"
    15  
    16  	"github.com/fatih/color"
    17  )
    18  
    19  // Level is the type for all possible signature levels
    20  type Level int64
    21  
    22  // Status is the type for all possible asset statuses
    23  type Status int64
    24  
    25  // Visibility is the type for all visibility values
    26  type Visibility int64
    27  
    28  // Allowed Level values
    29  const (
    30  	LevelDisabled         Level = -1
    31  	LevelUnknown          Level = 0
    32  	LevelEmailVerified    Level = 1
    33  	LevelSocialVerified   Level = 2
    34  	LevelIDVerified       Level = 3
    35  	LevelLocationVerified Level = 4
    36  	LevelCNLC             Level = 98
    37  	LevelVchain           Level = 99
    38  )
    39  
    40  // Allowed Status values
    41  const (
    42  	StatusTrusted       Status = 0
    43  	StatusUntrusted     Status = 1
    44  	StatusUnknown       Status = 2
    45  	StatusUnsupported   Status = 3
    46  	StatusApikeyRevoked Status = 4
    47  )
    48  
    49  // Allowed Visibility values
    50  const (
    51  	VisibilityPublic  Visibility = 0
    52  	VisibilityPrivate Visibility = 1
    53  )
    54  
    55  // Event tracking related consts
    56  const (
    57  	VcnLoginEvent       string = "VCN_LOGIN"
    58  	VcnSignEvent        string = "VCN_SIGN"
    59  	VcnVerifyEvent      string = "VCN_VERIFY"
    60  	VcnAlertVerifyEvent string = "VCN_ALERT_VERIFY"
    61  )
    62  
    63  // vcn environment variable names
    64  const (
    65  	VcnUserEnv                   string = "VCN_USER"
    66  	VcnPasswordEnv               string = "VCN_PASSWORD"
    67  	VcnNotarizationPassword      string = "VCN_NOTARIZATION_PASSWORD"
    68  	VcnNotarizationPasswordEmpty string = "VCN_NOTARIZATION_PASSWORD_EMPTY"
    69  	VcnOtp                       string = "VCN_OTP"
    70  	VcnOtpEmpty                  string = "VCN_OTP_EMPTY"
    71  	VcnLcApiKey                  string = "VCN_LC_API_KEY"
    72  	VcnLcHost                    string = "VCN_LC_HOST"
    73  	VcnLcPort                    string = "VCN_LC_PORT"
    74  	VcnLcCert                    string = "VCN_LC_CERT"
    75  	VcnLcNoTls                   string = "VCN_LC_NO_TLS"
    76  	VcnLcSkipTlsVerify           string = "VCN_LC_SKIP_TLS_VERIFY"
    77  	VcnSigningPubKeyFile         string = "VCN_SIGNING_PUB_KEY_FILE"
    78  )
    79  
    80  const VcnExitCode string = "override default exit codes in case of success"
    81  
    82  const VcnPrefix string = "vcn"
    83  const VcnAttachmentLabelPrefix string = "_ITEM.ATTACH.LABEL"
    84  
    85  // Ledger compliance
    86  const VcnLCPluginTypeHeaderName string = "lc-plugin-type"
    87  const VcnLCLedgerHeaderName string = "lc-ledger"
    88  const VcnLCVersionHeaderName string = "version"
    89  const VcnLCPluginTypeHeaderValue string = "vcn"
    90  const VcnLCCmdHeaderName = "vcn-command"
    91  const VcnLCNotarizeCmdHeaderValue = "notarize"
    92  const VcnLCVerifyCmdHeaderValue = "verify"
    93  
    94  const VcnLcHostFlagDesc string = "if set with host, action will be route to a Codenotary Cloud server"
    95  const VcnLcPortFlagDesc string = "set port for set up a connection to a Codenotary Cloud server (default 443). If --lc-no-tls is provided default port will be 80"
    96  const VcnLcCertPathDesc string = "local or absolute path to a certificate file needed to set up tls connection to a Codenotary Cloud server"
    97  const VcnLcSkipTlsVerifyDesc string = "disables tls certificate verification when connecting to a Codenotary Cloud server"
    98  const VcnLcNoTlsDesc string = "allow insecure connections when connecting to a Codenotary Cloud server"
    99  const VcnLcApiKeyDesc string = "Codenotary Cloud server api key"
   100  const VcnLcLedgerDesc string = "Codenotary Cloud ledger. Required when a multi-ledger API key is used."
   101  const VcnLcAttachDesc string = "add user defined file attachments. Ex. vcn n myfile --attach mysecondfile. (repeat --attach for multiple entries). It's possible to specify a label for each entry, Ex: --attach=vscanner.result:jobid123. In this way it will be possible to retrieve the specific attachment with `vcn a binary1 --attach=vscanner.result:jobid123` or `vcn a binary1 --attach=jobid123` to get all attachments"
   102  const VcnLcCIAttribDesc string = "detect CI environment variables context if presents and inject "
   103  const VcnLcUidDesc string = "authenticate on a specific artifact uid"
   104  const VcnLcAttachmentAuthDesc string = `authenticate an artifact on a specific attachment label. With this it's be possible to retrieve the specific attachment with:
   105  vcn a binary1 --attach=vscanner.result:jobid123 --output=attachments
   106  or to get all attachments for a label:
   107  vcn a binary1 --attach=jobid123 --output=attachments`
   108  const VcnLcForceAttachmentDownloadDesc string = "if provided when downloading attachments files are silently overwritten"
   109  const VcnSigningPubKeyFileNameDesc string = "specify a public key file path to verify signature in messages when connected to a Codenotary Cloud server. If no public key file is specified but server is signig messages is possible an interactive confirmation of the fingerprint. When confirmed the public key is stored in ~/.vcn-trusted-signing-pub-key file."
   110  const VcnSigningPubKeyDesc string = "specify a public key to verify signature in messages when connected to a Codenotary Cloud server. It's required a valid ECDSA key content without header and footer. Ex: --signing-pub-key=\"MFkwE...y5i4w==\""
   111  const VcnEnforceSignatureVerifyDesc string = "if this flag is provided vcn will disable signature auto trusting when connecting to a new Codenotary Cloud server"
   112  
   113  const BomEntryKeyName string = "BOM"
   114  
   115  // UserAgent returns the vcn's User-Agent string
   116  func UserAgent() string {
   117  	// Syntax reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent#Syntax
   118  	return fmt.Sprintf("vcn/%s (%s; %s)", Version(), runtime.GOOS, runtime.GOARCH)
   119  }
   120  
   121  // String returns the name of the given level as string.
   122  func (l Level) String() string {
   123  	switch l {
   124  	case LevelDisabled:
   125  		return "DISABLED"
   126  	case LevelUnknown:
   127  		return "0 - UNKNOWN"
   128  	case LevelEmailVerified:
   129  		return "1 - EMAIL_VERIFIED"
   130  	case LevelSocialVerified:
   131  		return "2 - SOCIAL_VERIFIED"
   132  	case LevelIDVerified:
   133  		return "3 - ID_VERIFIED"
   134  	case LevelLocationVerified:
   135  		return "4 - LOCATION_VERIFIED"
   136  	case LevelVchain:
   137  		return "99 - VCHAIN"
   138  	default:
   139  		log.Fatal("unsupported level: ", int64(l))
   140  		return ""
   141  	}
   142  }
   143  
   144  // String returns the name of the given status as string
   145  func (s Status) String() string {
   146  	switch s {
   147  	case StatusTrusted:
   148  		return "TRUSTED"
   149  	case StatusUntrusted:
   150  		return "UNTRUSTED"
   151  	case StatusUnknown:
   152  		return "UNKNOWN"
   153  	case StatusUnsupported:
   154  		return "UNSUPPORTED"
   155  	case StatusApikeyRevoked:
   156  		return "REVOKED"
   157  	default:
   158  		log.Fatal("unsupported status: ", int64(s))
   159  		return ""
   160  	}
   161  }
   162  func (s Status) Int() int {
   163  	return int(s)
   164  }
   165  
   166  // StatusNameStyled returns the colorized name of the given status as string
   167  func StatusNameStyled(status Status) string {
   168  	c, s, b := StatusColor(status)
   169  	return color.New(c, s, b).Sprintf(status.String())
   170  }
   171  
   172  // String returns the name of the given visibility as string
   173  func (v Visibility) String() string {
   174  	switch v {
   175  	case VisibilityPublic:
   176  		return "PUBLIC"
   177  	case VisibilityPrivate:
   178  		return "PRIVATE"
   179  	default:
   180  		log.Fatal("unsupported visibility: ", int(64))
   181  		return ""
   182  	}
   183  }
   184  
   185  // VisibilityForFlag returns VisibilityPublic if public is true, otherwise VisibilityPrivate
   186  func VisibilityForFlag(public bool) Visibility {
   187  	if public {
   188  		return VisibilityPublic
   189  	}
   190  	return VisibilityPrivate
   191  }
   192  
   193  const DateShortForm = "2006/1/2-15:04:05"
   194  const IndexDateRangePrefix = "_INDEX.ITEM.INSERTION-DATE."
   195  
   196  const VcnDefaultExitCode = 0
   197  
   198  const AttachmentSeparator = ".attach."
   199  const VcnSigningPubKeyFileName = ".vcn-trusted-signing-pub-key"