diff --git a/Makefile b/Makefile index ff2245612..43f65be19 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ COVERAGE_DIR?=$(shell mktemp -d) GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) -# Uncomment to update test outputs +# Uncomment to update system test gold files # CAPTURE := "--capture" help: ## Print this help diff --git a/cmd/config_show.go b/cmd/config_show.go index 56ab33e8a..6568604f3 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -9,11 +9,11 @@ import ( ) func aptlyConfigShow(_ *commander.Command, _ []string) error { - show_yaml := context.Flags().Lookup("yaml").Value.Get().(bool) + showYaml := context.Flags().Lookup("yaml").Value.Get().(bool) config := context.Config() - if show_yaml { + if showYaml { yamlData, err := yaml.Marshal(&config) if err != nil { return fmt.Errorf("error marshaling to YAML: %s", err) diff --git a/context/context_test.go b/context/context_test.go index f83d42f20..b2e42fe8b 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -84,6 +84,6 @@ func (s *AptlyContextSuite) TestGetPublishedStorageBadFS(c *C) { // storage never exists. c.Assert(func() { s.context.GetPublishedStorage("filesystem:fuji") }, FatalErrorPanicMatches, - &FatalError{ReturnCode: 1, Message: fmt.Sprintf("error loading config file %s/.aptly.conf: EOF", + &FatalError{ReturnCode: 1, Message: fmt.Sprintf("error loading config file %s/.aptly.conf: not valid yaml or json", os.Getenv("HOME"))}) } diff --git a/system/t02_config/BadConfigTest_gold b/system/t02_config/BadConfigTest_gold index 10f5b8ce8..0b0ca4470 100644 --- a/system/t02_config/BadConfigTest_gold +++ b/system/t02_config/BadConfigTest_gold @@ -1 +1 @@ -ERROR: error loading config file ${HOME}/.aptly.conf: invalid character 's' looking for beginning of object key string +ERROR: error loading config file ${HOME}/.aptly.conf: not valid yaml or json diff --git a/system/t02_config/ConfigShowTest_gold b/system/t02_config/ConfigShowTest_gold index 0529de71a..5a4a2273a 100644 --- a/system/t02_config/ConfigShowTest_gold +++ b/system/t02_config/ConfigShowTest_gold @@ -1,39 +1,39 @@ { "rootDir": "${HOME}/.aptly", - "downloadConcurrency": 4, - "downloadSpeedLimit": 0, - "downloadRetries": 5, - "downloader": "default", + "logLevel": "debug", + "logFormat": "default", "databaseOpenAttempts": 10, "architectures": [], + "skipLegacyPool": false, "dependencyFollowSuggests": false, "dependencyFollowRecommends": false, "dependencyFollowAllVariants": false, "dependencyFollowSource": false, "dependencyVerboseResolve": false, - "gpgDisableSign": false, - "gpgDisableVerify": false, - "gpgProvider": "gpg", - "downloadSourcePackages": false, - "packagePoolStorage": {}, - "skipLegacyPool": false, "ppaDistributorID": "ubuntu", "ppaCodename": "", + "serveInAPIMode": true, + "enableMetricsEndpoint": true, + "enableSwaggerEndpoint": false, + "AsyncAPI": false, + "databaseBackend": { + "type": "", + "dbPath": "", + "url": "" + }, + "downloader": "default", + "downloadConcurrency": 4, + "downloadSpeedLimit": 0, + "downloadRetries": 5, + "downloadSourcePackages": false, + "gpgProvider": "gpg", + "gpgDisableSign": false, + "gpgDisableVerify": false, "skipContentsPublishing": false, "skipBz2Publishing": false, "FileSystemPublishEndpoints": {}, "S3PublishEndpoints": {}, "SwiftPublishEndpoints": {}, "AzurePublishEndpoints": {}, - "AsyncAPI": false, - "enableMetricsEndpoint": true, - "logLevel": "debug", - "logFormat": "default", - "serveInAPIMode": true, - "databaseBackend": { - "type": "", - "url": "", - "dbPath": "" - }, - "enableSwaggerEndpoint": false + "packagePoolStorage": {} } diff --git a/system/t02_config/CreateConfigTest_gold b/system/t02_config/CreateConfigTest_gold index 6eeed77ec..24bbbecfb 100644 --- a/system/t02_config/CreateConfigTest_gold +++ b/system/t02_config/CreateConfigTest_gold @@ -1,370 +1,339 @@ -// vim: : filetype=json -// json configuration file with comments -// validate with: sed '/\/\//d' aptly.conf | json_pp -{ +# Aptly Configuration File +########################### -// Aptly Configuration File -//////////////////////////// +# Aptly storage directory for: +# - downloaded packages (`rootDir`/pool) +# - database (`rootDir`/db) +# - published repositories (`rootDir`/public) +root_dir: ~/.aptly - // Aptly storage directory for: - // - downloaded packages (`rootDir`/pool) - // - database (`rootDir`/db) - // - published repositories (`rootDir`/public) - "rootDir": "~/.aptly", +# Log Level +# * debug +# * info +# * warning +# * error +log_level: info - // Number of attempts to open database if it's locked by other instance - // * -1 (no retry) - "databaseOpenAttempts": -1, +# Log Format +# * default (text) +# * json +log_format: default - // Log Level - // * debug - // * info - // * warning - // * error - "logLevel": "info", +# Number of attempts to open database if it's locked by other instance +# * -1 (no retry) +database_open_attempts: -1 - // Log Format - // * default (text) - // * json - "logFormat": "default", +# Default Architectures +# empty list defaults to all available architectures +architectures: +# - amd64 - // Default Architectures - // empty array defaults to all available architectures - "architectures": [], +# OBSOLETE +# in aptly up to version 1.0.0, package files were stored in internal package pool +# with MD5-dervied path, since 1.1.0 package pool layout was changed; +# if option is enabled, aptly stops checking for legacy paths; +# by default option is enabled for new aptly installations and disabled when +# upgrading from older versions +skip_legacy_pool: true - // Follow contents of `Suggests:` field when processing dependencies for the package - "dependencyFollowSuggests": false, - // Follow contents of `Recommends:` field when processing dependencies for the package - "dependencyFollowRecommends": false, +# Dependency following +####################### - // When dependency looks like `package-a | package-b`, follow both variants always - "dependencyFollowAllVariants": false, +# Follow contents of `Suggests:` field when processing dependencies for the package +dep_follow_suggests: false - // Follow dependency from binary package to source package - "dependencyFollowSource": false, +# Follow contents of `Recommends:` field when processing dependencies for the package +dep_follow_recommends: false - // Log additional details while resolving dependencies (useful for debugging) - "dependencyVerboseResolve": false, +# When dependency looks like `package-a | package-b`, follow both variants always +dep_follow_allvariants: false - // Specifies paramaters for short PPA url expansion - // empty defaults to output of `lsb_release` command - "ppaDistributorID": "ubuntu", +# Follow dependency from binary package to source package +dep_follow_source: false - // Codename for short PPA url expansion - "ppaCodename": "", +# Log additional details while resolving dependencies (useful for debugging) +dep_verbose_resolve: false - // OBSOLETE - // in aptly up to version 1.0.0, package files were stored in internal package pool - // with MD5-dervied path, since 1.1.0 package pool layout was changed; - // if option is enabled, aptly stops checking for legacy paths; - // by default option is enabled for new aptly installations and disabled when - // upgrading from older versions - "skipLegacyPool": true, +# PPA +###### -// Aptly Server -//////////////// +# Specify paramaters for short PPA url expansion +# empty defaults to output of `lsb_release` command +ppa_distributor_id: ubuntu - // Serve published repos as well as API - "serveInAPIMode": false, +# Codename for short PPA url expansion +ppa_codename: "" - // Enable metrics for Prometheus client - "enableMetricsEndpoint": false, - // Enable API documentation on /docs - "enableSwaggerEndpoint": false, +# Aptly Server +############### - // OBSOLETE: use via url param ?_async=true - "AsyncAPI": false, +# Serve published repos as well as API +serve_in_api_mode: false +# Enable metrics for Prometheus client +enable_metrics_endpoint: false -// Database -//////////// +# Enable API documentation on /docs +enable_swagger_endpoint: false + +# OBSOLETE: use via url param ?_async=true +async_api: false + + +# Database +########### + +# Database backend +# Type must be one of: +# * leveldb (default) +# * etcd +database_backend: + type: leveldb + # Path to leveldb files + # empty dbPath defaults to `rootDir`/db + db_path: "" + + # type: etcd + # # URL to db server + # url: "127.0.0.1:2379" + + +# Mirroring +############ + +# Downloader +# * "default" +# * "grab" (more robust) +downloader: default + +# Number of parallel download threads to use when downloading packages +download_concurrency: 4 + +# Limit in kbytes/sec on download speed while mirroring remote repositories +download_limit: 0 + +# Number of retries for download attempts +download_retries: 0 + +# Download source packages per default +download_sourcepackages: false + + +# Signing +########## + +# GPG Provider +# * "internal" (Go internal implementation) +# * "gpg" (External `gpg` utility) +gpg_provider: gpg + +# Disable signing of published repositories +gpg_disable_sign: false + +# Disable signature verification of remote repositories +gpg_disable_verify: false + + +# Publishing +############# + +# Do not publish Contents files +skip_contents_publishing: false + +# Do not create bz2 files +skip_bz2_publishing: false + + +# Storage +########## + +# Filesystem publishing endpoints +# +# aptly defaults to publish to a single publish directory under `rootDir`/public. For +# a more advanced publishing strategy, you can define one or more filesystem endpoints in the +# `FileSystemPublishEndpoints` list of the aptly configuration file. Each endpoint has a name +# and the following associated settings. +# +# In order to publish to such an endpoint, specify the endpoint as `filesystem:endpoint-name` +# with `endpoint-name` as the name given in the aptly configuration file. For example: +# +# `aptly publish snapshot wheezy-main filesystem:test1:wheezy/daily` +# +filesystem_publish_endpoints: + # # Endpoint Name + # test1: + # # Directory for publishing + # root_dir: /opt/srv/aptly_public + # # File Link Method for linking files from the internal pool to the published directory + # # * hardlink + # # * symlink + # # * copy + # link_method: hardlink + # # File Copare Method for comparing existing links from the internal pool to the published directory + # # Only used when "linkMethod" is set to "copy" + # # * md5 (default: compare md5 sum) + # # * size (compare file size) + # verify_method: md5 + +# S3 Endpoint Support +# +# cloud storage). First, publishing +# endpoints should be described in aptly configuration file. Each endpoint has name +# and associated settings. +# +# In order to publish to S3, specify endpoint as `s3:endpoint-name:` before +# publishing prefix on the command line, e.g.: +# +# `aptly publish snapshot wheezy-main s3:test:` +# +s3_publish_endpoints: + # # Endpoint Name + # test: + # # Amazon region for S3 bucket + # region: us-east-1 + # # Bucket name + # bucket: test-bucket + # # Prefix (optional) + # # publishing under specified prefix in the bucket, defaults to + # # no prefix (bucket root) + # prefix: "" + # # Default ACLs (optional) + # # assign ACL to published files: + # # * private (default, for use with apt S3 transport) + # # * public-read (public repository) + # # * none (don't set ACL) + # acl: private + # # Credentials (optional) + # # Amazon credentials to access S3 bucket. If not supplied, environment variables + # # `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` are used + # access_key_id: "" + # secret_access_key: "" + # session_token: "" + # # Endpoint (optional) + # # When using S3-compatible cloud storage, specify hostname of service endpoint here, + # # region is ignored if endpoint is set (set region to some human-readable name) + # # (should be left blank for real Amazon S3) + # endpoint: "" + # # Storage Class (optional) + # # Amazon S3 storage class, defaults to `STANDARD`. Other values + # # available: `REDUCED_REDUNDANCY` (lower price, lower redundancy) + # storage_class: STANDARD + # # Encryption Method (optional) + # # Server-side encryption method, defaults to none. Currently + # # the only available encryption method is `AES256` + # encryption_method: none + # # Plus Workaround (optional) + # # Workaround misbehavior in apt and Amazon S3 for files with `+` in filename by + # # creating two copies of package files with `+` in filename: one original + # # and another one with spaces instead of plus signs + # # With `plusWorkaround` enabled, package files with plus sign + # # would be stored twice. aptly might not cleanup files with spaces when published + # # repository is dropped or updated (switched) to new version of repository (snapshot) + # plus_workaround: false + # # Disable MultiDel (optional) + # # For S3-compatible cloud storages which do not support `MultiDel` S3 API, + # # enable this setting (file deletion would be slower with this setting enabled) + # disable_multidel: false + # # Force Signature v2 (optional) + # # Disable Signature V4 support, useful with non-AWS S3-compatible object stores + # # which do not support SigV4, shouldn't be enabled for AWS + # force_sigv2: false + # # Force VirtualHosted Style (optional) + # # Disable path style visit, useful with non-AWS S3-compatible object stores + # # which only support virtual hosted style + # force_virtualhosted_style: false + # # Debug (optional) + # # Enables detailed request/response dump for each S3 operation + # debug: false + +# Swift Endpoint Support +# +# aptly can publish a repository directly to OpenStack Swift. +# Each endpoint has name and associated settings. +# +# In order to publish to Swift, specify endpoint as `swift:endpoint-name:` before +# publishing prefix on the command line, e.g.: +# +# `aptly publish snapshot jessie-main swift:test:` +# +swift_publish_endpoints: + # # Endpoint Name + # test: + # # Container Name + # container: taylor1 + # # Prefix (optional) + # # Publish under specified prefix in the container, defaults to no prefix (container root) + # prefix: "" + # # Credentials (optional) + # # OpenStack credentials to access Keystone. If not supplied, environment variables `OS_USERNAME` and `OS_PASSWORD` are used + # username: "" + # password: "" + # # Domain (optional) + # # OpenStack domain + # domain: "" + # domain_id: "" + # # Tenant (optional) + # # OpenStack tenant (in order to use v2 authentication) + # tenant: "" + # tenant_id: "" + # tenant_domain: "" + # tenant_domain_id: "" + # # Auth URL (optional) + # # Full url of Keystone server (including port, and version). + # # Example `http://identity.example.com:5000/v2.0` + # auth_url: "" + +# Azure Endpoint Support +# +# aptly can be configured to publish repositories directly to Microsoft Azure Blob +# Storage. First, publishing endpoints should be described in the aptly +# configuration file. Each endpoint has its name and associated settings. +azure_publish_endpoints: + # # Endpoint Name + # test: + # # Container Name + # container: container1 + # # Prefix (optional) + # # Publishing under specified prefix in the container, defaults to no prefix (container root) + # prefix: "" + # # Credentials + # # Azure storage account access key to access blob storage + # account_name: "" + # account_key: "" + # # Endpoint URL + # # See: Azure documentation https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string + # # defaults to "https://.blob.core.windows.net" + # endpoint: "" + +# Package Pool +# +# Location for storing downloaded packages +# Type must be one of: +# * local +# * azure +packagepool_storage: + # Local Pool + type: local + # Local Pool Path + # empty path defaults to `rootDir`/pool + path: + + # # Azure Azure Blob Storage Pool + # type: azure + # # Container Name + # container: pool1 + # # Prefix (optional) + # # Publishing under specified prefix in the container, defaults to no prefix (container root) + # prefix: "" + # # Credentials + # # Azure storage account access key to access blob storage + # account_name: "" + # account_key: "" + # # Endpoint URL + # # See: Azure documentation https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string + # # defaults to "https://.blob.core.windows.net" + # endpoint: "" - // Database backend - // Type must be one of: - // * leveldb (default) - // * etcd - "databaseBackend": { - // LevelDB - "type": "leveldb", - // Path to leveldb files - // empty dbPath defaults to `rootDir`/db - "dbPath": "" - - // // etcd - // "type": "etcd", - // // URL to db server - // "url": "127.0.0.1:2379" - }, - - -// Mirroring -///////////// - - // Downloader - // * "default" - // * "grab" (more robust) - "downloader": "default", - - // Number of parallel download threads to use when downloading packages - "downloadConcurrency": 4, - - // Limit in kbytes/sec on download speed while mirroring remote repositories - "downloadSpeedLimit": 0, - - // Number of retries for download attempts - "downloadRetries": 0, - - // Download source packages per default - "downloadSourcePackages": false, - - -// Signing -/////////// - - // GPG Provider - // * "internal" (Go internal implementation) - // * "gpg" (External `gpg` utility) - "gpgProvider": "gpg", - - // Disable signing of published repositories - "gpgDisableSign": false, - - // Disable signature verification of remote repositories - "gpgDisableVerify": false, - - -// Publishing -////////////// - - // Do not publish Contents files - "skipContentsPublishing": false, - - // Do not create bz2 files - "skipBz2Publishing": false, - - -// Storage -/////////// - - // Filesystem publishing endpoints - // - // aptly defaults to publish to a single publish directory under `rootDir`/public. For - // a more advanced publishing strategy, you can define one or more filesystem endpoints in the - // `FileSystemPublishEndpoints` list of the aptly configuration file. Each endpoint has a name - // and the following associated settings. - // - // In order to publish to such an endpoint, specify the endpoint as `filesystem:endpoint-name` - // with `endpoint-name` as the name given in the aptly configuration file. For example: - // - // `aptly publish snapshot wheezy-main filesystem:test1:wheezy/daily` - // - "FileSystemPublishEndpoints": { - // // Endpoint Name - // "test1": { - // // Directory for publishing - // "rootDir": "/opt/srv/aptly_public", - - // // File Link Method for linking files from the internal pool to the published directory - // // * hardlink - // // * symlink - // // * copy - // "linkMethod": "hardlink", - - // // File Copare Method for comparing existing links from the internal pool to the published directory - // // Only used when "linkMethod" is set to "copy" - // // * md5 (default: compare md5 sum) - // // * size (compare file size) - // "verifyMethod": "md5" - // } - }, - - // S3 Endpoint Support - // - // cloud storage). First, publishing - // endpoints should be described in aptly configuration file. Each endpoint has name - // and associated settings. - // - // In order to publish to S3, specify endpoint as `s3:endpoint-name:` before - // publishing prefix on the command line, e.g.: - // - // `aptly publish snapshot wheezy-main s3:test:` - // - "S3PublishEndpoints": { - // // Endpoint Name - // "test": { - - // // Amazon region for S3 bucket - // "region": "us-east-1", - - // // Bucket name - // "bucket": "test-bucket", - - // // Endpoint (optional) - // // When using S3-compatible cloud storage, specify hostname of service endpoint here, - // // region is ignored if endpoint is set (set region to some human-readable name) - // // (should be left blank for real Amazon S3) - // "endpoint": "", - - // // Prefix (optional) - // // publishing under specified prefix in the bucket, defaults to - // // no prefix (bucket root) - // "prefix": "", - - // // Default ACLs (optional) - // // assign ACL to published files (one of the canned ACLs in Amazon - // // terminology). Useful values: `private` (default), `public-read` (public - // // repository) or `none` (don't set ACL). Public repositories could be consumed by `apt` using - // // HTTP endpoint (Amazon bucket should be configured for "website hosting"), - // // for private repositories special apt S3 transport is required. - // "acl": "private", - - // // Credentials (optional) - // // Amazon credentials to access S3 bucket. If not supplied, - // // environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` - // // are used. - // "awsAccessKeyID": "", - // "awsSecretAccessKey": "", - - // // Storage Class (optional) - // // Amazon S3 storage class, defaults to `STANDARD`. Other values - // // available: `REDUCED_REDUNDANCY` (lower price, lower redundancy) - // "storageClass": "STANDARD", - - // // Encryption Method (optional) - // // Server-side encryption method, defaults to none. Currently - // // the only available encryption method is `AES256` - // "encryptionMethod": "none", - - // // Plus Workaround (optional) - // // Workaround misbehavior in apt and Amazon S3 for files with `+` in filename by - // // creating two copies of package files with `+` in filename: one original - // // and another one with spaces instead of plus signs - // // With `plusWorkaround` enabled, package files with plus sign - // // would be stored twice. aptly might not cleanup files with spaces when published - // // repository is dropped or updated (switched) to new version of repository (snapshot) - // "plusWorkaround": false, - - // // Disable MultiDel (optional) - // // For S3-compatible cloud storages which do not support `MultiDel` S3 API, - // // enable this setting (file deletion would be slower with this setting enabled) - // "disableMultiDel": false, - - // // ForceSig2 (optional) - // // Disable Signature V4 support, useful with non-AWS S3-compatible object stores - // // which do not support SigV4, shouldn't be enabled for AWS - // "forceSigV2": false, - - // // ForceVirtualHostedStyle (optional) - // // Disable path style visit, useful with non-AWS S3-compatible object stores - // // which only support virtual hosted style - // "forceVirtualHostedStyle": false, - - // // Debug (optional) - // // Enables detailed request/response dump for each S3 operation - // "debug": false - // } - }, - - // Swift Endpoint Support - // - // aptly could be configured to publish repository directly to OpenStack Swift. First, - // publishing endpoints should be described in aptly configuration file. Each endpoint - // has name and associated settings. - // - // In order to publish to Swift, specify endpoint as `swift:endpoint-name:` before - // publishing prefix on the command line, e.g.: - // - // `aptly publish snapshot jessie-main swift:test:` - // - "SwiftPublishEndpoints": { - // Endpoint Name - // "test": { - - // // Container Name - // "container": "taylor1", - - // // Prefix (optional) - // // Publish under specified prefix in the container, defaults to no prefix (container root) - // "prefix": "", - - // // Credentials (optional) - // // OpenStack credentials to access Keystone. If not supplied, environment variables `OS_USERNAME` and `OS_PASSWORD` are used - // "osname": "", - // "password": "", - - // // Tenant (optional) - // // OpenStack tenant name and id (in order to use v2 authentication) - // "tenant": "", - // "tenantid": "", - - // // Auth URL (optional) - // // Full url of Keystone server (including port, and version). - // // Example `http://identity.example.com:5000/v2.0` - // "authurl": "" - // } - }, - - // Azure Endpoint Support - // - // aptly can be configured to publish repositories directly to Microsoft Azure Blob - // Storage. First, publishing endpoints should be described in the aptly - // configuration file. Each endpoint has its name and associated settings. - "AzurePublishEndpoints": { - // // Endpoint Name - // "test": { - - // // Container Name - // "container": "container1", - - // // Prefix (optional) - // // Publishing under specified prefix in the container, defaults to no prefix (container root) - // "prefix": "", - - // // Credentials - // // Azure storage account access key to access blob storage - // "accountName": "", - // "accountKey": "", - - // // Endpoint URL - // // See: Azure documentation https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string - // // defaults to "https://.blob.core.windows.net" - // "endpoint": "" - // } - }, - - // Package Pool - // Location for storing downloaded packages - // Type must be one of: - // * local - // * azure - "packagePoolStorage": { - // Local Pool - "type": "local", - // Local Pool Path - // empty path defaults to `rootDir`/pool - "path": "" - - // // Azure Azure Blob Storage Pool - // "type": "azure", - // "container": "pool1", - - // // Prefix (optional) - // // Publishing under specified prefix in the container, defaults to no prefix (container root) - // "prefix": "", - - // // Credentials - // // Azure storage account access key to access blob storage - // "accountName": "", - // "accountKey": "", - - // // Endpoint URL - // // See: Azure documentation https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string - // // defaults to "https://.blob.core.windows.net" - // "endpoint": "" - } - -// End of config -} diff --git a/utils/config.go b/utils/config.go index 5b8aedd0c..7f02595c3 100644 --- a/utils/config.go +++ b/utils/config.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "errors" "github.com/DisposaBoy/JsonConfigReader" "gopkg.in/yaml.v3" @@ -81,6 +82,9 @@ type PackagePoolStorage struct { Azure *AzureEndpoint } +var AZURE = "azure" +var LOCAL = "local" + func (pool *PackagePoolStorage) UnmarshalJSON(data []byte) error { var discriminator struct { Type string `json:"type"` @@ -91,10 +95,10 @@ func (pool *PackagePoolStorage) UnmarshalJSON(data []byte) error { } switch discriminator.Type { - case "azure": + case AZURE: pool.Azure = &AzureEndpoint{} return json.Unmarshal(data, &pool.Azure) - case "local", "": + case LOCAL, "": pool.Local = &LocalPoolStorage{} return json.Unmarshal(data, &pool.Local) default: @@ -111,10 +115,10 @@ func (pool *PackagePoolStorage) UnmarshalYAML(unmarshal func(interface{}) error) } switch discriminator.Type { - case "azure": + case AZURE: pool.Azure = &AzureEndpoint{} return unmarshal(&pool.Azure) - case "local", "": + case LOCAL, "": pool.Local = &LocalPoolStorage{} return unmarshal(&pool.Local) default: @@ -250,17 +254,13 @@ func LoadConfig(filename string, config *ConfigStructure) error { } defer f.Close() - dec_json := json.NewDecoder(JsonConfigReader.New(f)) - if err = dec_json.Decode(&config); err != nil { + decJSON := json.NewDecoder(JsonConfigReader.New(f)) + if err = decJSON.Decode(&config); err != nil { f.Seek(0, 0) - dec_yaml := yaml.NewDecoder(f) - if err = dec_yaml.Decode(&config); err != nil { - fmt.Errorf("config file %s is not valid yaml or json\n", filename) - } else { - fmt.Printf("config file %s format is yaml\n", filename) + decYAML := yaml.NewDecoder(f) + if err = decYAML.Decode(&config); err != nil { + err = errors.New("not valid yaml or json") } - } else { - fmt.Printf("config file %s format is json\n", filename) } return err } diff --git a/utils/config_test.go b/utils/config_test.go index ddfa4ba91..d88944e23 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -63,93 +63,93 @@ func (s *ConfigSuite) TestSaveConfig(c *C) { f.Read(buf) c.Check(string(buf), Equals, ""+ - "{\n"+ - " \"rootDir\": \"/tmp/aptly\",\n"+ - " \"downloadConcurrency\": 5,\n"+ - " \"downloadSpeedLimit\": 0,\n"+ - " \"downloadRetries\": 0,\n"+ - " \"downloader\": \"\",\n"+ - " \"databaseOpenAttempts\": 5,\n"+ - " \"architectures\": null,\n"+ - " \"dependencyFollowSuggests\": false,\n"+ - " \"dependencyFollowRecommends\": false,\n"+ - " \"dependencyFollowAllVariants\": false,\n"+ - " \"dependencyFollowSource\": false,\n"+ - " \"dependencyVerboseResolve\": false,\n"+ - " \"gpgDisableSign\": false,\n"+ - " \"gpgDisableVerify\": false,\n"+ - " \"gpgProvider\": \"gpg\",\n"+ - " \"downloadSourcePackages\": false,\n"+ - " \"packagePoolStorage\": {\n"+ - " \"type\": \"local\",\n"+ - " \"path\": \"/tmp/aptly-pool\"\n"+ - " },\n"+ - " \"skipLegacyPool\": false,\n"+ - " \"ppaDistributorID\": \"\",\n"+ - " \"ppaCodename\": \"\",\n"+ - " \"skipContentsPublishing\": false,\n"+ - " \"skipBz2Publishing\": false,\n"+ - " \"FileSystemPublishEndpoints\": {\n"+ - " \"test\": {\n"+ - " \"rootDir\": \"/opt/aptly-publish\",\n"+ - " \"linkMethod\": \"\",\n"+ - " \"verifyMethod\": \"\"\n"+ - " }\n"+ - " },\n"+ - " \"S3PublishEndpoints\": {\n"+ - " \"test\": {\n"+ - " \"region\": \"us-east-1\",\n"+ - " \"bucket\": \"repo\",\n"+ - " \"endpoint\": \"\",\n"+ - " \"awsAccessKeyID\": \"\",\n"+ - " \"awsSecretAccessKey\": \"\",\n"+ - " \"awsSessionToken\": \"\",\n"+ - " \"prefix\": \"\",\n"+ - " \"acl\": \"\",\n"+ - " \"storageClass\": \"\",\n"+ - " \"encryptionMethod\": \"\",\n"+ - " \"plusWorkaround\": false,\n"+ - " \"disableMultiDel\": false,\n"+ - " \"forceSigV2\": false,\n"+ - " \"forceVirtualHostedStyle\": false,\n"+ - " \"debug\": false\n"+ - " }\n"+ - " },\n"+ - " \"SwiftPublishEndpoints\": {\n"+ - " \"test\": {\n"+ - " \"osname\": \"\",\n"+ - " \"password\": \"\",\n"+ - " \"authurl\": \"\",\n"+ - " \"tenant\": \"\",\n"+ - " \"tenantid\": \"\",\n"+ - " \"domain\": \"\",\n"+ - " \"domainid\": \"\",\n"+ - " \"tenantdomain\": \"\",\n"+ - " \"tenantdomainid\": \"\",\n"+ - " \"prefix\": \"\",\n"+ - " \"container\": \"repo\"\n"+ - " }\n"+ - " },\n"+ - " \"AzurePublishEndpoints\": {\n"+ - " \"test\": {\n"+ - " \"accountName\": \"\",\n"+ - " \"accountKey\": \"\",\n"+ - " \"container\": \"repo\",\n"+ - " \"prefix\": \"\",\n"+ - " \"endpoint\": \"\"\n"+ - " }\n"+ - " },\n"+ - " \"AsyncAPI\": false,\n"+ - " \"enableMetricsEndpoint\": false,\n"+ - " \"logLevel\": \"info\",\n"+ - " \"logFormat\": \"json\",\n"+ - " \"serveInAPIMode\": false,\n"+ - " \"databaseBackend\": {\n"+ - " \"type\": \"\",\n"+ - " \"url\": \"\",\n"+ - " \"dbPath\": \"\"\n" + - " },\n"+ - " \"enableSwaggerEndpoint\": false\n" + + "{\n" + + " \"rootDir\": \"/tmp/aptly\",\n" + + " \"logLevel\": \"info\",\n" + + " \"logFormat\": \"json\",\n" + + " \"databaseOpenAttempts\": 5,\n" + + " \"architectures\": null,\n" + + " \"skipLegacyPool\": false,\n" + + " \"dependencyFollowSuggests\": false,\n" + + " \"dependencyFollowRecommends\": false,\n" + + " \"dependencyFollowAllVariants\": false,\n" + + " \"dependencyFollowSource\": false,\n" + + " \"dependencyVerboseResolve\": false,\n" + + " \"ppaDistributorID\": \"\",\n" + + " \"ppaCodename\": \"\",\n" + + " \"serveInAPIMode\": false,\n" + + " \"enableMetricsEndpoint\": false,\n" + + " \"enableSwaggerEndpoint\": false,\n" + + " \"AsyncAPI\": false,\n" + + " \"databaseBackend\": {\n" + + " \"type\": \"\",\n" + + " \"dbPath\": \"\",\n" + + " \"url\": \"\"\n" + + " },\n" + + " \"downloader\": \"\",\n" + + " \"downloadConcurrency\": 5,\n" + + " \"downloadSpeedLimit\": 0,\n" + + " \"downloadRetries\": 0,\n" + + " \"downloadSourcePackages\": false,\n" + + " \"gpgProvider\": \"gpg\",\n" + + " \"gpgDisableSign\": false,\n" + + " \"gpgDisableVerify\": false,\n" + + " \"skipContentsPublishing\": false,\n" + + " \"skipBz2Publishing\": false,\n" + + " \"FileSystemPublishEndpoints\": {\n" + + " \"test\": {\n" + + " \"rootDir\": \"/opt/aptly-publish\",\n" + + " \"linkMethod\": \"\",\n" + + " \"verifyMethod\": \"\"\n" + + " }\n" + + " },\n" + + " \"S3PublishEndpoints\": {\n" + + " \"test\": {\n" + + " \"region\": \"us-east-1\",\n" + + " \"bucket\": \"repo\",\n" + + " \"prefix\": \"\",\n" + + " \"acl\": \"\",\n" + + " \"awsAccessKeyID\": \"\",\n" + + " \"awsSecretAccessKey\": \"\",\n" + + " \"awsSessionToken\": \"\",\n" + + " \"endpoint\": \"\",\n" + + " \"storageClass\": \"\",\n" + + " \"encryptionMethod\": \"\",\n" + + " \"plusWorkaround\": false,\n" + + " \"disableMultiDel\": false,\n" + + " \"forceSigV2\": false,\n" + + " \"forceVirtualHostedStyle\": false,\n" + + " \"debug\": false\n" + + " }\n" + + " },\n" + + " \"SwiftPublishEndpoints\": {\n" + + " \"test\": {\n" + + " \"container\": \"repo\",\n" + + " \"prefix\": \"\",\n" + + " \"osname\": \"\",\n" + + " \"password\": \"\",\n" + + " \"tenant\": \"\",\n" + + " \"tenantid\": \"\",\n" + + " \"domain\": \"\",\n" + + " \"domainid\": \"\",\n" + + " \"tenantdomain\": \"\",\n" + + " \"tenantdomainid\": \"\",\n" + + " \"authurl\": \"\"\n" + + " }\n" + + " },\n" + + " \"AzurePublishEndpoints\": {\n" + + " \"test\": {\n" + + " \"container\": \"repo\",\n" + + " \"prefix\": \"\",\n" + + " \"accountName\": \"\",\n" + + " \"accountKey\": \"\",\n" + + " \"endpoint\": \"\"\n" + + " }\n" + + " },\n" + + " \"packagePoolStorage\": {\n" + + " \"type\": \"local\",\n" + + " \"path\": \"/tmp/aptly-pool\"\n" + + " }\n" + "}") }