-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create gcp wif helpers file and remove unnecessary validation functions
- Loading branch information
Showing
7 changed files
with
73 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package gcp | ||
|
||
import ( | ||
"fmt" | ||
|
||
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
) | ||
|
||
// Checks for WIF config name or id in input | ||
func wifKeyArgCheck(args []string) error { | ||
if len(args) != 1 || args[0] == "" { | ||
return fmt.Errorf("expected exactly one command line parameters containing the name " + | ||
"or ID of the WIF config") | ||
} | ||
return nil | ||
} | ||
|
||
// Extracts WIF config name or id from input | ||
func wifKeyFromArgs(args []string) (string, error) { | ||
if err := wifKeyArgCheck(args); err != nil { | ||
return "", err | ||
} | ||
return args[0], nil | ||
} | ||
|
||
// findWifConfig finds the WIF configuration by ID or name | ||
func findWifConfig(client *cmv1.Client, key string) (*cmv1.WifConfig, error) { | ||
collection := client.GCP().WifConfigs() | ||
page := 1 | ||
size := 1 | ||
query := fmt.Sprintf( | ||
"id = '%s' or display_name = '%s'", | ||
key, key, | ||
) | ||
|
||
response, err := collection.List().Search(query).Page(page).Size(size).Send() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if response.Total() == 0 { | ||
return nil, fmt.Errorf("WIF configuration with identifier or name '%s' not found", key) | ||
} | ||
if response.Total() > 1 { | ||
return nil, fmt.Errorf("there are %d WIF configurations found with identifier or name '%s'", response.Total(), key) | ||
} | ||
return response.Items().Slice()[0], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters