makit 0.0.147 → 0.0.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generated/makit/v1/configuration/project_pb.rb +22 -0
  3. data/lib/generated/makit/v1/configuration/project_service_pb.rb +34 -0
  4. data/lib/generated/makit/v1/configuration/project_service_services_pb.rb +51 -0
  5. data/lib/generated/makit/v1/git/git_repository_model_pb.rb +22 -0
  6. data/lib/generated/makit/v1/git/git_repository_service_pb.rb +29 -0
  7. data/lib/generated/makit/v1/git/git_repository_service_services_pb.rb +39 -0
  8. data/lib/generated/makit/v1/gitlab/pipeline_pb.rb +26 -0
  9. data/lib/generated/makit/v1/gitlab/pipeline_result_pb.rb +29 -0
  10. data/lib/generated/makit/v1/gitlab/pipeline_service_pb.rb +36 -0
  11. data/lib/generated/makit/v1/gitlab/pipeline_service_services_pb.rb +41 -0
  12. data/lib/generated/makit/v1/grpc/service_specification_pb.rb +27 -0
  13. data/lib/generated/makit/v1/grpc/test_specification_pb.rb +29 -0
  14. data/lib/generated/makit/v1/io/filesystem_pb.rb +27 -0
  15. data/lib/generated/makit/v1/io/filesystem_services_pb.rb +47 -0
  16. data/lib/generated/makit/v1/makit.v1_pb.rb +35 -0
  17. data/lib/generated/makit/v1/makit.v1_services_pb.rb +26 -0
  18. data/lib/generated/makit/v1/podman/podman_service_pb.rb +64 -0
  19. data/lib/generated/makit/v1/podman/podman_service_services_pb.rb +52 -0
  20. data/lib/generated/makit/v1/services/repository_manager_model_pb.rb +23 -0
  21. data/lib/generated/makit/v1/services/repository_manager_service_pb.rb +32 -0
  22. data/lib/generated/makit/v1/services/repository_manager_service_services_pb.rb +35 -0
  23. data/lib/generated/makit/v1/spec/message_proto_generator_pb.rb +33 -0
  24. data/lib/generated/makit/v1/spec/message_proto_generator_services_pb.rb +38 -0
  25. data/lib/generated/makit/v1/spec/message_spec_pb.rb +31 -0
  26. data/lib/generated/makit/v1/spec/message_spec_suite_pb.rb +30 -0
  27. data/lib/generated/makit/v1/spec/message_spec_test_pb.rb +34 -0
  28. data/lib/generated/makit/v1/spec/proto_service_pb.rb +53 -0
  29. data/lib/generated/makit/v1/spec/proto_service_services_pb.rb +42 -0
  30. data/lib/generated/makit/v1/spec/spec_manifest_pb.rb +44 -0
  31. data/lib/generated/makit/v1/web/link_pb.rb +20 -0
  32. data/lib/makit/azure/blob_storage.rb +257 -0
  33. data/lib/makit/azure/cli.rb +285 -0
  34. data/lib/makit/configuration/project.rb +137 -291
  35. data/lib/makit/git/repository.rb +24 -190
  36. data/lib/makit/gitlab/pipeline.rb +16 -16
  37. data/lib/makit/gitlab/pipeline_service_impl.rb +43 -43
  38. data/lib/makit/io/filesystem_service_impl.rb +6 -6
  39. data/lib/makit/lint.rb +212 -0
  40. data/lib/makit/logging/configuration.rb +2 -1
  41. data/lib/makit/logging.rb +15 -2
  42. data/lib/makit/podman/podman.rb +20 -20
  43. data/lib/makit/podman/podman_service_impl.rb +41 -41
  44. data/lib/makit/secrets/azure_key_vault.rb +323 -0
  45. data/lib/makit/secrets/azure_secrets.rb +183 -0
  46. data/lib/makit/secrets/local_secrets.rb +72 -0
  47. data/lib/makit/secrets/secrets_manager.rb +105 -0
  48. data/lib/makit/secrets.rb +10 -45
  49. data/lib/makit/tasks/bump.rb +7 -0
  50. data/lib/makit/tasks/info.rb +204 -0
  51. data/lib/makit/tasks/integrate.rb +28 -1
  52. data/lib/makit/tasks/secrets.rb +7 -0
  53. data/lib/makit/tasks/version.rb +6 -0
  54. data/lib/makit/tasks.rb +4 -0
  55. data/lib/makit/v1/configuration/project_service_impl.rb +1 -1
  56. data/lib/makit/version.rb +382 -1
  57. data/lib/makit.rb +21 -18
  58. metadata +46 -5
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: makit/v1/spec/spec_manifest.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+ require 'google/protobuf/struct_pb'
8
+ require 'makit/v1/spec/message_spec_pb'
9
+ require 'makit/v1/spec/message_spec_suite_pb'
10
+ require 'makit/v1/spec/message_spec_test_pb'
11
+
12
+
13
+ descriptor_data = "\n!makit/v1/spec/spec_manifest.proto\x12\rmakit.v1.spec\x1a\x1cgoogle/protobuf/struct.proto\x1a makit/v1/spec/message_spec.proto\x1a&makit/v1/spec/message_spec_suite.proto\x1a%makit/v1/spec/message_spec_test.proto\"\x96\x03\n\x0cSpecManifest\x12\x15\n\rmanifest_name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x13\n\x0bprotos_path\x18\x04 \x01(\t\x12\x36\n\rmessage_suite\x18\x05 \x01(\x0b\x32\x1f.makit.v1.spec.MessageSpecSuite\x12\x32\n\ntest_suite\x18\x06 \x01(\x0b\x32\x1e.makit.v1.spec.MessageSpecTest\x12\x31\n\x10\x61\x64\x64itional_specs\x18\x07 \x03(\x0b\x32\x17.makit.v1.spec.SpecFile\x12\x33\n\x0c\x64\x65pendencies\x18\x08 \x03(\x0b\x32\x1d.makit.v1.spec.SpecDependency\x12-\n\x08metadata\x18\t \x01(\x0b\x32\x1b.makit.v1.spec.SpecMetadata\x12\x31\n\ngovernance\x18\n \x01(\x0b\x32\x1d.makit.v1.spec.GovernanceInfo\"\x9f\x01\n\x08SpecFile\x12\x11\n\tfile_path\x18\x01 \x01(\t\x12.\n\tfile_type\x18\x02 \x01(\x0e\x32\x1b.makit.v1.spec.SpecFileType\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x10\n\x08\x63hecksum\x18\x04 \x01(\t\x12\x12\n\nsize_bytes\x18\x05 \x01(\x03\x12\x15\n\rlast_modified\x18\x06 \x01(\t\"\xee\x01\n\x0eSpecDependency\x12\x17\n\x0f\x64\x65pendency_name\x18\x01 \x01(\t\x12\x1a\n\x12version_constraint\x18\x02 \x01(\t\x12\x36\n\x0f\x64\x65pendency_type\x18\x03 \x01(\x0e\x32\x1d.makit.v1.spec.DependencyType\x12\x13\n\x0b\x64\x65scription\x18\x04 \x01(\t\x12/\n\x06source\x18\x05 \x01(\x0e\x32\x1f.makit.v1.spec.DependencySource\x12)\n\x08metadata\x18\x06 \x01(\x0b\x32\x17.google.protobuf.Struct\"\xd4\x02\n\x0eGovernanceInfo\x12)\n\x06\x61uthor\x18\x01 \x01(\x0b\x32\x19.makit.v1.spec.AuthorInfo\x12+\n\x07license\x18\x02 \x01(\x0b\x32\x1a.makit.v1.spec.LicenseInfo\x12\x34\n\x0ereview_process\x18\x03 \x01(\x0b\x32\x1c.makit.v1.spec.ReviewProcess\x12:\n\x11\x63hange_management\x18\x04 \x01(\x0b\x32\x1f.makit.v1.spec.ChangeManagement\x12\x31\n\rquality_gates\x18\x05 \x03(\x0b\x32\x1a.makit.v1.spec.QualityGate\x12\x45\n\x17\x63ompliance_requirements\x18\x06 \x03(\x0b\x32$.makit.v1.spec.ComplianceRequirement\"\x85\x01\n\nAuthorInfo\x12\x16\n\x0eprimary_author\x18\x01 \x01(\t\x12\x1c\n\x14\x63ontributing_authors\x18\x02 \x03(\t\x12\x14\n\x0corganization\x18\x03 \x01(\t\x12+\n\x07\x63ontact\x18\x04 \x01(\x0b\x32\x1a.makit.v1.spec.ContactInfo\"\xb9\x01\n\x0b\x43ontactInfo\x12\r\n\x05\x65mail\x18\x01 \x01(\t\x12\x0f\n\x07website\x18\x02 \x01(\t\x12O\n\x13\x61\x64\x64itional_contacts\x18\x03 \x03(\x0b\x32\x32.makit.v1.spec.ContactInfo.AdditionalContactsEntry\x1a\x39\n\x17\x41\x64\x64itionalContactsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"h\n\x0bLicenseInfo\x12\x14\n\x0clicense_type\x18\x01 \x01(\t\x12\x14\n\x0clicense_text\x18\x02 \x01(\t\x12\x13\n\x0blicense_url\x18\x03 \x01(\t\x12\x18\n\x10\x63opyright_notice\x18\x04 \x01(\t\"\x90\x01\n\rReviewProcess\x12.\n\x0breview_type\x18\x01 \x01(\x0e\x32\x19.makit.v1.spec.ReviewType\x12\x1a\n\x12required_reviewers\x18\x02 \x03(\t\x12\x17\n\x0freview_criteria\x18\x03 \x03(\t\x12\x1a\n\x12\x61pproval_threshold\x18\x04 \x01(\x05\"\x95\x02\n\x10\x43hangeManagement\x12>\n\x10\x61pproval_process\x18\x01 \x01(\x0e\x32$.makit.v1.spec.ChangeApprovalProcess\x12>\n\x13versioning_strategy\x18\x02 \x01(\x0e\x32!.makit.v1.spec.VersioningStrategy\x12\x43\n\x16\x62reaking_change_policy\x18\x03 \x01(\x0b\x32#.makit.v1.spec.BreakingChangePolicy\x12<\n\x12\x64\x65precation_policy\x18\x04 \x01(\x0b\x32 .makit.v1.spec.DeprecationPolicy\"\x8f\x01\n\x14\x42reakingChangePolicy\x12\x13\n\x0b\x64\x65scription\x18\x01 \x01(\t\x12 \n\x18notification_period_days\x18\x02 \x01(\x05\x12%\n\x1dmigration_support_period_days\x18\x03 \x01(\x05\x12\x19\n\x11\x61pproval_required\x18\x04 \x01(\x08\"\x7f\n\x11\x44\x65precationPolicy\x12\x13\n\x0b\x64\x65scription\x18\x01 \x01(\t\x12\x1a\n\x12notice_period_days\x18\x02 \x01(\x05\x12\x1b\n\x13removal_period_days\x18\x03 \x01(\x05\x12\x1c\n\x14migration_assistance\x18\x04 \x01(\x08\"\xe1\x01\n\x0bQualityGate\x12\x11\n\tgate_name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x31\n\tgate_type\x18\x03 \x01(\x0e\x32\x1e.makit.v1.spec.QualityGateType\x12.\n\rconfiguration\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x11\n\tthreshold\x18\x05 \x01(\x01\x12\x34\n\x08severity\x18\x06 \x01(\x0e\x32\".makit.v1.spec.QualityGateSeverity\"\xc8\x01\n\x15\x43omplianceRequirement\x12\x18\n\x10requirement_name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x1b\n\x13\x63ompliance_standard\x18\x03 \x01(\t\x12-\n\x05level\x18\x04 \x01(\x0e\x32\x1e.makit.v1.spec.ComplianceLevel\x12\x19\n\x11validation_method\x18\x05 \x01(\t\x12\x19\n\x11\x65vidence_required\x18\x06 \x03(\t*\xe3\x01\n\x0cSpecFileType\x12\x1e\n\x1aSPEC_FILE_TYPE_UNSPECIFIED\x10\x00\x12\x18\n\x14SPEC_FILE_TYPE_PROTO\x10\x01\x12\x1c\n\x18SPEC_FILE_TYPE_JSON_SPEC\x10\x02\x12\x1c\n\x18SPEC_FILE_TYPE_TEST_DATA\x10\x03\x12 \n\x1cSPEC_FILE_TYPE_DOCUMENTATION\x10\x04\x12 \n\x1cSPEC_FILE_TYPE_CONFIGURATION\x10\x05\x12\x19\n\x15SPEC_FILE_TYPE_CUSTOM\x10\x06*\xc6\x01\n\x10\x44\x65pendencySource\x12!\n\x1d\x44\x45PENDENCY_SOURCE_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x44\x45PENDENCY_SOURCE_LOCAL\x10\x01\x12\x19\n\x15\x44\x45PENDENCY_SOURCE_GIT\x10\x02\x12\x1e\n\x1a\x44\x45PENDENCY_SOURCE_REGISTRY\x10\x03\x12\x19\n\x15\x44\x45PENDENCY_SOURCE_URL\x10\x04\x12\x1c\n\x18\x44\x45PENDENCY_SOURCE_CUSTOM\x10\x05*\x9b\x01\n\nReviewType\x12\x1b\n\x17REVIEW_TYPE_UNSPECIFIED\x10\x00\x12\x14\n\x10REVIEW_TYPE_NONE\x10\x01\x12\x14\n\x10REVIEW_TYPE_SELF\x10\x02\x12\x14\n\x10REVIEW_TYPE_PEER\x10\x03\x12\x14\n\x10REVIEW_TYPE_TEAM\x10\x04\x12\x18\n\x14REVIEW_TYPE_EXTERNAL\x10\x05*\xd4\x01\n\x15\x43hangeApprovalProcess\x12\'\n#CHANGE_APPROVAL_PROCESS_UNSPECIFIED\x10\x00\x12 \n\x1c\x43HANGE_APPROVAL_PROCESS_NONE\x10\x01\x12%\n!CHANGE_APPROVAL_PROCESS_AUTOMATIC\x10\x02\x12\"\n\x1e\x43HANGE_APPROVAL_PROCESS_MANUAL\x10\x03\x12%\n!CHANGE_APPROVAL_PROCESS_COMMITTEE\x10\x04*\x9d\x01\n\x12VersioningStrategy\x12#\n\x1fVERSIONING_STRATEGY_UNSPECIFIED\x10\x00\x12 \n\x1cVERSIONING_STRATEGY_SEMANTIC\x10\x01\x12 \n\x1cVERSIONING_STRATEGY_CALENDAR\x10\x02\x12\x1e\n\x1aVERSIONING_STRATEGY_CUSTOM\x10\x03*\x80\x02\n\x0fQualityGateType\x12!\n\x1dQUALITY_GATE_TYPE_UNSPECIFIED\x10\x00\x12#\n\x1fQUALITY_GATE_TYPE_TEST_COVERAGE\x10\x01\x12\"\n\x1eQUALITY_GATE_TYPE_CODE_QUALITY\x10\x02\x12!\n\x1dQUALITY_GATE_TYPE_PERFORMANCE\x10\x03\x12\x1e\n\x1aQUALITY_GATE_TYPE_SECURITY\x10\x04\x12 \n\x1cQUALITY_GATE_TYPE_COMPLIANCE\x10\x05\x12\x1c\n\x18QUALITY_GATE_TYPE_CUSTOM\x10\x06*\xc1\x01\n\x13QualityGateSeverity\x12%\n!QUALITY_GATE_SEVERITY_UNSPECIFIED\x10\x00\x12\"\n\x1eQUALITY_GATE_SEVERITY_CRITICAL\x10\x01\x12\x1e\n\x1aQUALITY_GATE_SEVERITY_HIGH\x10\x02\x12 \n\x1cQUALITY_GATE_SEVERITY_MEDIUM\x10\x03\x12\x1d\n\x19QUALITY_GATE_SEVERITY_LOW\x10\x04*\xa5\x01\n\x0f\x43omplianceLevel\x12 \n\x1c\x43OMPLIANCE_LEVEL_UNSPECIFIED\x10\x00\x12\x19\n\x15\x43OMPLIANCE_LEVEL_MUST\x10\x01\x12\x1b\n\x17\x43OMPLIANCE_LEVEL_SHOULD\x10\x02\x12\x18\n\x14\x43OMPLIANCE_LEVEL_MAY\x10\x03\x12\x1e\n\x1a\x43OMPLIANCE_LEVEL_SHALL_NOT\x10\x04\x42>\n\x10io.makit.v1.specP\x01Z\x18github.com/makit/v1/spec\xaa\x02\rMakit.V1.Specb\x06proto3"
14
+
15
+ pool = ::Google::Protobuf::DescriptorPool.generated_pool
16
+ pool.add_serialized_file(descriptor_data)
17
+
18
+ module Makit
19
+ module V1
20
+ module Spec
21
+ SpecManifest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.SpecManifest").msgclass
22
+ SpecFile = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.SpecFile").msgclass
23
+ SpecDependency = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.SpecDependency").msgclass
24
+ GovernanceInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.GovernanceInfo").msgclass
25
+ AuthorInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.AuthorInfo").msgclass
26
+ ContactInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ContactInfo").msgclass
27
+ LicenseInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.LicenseInfo").msgclass
28
+ ReviewProcess = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ReviewProcess").msgclass
29
+ ChangeManagement = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ChangeManagement").msgclass
30
+ BreakingChangePolicy = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.BreakingChangePolicy").msgclass
31
+ DeprecationPolicy = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.DeprecationPolicy").msgclass
32
+ QualityGate = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.QualityGate").msgclass
33
+ ComplianceRequirement = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ComplianceRequirement").msgclass
34
+ SpecFileType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.SpecFileType").enummodule
35
+ DependencySource = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.DependencySource").enummodule
36
+ ReviewType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ReviewType").enummodule
37
+ ChangeApprovalProcess = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ChangeApprovalProcess").enummodule
38
+ VersioningStrategy = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.VersioningStrategy").enummodule
39
+ QualityGateType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.QualityGateType").enummodule
40
+ QualityGateSeverity = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.QualityGateSeverity").enummodule
41
+ ComplianceLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.spec.ComplianceLevel").enummodule
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: makit/v1/web/link.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+ require 'google/protobuf/timestamp_pb'
8
+ require 'google/protobuf/duration_pb'
9
+
10
+
11
+ descriptor_data = "\n\x17makit/v1/web/link.proto\x12\x08makit.v1\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1egoogle/protobuf/duration.proto\"6\n\x04Link\x12\x0b\n\x03url\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\tb\x06proto3"
12
+
13
+ pool = ::Google::Protobuf::DescriptorPool.generated_pool
14
+ pool.add_serialized_file(descriptor_data)
15
+
16
+ module Makit
17
+ module V1
18
+ Link = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("makit.v1.Link").msgclass
19
+ end
20
+ end
@@ -0,0 +1,257 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Azure Blob Storage helper methods
4
+ module Makit
5
+ module Azure
6
+ class BlobStorage
7
+ # Get Azure Storage account from environment variable or Azure Key Vault
8
+ # @return [String, nil] The storage account name, or nil if not found
9
+ def self.storage_account
10
+ # First try environment variable
11
+ return ENV["AZURE_STORAGE_ACCOUNT"] if ENV["AZURE_STORAGE_ACCOUNT"] && !ENV["AZURE_STORAGE_ACCOUNT"].empty?
12
+
13
+ # Fall back to Azure Key Vault if available (requires az login)
14
+ retrieve_from_key_vault("AZURE_STORAGE_ACCOUNT")
15
+ end
16
+
17
+ # Get Azure Storage account key from environment variable or Azure Key Vault
18
+ # @return [String, nil] The storage account key, or nil if not found
19
+ def self.storage_account_key
20
+ # First try environment variable
21
+ return ENV["AZURE_STORAGE_ACCOUNT_KEY"] if ENV["AZURE_STORAGE_ACCOUNT_KEY"] && !ENV["AZURE_STORAGE_ACCOUNT_KEY"].empty?
22
+
23
+ # Fall back to Azure Key Vault if available (requires az login)
24
+ retrieve_from_key_vault("AZURE_STORAGE_ACCOUNT_KEY")
25
+ end
26
+
27
+ # Retrieve a secret from Azure Key Vault
28
+ # Only attempts retrieval if Azure CLI is authenticated (az login has been performed)
29
+ # @param key [String] The secret key name (e.g., "AZURE_STORAGE_ACCOUNT")
30
+ # @return [String, nil] The secret value, or nil if not found or Azure CLI not authenticated
31
+ def self.retrieve_from_key_vault(key)
32
+ # Check if Azure Key Vault is configured
33
+ keyvault_name = ENV["AZURE_KEYVAULT_NAME"]
34
+ return nil unless keyvault_name && !keyvault_name.empty?
35
+
36
+ # Check if Azure CLI is authenticated
37
+ require_relative "../secrets/azure_key_vault"
38
+ return nil unless Makit::Secrets::AzureKeyVault.azure_cli_authenticated?
39
+
40
+ # Try to retrieve from Key Vault
41
+ begin
42
+ require_relative "../secrets/azure_secrets"
43
+ azure_secrets = Makit::Secrets::AzureSecrets.new(keyvault_name: keyvault_name)
44
+ value = azure_secrets.get(key)
45
+ return value if value && !value.empty?
46
+ rescue => e
47
+ # Silently fail - Key Vault retrieval is optional
48
+ # This allows the code to work without Key Vault if env vars are set
49
+ end
50
+
51
+ nil
52
+ end
53
+
54
+ # Validate Azure Storage credentials are set
55
+ # Checks environment variables first, then Azure Key Vault (if az login has been performed)
56
+ def self.validate_storage_credentials!
57
+ account = storage_account
58
+ key = storage_account_key
59
+
60
+ if account.nil? || account.empty?
61
+ error_msg = "AZURE_STORAGE_ACCOUNT is not set"
62
+ # Provide helpful message about Key Vault fallback
63
+ if ENV["AZURE_KEYVAULT_NAME"] && !ENV["AZURE_KEYVAULT_NAME"].empty?
64
+ require_relative "../secrets/azure_key_vault"
65
+ if Makit::Secrets::AzureKeyVault.azure_cli_authenticated?
66
+ error_msg += " (checked environment variables and Azure Key Vault '#{ENV["AZURE_KEYVAULT_NAME"]}')"
67
+ else
68
+ error_msg += " (Azure Key Vault available but 'az login' not performed)"
69
+ end
70
+ end
71
+ raise error_msg
72
+ end
73
+
74
+ if key.nil? || key.empty?
75
+ error_msg = "AZURE_STORAGE_ACCOUNT_KEY is not set"
76
+ # Provide helpful message about Key Vault fallback
77
+ if ENV["AZURE_KEYVAULT_NAME"] && !ENV["AZURE_KEYVAULT_NAME"].empty?
78
+ require_relative "../secrets/azure_key_vault"
79
+ if Makit::Secrets::AzureKeyVault.azure_cli_authenticated?
80
+ error_msg += " (checked environment variables and Azure Key Vault '#{ENV["AZURE_KEYVAULT_NAME"]}')"
81
+ else
82
+ error_msg += " (Azure Key Vault available but 'az login' not performed)"
83
+ end
84
+ end
85
+ raise error_msg
86
+ end
87
+ end
88
+
89
+ # Delete all blobs in a storage path
90
+ # @param path [String] The storage path (e.g., '$web/apps/portal/v0.1.0')
91
+ def self.delete_blobs(path)
92
+ validate_storage_credentials!
93
+ puts " Deleting existing files in #{path}/".colorize(:yellow)
94
+
95
+ cmd = [
96
+ "az storage blob delete-batch",
97
+ "--source '#{path}'",
98
+ "--account-name #{storage_account}",
99
+ "--account-key '#{storage_account_key}'",
100
+ "--pattern '*'",
101
+ "2>/dev/null",
102
+ ].join(" ")
103
+
104
+ system(cmd)
105
+ # Don't fail if path doesn't exist (first deployment)
106
+ true
107
+ end
108
+
109
+ # Upload files to Azure Storage
110
+ # @param source [String] Local directory to upload from
111
+ # @param destination [String] Storage path destination (e.g., '$web/apps/portal/v0.1.0')
112
+ def self.upload_blobs(source, destination)
113
+ validate_storage_credentials!
114
+ puts " Uploading files from #{source} to #{destination}/".colorize(:green)
115
+
116
+ unless Dir.exist?(source)
117
+ raise "Source directory does not exist: #{source}"
118
+ end
119
+
120
+ cmd = [
121
+ "az storage blob upload-batch",
122
+ "--destination '#{destination}'",
123
+ "--source #{source}",
124
+ "--account-name #{storage_account}",
125
+ "--account-key '#{storage_account_key}'",
126
+ "--overwrite",
127
+ ].join(" ")
128
+
129
+ unless system(cmd)
130
+ raise "Failed to upload blobs to Azure Storage"
131
+ end
132
+ true
133
+ end
134
+
135
+ # Get static website endpoint URL for the storage account
136
+ # @return [String] The static website endpoint URL (e.g., 'https://louparslow.z22.web.core.windows.net')
137
+ def self.static_website_endpoint
138
+ validate_storage_credentials!
139
+
140
+ unless Cli.available?
141
+ # Fallback if Azure CLI not available
142
+ return "https://#{storage_account}.z22.web.core.windows.net"
143
+ end
144
+
145
+ # Try to get the static website endpoint from Azure
146
+ cmd = "az storage account show --name #{storage_account} --query 'primaryEndpoints.web' --output tsv 2>/dev/null"
147
+ endpoint = `#{cmd}`.strip
148
+
149
+ if endpoint.nil? || endpoint.empty?
150
+ # Fallback: construct URL from storage account name
151
+ # This assumes the standard format, but may not work for all storage accounts
152
+ endpoint = "https://#{storage_account}.z22.web.core.windows.net"
153
+ puts " Warning: Could not retrieve static website endpoint, using default format".colorize(:yellow)
154
+ end
155
+
156
+ # Remove trailing slash if present
157
+ endpoint.chomp("/")
158
+ end
159
+
160
+ # List blobs in a storage path
161
+ # @param path [String] The storage path (e.g., '$web' or '$web/apps/portal')
162
+ # @return [Array<String>] Array of blob names/paths (immediate children only, flat listing)
163
+ def self.list_blobs(path)
164
+ validate_storage_credentials!
165
+
166
+ # Parse path to extract container name and prefix
167
+ # Path format: "container" or "container/prefix/path"
168
+ path_parts = path.split("/", 2)
169
+ container_name = path_parts[0]
170
+ prefix = path_parts[1] || ""
171
+
172
+ # Build Azure CLI command
173
+ cmd_parts = [
174
+ "az storage blob list",
175
+ "--container-name '#{container_name}'",
176
+ "--account-name #{storage_account}",
177
+ "--account-key '#{storage_account_key}'",
178
+ "--output json",
179
+ "--query '[].name'",
180
+ "2>/dev/null",
181
+ ]
182
+
183
+ # Add prefix if specified
184
+ unless prefix.empty?
185
+ cmd_parts.insert(4, "--prefix '#{prefix}/'")
186
+ end
187
+
188
+ cmd = cmd_parts.join(" ")
189
+
190
+ # Execute command and capture output
191
+ output = `#{cmd}`.strip
192
+ exit_code = $?.exitstatus
193
+
194
+ # Handle command failure
195
+ # Check exit code - non-zero indicates command failure
196
+ if exit_code != 0
197
+ raise "Failed to list blobs from Azure Storage"
198
+ end
199
+
200
+ # Parse JSON output
201
+ begin
202
+ require "json"
203
+ # Empty string is not valid JSON and indicates command failure
204
+ # Valid empty result from Azure CLI would be "[]", not ""
205
+ if output.empty?
206
+ raise "Failed to list blobs from Azure Storage"
207
+ end
208
+ blob_data = JSON.parse(output)
209
+ rescue JSON::ParserError => e
210
+ # Invalid JSON indicates parsing failure
211
+ raise "Failed to parse Azure CLI output: #{e.message}"
212
+ end
213
+
214
+ # Return empty array if no blobs found
215
+ return [] if blob_data.nil? || blob_data.empty?
216
+
217
+ # Extract blob names from JSON array
218
+ # JSON format from Azure CLI: [{"name":"path/to/blob"}, ...] or ["name1", "name2", ...]
219
+ blob_names = if blob_data.first.is_a?(Hash)
220
+ blob_data.map { |item| item["name"] }
221
+ else
222
+ blob_data
223
+ end
224
+
225
+ # Filter to get only immediate children (flat listing)
226
+ prefix_with_slash = prefix.empty? ? "" : "#{prefix}/"
227
+ immediate_children = []
228
+
229
+ blob_names.each do |blob_name|
230
+ # Remove prefix if specified to get relative path
231
+ relative_path = if prefix_with_slash.empty?
232
+ blob_name
233
+ else
234
+ # Remove prefix from blob name
235
+ blob_name.sub(/^#{Regexp.escape(prefix_with_slash)}/, "")
236
+ end
237
+
238
+ # Get only immediate children (first level after prefix)
239
+ # Split by '/' and take first part, but preserve trailing slash if present
240
+ parts = relative_path.split("/", 2)
241
+ first_part = parts[0]
242
+
243
+ # If the original blob_name had a trailing slash or ends with "/", preserve it
244
+ # Check if this is a directory (ends with /) in the original name
245
+ is_directory = blob_name.end_with?("/") || (parts.length > 1 && relative_path.end_with?("/"))
246
+ first_part += "/" if is_directory && !first_part.end_with?("/")
247
+
248
+ # Add to results if not already included (avoid duplicates)
249
+ immediate_children << first_part unless immediate_children.include?(first_part)
250
+ end
251
+
252
+ immediate_children
253
+ end
254
+ end
255
+ end
256
+ end
257
+
@@ -0,0 +1,285 @@
1
+ # Azure helper methods for CLI operations
2
+ module Makit
3
+ module Azure
4
+ class Cli
5
+ # Check if Azure CLI is installed
6
+ def self.available?
7
+ system("which az > /dev/null 2>&1")
8
+ end
9
+
10
+ # Check if Azure CLI is authenticated
11
+ def self.authenticated?
12
+ return false unless available?
13
+ system("az account show > /dev/null 2>&1")
14
+ end
15
+
16
+ # Get Azure Storage account from environment variable
17
+ def self.storage_account
18
+ ENV["AZURE_STORAGE_ACCOUNT"]
19
+ end
20
+
21
+ # Get Azure Storage account key from environment variable
22
+ def self.storage_account_key
23
+ ENV["AZURE_STORAGE_ACCOUNT_KEY"]
24
+ end
25
+
26
+ # Validate Azure Storage credentials are set
27
+ def self.validate_storage_credentials!
28
+ if storage_account.nil? || storage_account.empty?
29
+ raise "AZURE_STORAGE_ACCOUNT environment variable is not set"
30
+ end
31
+ if storage_account_key.nil? || storage_account_key.empty?
32
+ raise "AZURE_STORAGE_ACCOUNT_KEY environment variable is not set"
33
+ end
34
+ end
35
+
36
+ # Delete all blobs in a storage path
37
+ # @param path [String] The storage path (e.g., '$web/apps/portal/v0.1.0')
38
+ def self.delete_blobs(path)
39
+ validate_storage_credentials!
40
+ puts " Deleting existing files in #{path}/".colorize(:yellow)
41
+
42
+ cmd = [
43
+ "az storage blob delete-batch",
44
+ "--source '#{path}'",
45
+ "--account-name #{storage_account}",
46
+ "--account-key '#{storage_account_key}'",
47
+ "--pattern '*'",
48
+ "2>/dev/null",
49
+ ].join(" ")
50
+
51
+ system(cmd)
52
+ # Don't fail if path doesn't exist (first deployment)
53
+ true
54
+ end
55
+
56
+ # Upload files to Azure Storage
57
+ # @param source [String] Local directory to upload from
58
+ # @param destination [String] Storage path destination (e.g., '$web/apps/portal/v0.1.0')
59
+ def self.upload_blobs(source, destination)
60
+ validate_storage_credentials!
61
+ puts " Uploading files from #{source} to #{destination}/".colorize(:green)
62
+
63
+ unless Dir.exist?(source)
64
+ raise "Source directory does not exist: #{source}"
65
+ end
66
+
67
+ cmd = [
68
+ "az storage blob upload-batch",
69
+ "--destination '#{destination}'",
70
+ "--source #{source}",
71
+ "--account-name #{storage_account}",
72
+ "--account-key '#{storage_account_key}'",
73
+ "--overwrite",
74
+ ].join(" ")
75
+
76
+ unless system(cmd)
77
+ raise "Failed to upload blobs to Azure Storage"
78
+ end
79
+ true
80
+ end
81
+
82
+ # Get CDN resource group from environment variable
83
+ def self.cdn_resource_group
84
+ ENV["AZURE_CDN_RESOURCE_GROUP"]
85
+ end
86
+
87
+ # Get CDN profile name from environment variable
88
+ def self.cdn_profile_name
89
+ ENV["AZURE_CDN_PROFILE_NAME"]
90
+ end
91
+
92
+ # Get CDN endpoint name from environment variable
93
+ def self.cdn_endpoint_name
94
+ ENV["AZURE_CDN_ENDPOINT_NAME"]
95
+ end
96
+
97
+ # Check if CDN variables are configured
98
+ def self.cdn_configured?
99
+ !cdn_resource_group.nil? && !cdn_resource_group.empty? &&
100
+ !cdn_profile_name.nil? && !cdn_profile_name.empty? &&
101
+ !cdn_endpoint_name.nil? && !cdn_endpoint_name.empty?
102
+ end
103
+
104
+ # Purge CDN cache for a specific path
105
+ # @param path [String] The path to purge (e.g., '/apps/portal/v0.1.0/*')
106
+ def self.purge_cdn_cache(path)
107
+ unless cdn_configured?
108
+ puts " CDN variables not configured, skipping cache purge".colorize(:yellow)
109
+ return false
110
+ end
111
+
112
+ puts " Purging Azure CDN cache for #{path}".colorize(:green)
113
+
114
+ cmd = [
115
+ "az cdn endpoint purge",
116
+ "--resource-group '#{cdn_resource_group}'",
117
+ "--profile-name '#{cdn_profile_name}'",
118
+ "--name '#{cdn_endpoint_name}'",
119
+ "--content-paths '#{path}'",
120
+ ].join(" ")
121
+
122
+ success = system(cmd)
123
+ unless success
124
+ puts " Warning: CDN purge failed or CDN not configured".colorize(:yellow)
125
+ end
126
+ success
127
+ end
128
+
129
+ # Get static website endpoint URL for the storage account
130
+ # @return [String] The static website endpoint URL (e.g., 'https://louparslow.z22.web.core.windows.net')
131
+ def self.static_website_endpoint
132
+ validate_storage_credentials!
133
+
134
+ unless available?
135
+ # Fallback if Azure CLI not available
136
+ return "https://#{storage_account}.z22.web.core.windows.net"
137
+ end
138
+
139
+ # Try to get the static website endpoint from Azure
140
+ cmd = "az storage account show --name #{storage_account} --query 'primaryEndpoints.web' --output tsv 2>/dev/null"
141
+ endpoint = `#{cmd}`.strip
142
+
143
+ if endpoint.nil? || endpoint.empty?
144
+ # Fallback: construct URL from storage account name
145
+ # This assumes the standard format, but may not work for all storage accounts
146
+ endpoint = "https://#{storage_account}.z22.web.core.windows.net"
147
+ puts " Warning: Could not retrieve static website endpoint, using default format".colorize(:yellow)
148
+ end
149
+
150
+ # Remove trailing slash if present
151
+ endpoint.chomp("/")
152
+ end
153
+
154
+ # List Key Vaults in a resource group
155
+ # @param resource_group [String] The Azure resource group name
156
+ # @return [Array<Hash>] Array of key vault information hashes, or empty array if none found
157
+ def self.list_key_vaults(resource_group)
158
+ unless available?
159
+ raise "Azure CLI is not installed. Install it from: https://aka.ms/InstallAzureCLI"
160
+ end
161
+
162
+ unless authenticated?
163
+ raise "Azure CLI is not authenticated. Run 'az login' first"
164
+ end
165
+
166
+ if resource_group.nil? || resource_group.empty?
167
+ raise "Resource group name is required"
168
+ end
169
+
170
+ puts " Listing Key Vaults in resource group: #{resource_group}".colorize(:cyan)
171
+
172
+ # Query for key vaults in the resource group
173
+ cmd = [
174
+ "az keyvault list",
175
+ "--resource-group '#{resource_group}'",
176
+ "--query '[].{Name:name, Location:location, ResourceGroup:resourceGroup, VaultUri:properties.vaultUri}'",
177
+ "--output json",
178
+ "2>/dev/null",
179
+ ].join(" ")
180
+
181
+ output = `#{cmd}`.strip
182
+
183
+ if output.nil? || output.empty?
184
+ puts " No Key Vaults found in resource group: #{resource_group}".colorize(:yellow)
185
+ return []
186
+ end
187
+
188
+ begin
189
+ require "json"
190
+ key_vaults = JSON.parse(output)
191
+ key_vaults
192
+ rescue JSON::ParserError => e
193
+ puts " Error parsing Key Vault list: #{e.message}".colorize(:red)
194
+ puts " Raw output: #{output}".colorize(:yellow)
195
+ []
196
+ end
197
+ end
198
+
199
+ # Grant Key Vault access to a service principal
200
+ # @param app_id [String] The service principal app ID (client ID)
201
+ # @param resource_group [String] The Azure resource group name (default: "LouParslow")
202
+ # @param keyvault_name [String] The Key Vault name (default: "louparslow-dev-secrets")
203
+ # @return [Boolean] true if successful, raises error on failure
204
+ def self.grant_keyvault_access(app_id, resource_group: "LouParslow", keyvault_name: "louparslow-dev-secrets")
205
+ unless available?
206
+ raise "Azure CLI is not installed. Install it from: https://aka.ms/InstallAzureCLI"
207
+ end
208
+
209
+ unless authenticated?
210
+ raise "Azure CLI is not authenticated. Run 'az login' first"
211
+ end
212
+
213
+ if app_id.nil? || app_id.empty?
214
+ raise "Service principal app ID (appId) is required"
215
+ end
216
+
217
+ if resource_group.nil? || resource_group.empty?
218
+ raise "Resource group name is required"
219
+ end
220
+
221
+ if keyvault_name.nil? || keyvault_name.empty?
222
+ raise "Key Vault name is required"
223
+ end
224
+
225
+ puts " Granting Key Vault access to service principal...".colorize(:cyan)
226
+ puts " App ID: #{app_id}".colorize(:white)
227
+ puts " Resource Group: #{resource_group}".colorize(:white)
228
+ puts " Key Vault: #{keyvault_name}".colorize(:white)
229
+
230
+ # Get subscription ID
231
+ puts " Getting subscription ID...".colorize(:cyan)
232
+ subscription_cmd = "az account show --query id -o tsv 2>/dev/null"
233
+ subscription_id = `#{subscription_cmd}`.strip
234
+
235
+ if subscription_id.nil? || subscription_id.empty?
236
+ raise "Failed to get subscription ID. Ensure you're logged in with 'az login'"
237
+ end
238
+
239
+ puts " Subscription ID: #{subscription_id}".colorize(:white)
240
+
241
+ # Get service principal object ID
242
+ puts " Getting service principal object ID...".colorize(:cyan)
243
+ sp_object_id_cmd = "az ad sp show --id '#{app_id}' --query id -o tsv 2>/dev/null"
244
+ sp_object_id = `#{sp_object_id_cmd}`.strip
245
+
246
+ if sp_object_id.nil? || sp_object_id.empty?
247
+ raise "Failed to get service principal object ID for app ID: #{app_id}. Ensure the service principal exists."
248
+ end
249
+
250
+ puts " Service Principal Object ID: #{sp_object_id}".colorize(:white)
251
+
252
+ # Grant "Key Vault Secrets User" role
253
+ scope = "/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.KeyVault/vaults/#{keyvault_name}"
254
+ puts " Granting 'Key Vault Secrets User' role...".colorize(:cyan)
255
+ puts " Scope: #{scope}".colorize(:white)
256
+
257
+ role_assignment_cmd = [
258
+ "az role assignment create",
259
+ "--assignee '#{sp_object_id}'",
260
+ "--role 'Key Vault Secrets User'",
261
+ "--scope '#{scope}'",
262
+ "2>&1",
263
+ ].join(" ")
264
+
265
+ output = `#{role_assignment_cmd}`
266
+ exit_code = $?.exitstatus
267
+
268
+ if exit_code != 0
269
+ # Check if role assignment already exists
270
+ if output.include?("already exists") || output.include?("RoleAssignmentExists")
271
+ puts " Role assignment already exists (this is OK)".colorize(:yellow)
272
+ return true
273
+ else
274
+ puts " Error output: #{output}".colorize(:red)
275
+ raise "Failed to grant Key Vault access: #{output}"
276
+ end
277
+ end
278
+
279
+ puts " Successfully granted Key Vault access".colorize(:green)
280
+ true
281
+ end
282
+ end
283
+ end
284
+ end
285
+