44 "fmt"
55 "strings"
66
7+ cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
8+
79 "github.com/openshift/rosa/pkg/interactive"
810 "github.com/openshift/rosa/pkg/logforwarding"
911 "github.com/openshift/rosa/pkg/ocm"
@@ -36,13 +38,13 @@ func InteractiveLogForwardingConfig(ocmClient *ocm.Client) (
3638 cloudWatchResult := & logforwarding.CloudWatchLogForwarderConfig {}
3739
3840 if con == cloudWatch || con == both {
39- cloudWatchResult , err = interactiveCloudWatch (ocmClient )
41+ cloudWatchResult , err = interactiveCloudWatch (ocmClient , "" , "" )
4042 if err != nil {
4143 return nil , err
4244 }
4345 }
4446 if con == s3 || con == both {
45- s3Result , err = interactiveS3 (ocmClient )
47+ s3Result , err = interactiveS3 (ocmClient , "" , "" )
4648 if err != nil {
4749 return nil , err
4850 }
@@ -55,12 +57,43 @@ func InteractiveLogForwardingConfig(ocmClient *ocm.Client) (
5557 return & result , nil
5658}
5759
58- func interactiveCloudWatch (ocmClient * ocm.Client ) (
60+ func InteractiveLogForwardingConfigWithDefaults (ocmClient * ocm.Client , logForwarder * cmv1.LogForwarder ) (
61+ * logforwarding.LogForwarderYaml , error ) {
62+
63+ s3Result := & logforwarding.S3LogForwarderConfig {}
64+ cloudWatchResult := & logforwarding.CloudWatchLogForwarderConfig {}
65+
66+ var err error
67+
68+ if logForwarder .Cloudwatch () != nil && logForwarder .Cloudwatch ().LogDistributionRoleArn () != "" {
69+ cloudWatchResult , err = interactiveCloudWatch (ocmClient ,
70+ logForwarder .Cloudwatch ().LogGroupName (), logForwarder .Cloudwatch ().LogDistributionRoleArn ())
71+ if err != nil {
72+ return nil , err
73+ }
74+ }
75+ if logForwarder .S3 () != nil && logForwarder .S3 ().BucketName () != "" {
76+ s3Result , err = interactiveS3 (ocmClient , logForwarder .S3 ().BucketName (), logForwarder .S3 ().BucketPrefix ())
77+ if err != nil {
78+ return nil , err
79+ }
80+ }
81+
82+ result := logforwarding.LogForwarderYaml {}
83+ result .S3 = s3Result
84+ result .CloudWatch = cloudWatchResult
85+
86+ return & result , nil
87+ }
88+
89+ func interactiveCloudWatch (ocmClient * ocm.Client , defaultLogGroupName string , defaultLogRoleArn string ) (
5990 * logforwarding.CloudWatchLogForwarderConfig , error ) {
91+
6092 cloudWatchConfig := logforwarding.CloudWatchLogForwarderConfig {}
6193 roleArn , err := interactive .GetString (interactive.Input {
6294 Question : "CloudWatch Log forwarding role ARN" ,
6395 Help : "The role ARN which forwards logs to CloudWatch" ,
96+ Default : defaultLogRoleArn ,
6497 Required : true ,
6598 })
6699 if err != nil {
@@ -71,6 +104,7 @@ func interactiveCloudWatch(ocmClient *ocm.Client) (
71104 groupName , err := interactive .GetString (interactive.Input {
72105 Question : "CloudWatch log group name" ,
73106 Help : "The name of the group on CloudWatch which will contain the logs" ,
107+ Default : defaultLogGroupName ,
74108 Required : true ,
75109 })
76110 if err != nil {
@@ -96,11 +130,14 @@ func interactiveCloudWatch(ocmClient *ocm.Client) (
96130 return & cloudWatchConfig , nil
97131}
98132
99- func interactiveS3 (ocmClient * ocm.Client ) (* logforwarding.S3LogForwarderConfig , error ) {
133+ func interactiveS3 (ocmClient * ocm.Client , defaultBucketName string , defaultBucketPrefix string ) (
134+ * logforwarding.S3LogForwarderConfig , error ) {
135+
100136 s3Config := logforwarding.S3LogForwarderConfig {}
101137 bucketPrefix , err := interactive .GetString (interactive.Input {
102138 Question : "S3 Bucket prefix" ,
103139 Help : "The identifiable prefix to prepend to the S3 Bucket used for log forwarding" ,
140+ Default : defaultBucketPrefix ,
104141 Required : false ,
105142 })
106143 if err != nil {
@@ -111,6 +148,7 @@ func interactiveS3(ocmClient *ocm.Client) (*logforwarding.S3LogForwarderConfig,
111148 bucketName , err := interactive .GetString (interactive.Input {
112149 Question : "S3 Bucket name" ,
113150 Help : "The identifiable name to append to the S3 Bucket used for log forwarding" ,
151+ Default : defaultBucketName ,
114152 Required : true ,
115153 })
116154 if err != nil {
0 commit comments